Class JsonConfigurationService
A service for loading configuration settings from JSON files, strings etc. into memory, and for getting and setting their (in-memory) values. Note that saving settings to JSON files is not supported.
This is the default configuration service for worker systems, but it can also be used stand-alone. See AConfig Configuration Facility and AConfig for further details.
Note that multiple calls to the Load*() methods can be made, which is useful when
loading a mix of mandatory and optional files.
On a modern computer, GetValue() can retrieve more than 10 million string settings per second, and retrieve and parse more than 1 million date settings per second. While very fast, do cache the values where appropriate, e.g. if accessing a setting once per dataflow row.
Implements
Namespace: actionETL.Configuration
Assembly: actionETL.dll
Syntax
public class JsonConfigurationService : IConfigurationService
Constructors
JsonConfigurationService()
Initializes a new instance of the JsonConfigurationService class, without loading any configuration files.
Declaration
public JsonConfigurationService()
Properties
Items
Gets all configuration items.
This property is thread-safe.
Declaration
public IEnumerable<IConfigurationServiceItem> Items { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<IConfigurationServiceItem> |
Methods
DefaultFileNames()
Returns the default configuration file names that LoadAnyDefault() attempts to load. This can be used to customize the loading of the default files, e.g. mandating that at least one file is found.
This method is thread-safe.
Declaration
public static IEnumerable<string> DefaultFileNames()
Returns
| Type | Description |
|---|---|
| IEnumerable<String> | The following file names, in this order:
|
LoadAll(IEnumerable<String>)
Loads all specified JSON configuration files.
This method is thread-safe.
Declaration
public JsonConfigurationService LoadAll(IEnumerable<string> fileNames)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<String> | fileNames | The file names to load. |
Returns
| Type | Description |
|---|---|
| JsonConfigurationService | The configuration instance itself, which allows chaining method calls. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| Exception | (Various JsonReaderException JSON parsing exceptions.) |
| FileNotFoundException | Configuration file not found. |
| IOException | An I/O error occurred. |
| SecurityException | The caller does not have the required permission. |
| UnauthorizedAccessException | The access requested is not permitted by the operating system for the specified path. |
LoadAll(String[])
Loads all specified JSON configuration files.
This method is thread-safe.
Declaration
public JsonConfigurationService LoadAll(params string[] fileNames)
Parameters
| Type | Name | Description |
|---|---|---|
| String[] | fileNames | The file names to load. |
Returns
| Type | Description |
|---|---|
| JsonConfigurationService | The configuration instance itself, which allows chaining method calls. |
Exceptions
| Type | Condition |
|---|---|
| Exception | (Various JsonReaderException JSON parsing exceptions.) |
| FileNotFoundException | Configuration file not found. |
| IOException | An I/O error occurred. |
| SecurityException | The caller does not have the required permission. |
| UnauthorizedAccessException | The access requested is not permitted by the operating system for the specified path. |
LoadAny(IEnumerable<String>)
Loads any of the specified JSON configuration files, if they can be found and accessed.
This method is thread-safe.
Declaration
public JsonConfigurationService LoadAny(IEnumerable<string> fileNames)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<String> | fileNames | The file names to load. |
Returns
| Type | Description |
|---|---|
| JsonConfigurationService | The configuration instance itself, which allows chaining method calls. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| Exception | (Various JsonReaderException JSON parsing exceptions.) |
| IOException | An I/O error occurred. |
LoadAny(String[])
Loads any of the specified JSON configuration files, if they can be found and accessed.
This method is thread-safe.
Declaration
public JsonConfigurationService LoadAny(params string[] fileNames)
Parameters
| Type | Name | Description |
|---|---|---|
| String[] | fileNames | The file names to load. |
Returns
| Type | Description |
|---|---|
| JsonConfigurationService | The configuration instance itself, which allows chaining method calls. |
Exceptions
| Type | Condition |
|---|---|
| Exception | (Various JsonReaderException JSON parsing exceptions.) |
| IOException | An I/O error occurred. |
LoadAnyDefault()
Gets the default JSON configurations by loading any of the default configuration files (see DefaultFileNames()) that can be found.
This method is thread-safe.
Declaration
public JsonConfigurationService LoadAnyDefault()
Returns
| Type | Description |
|---|---|
| JsonConfigurationService | The configuration instance itself, which allows chaining method calls. |
Exceptions
| Type | Condition |
|---|---|
| Exception | (Various JsonReaderException JSON parsing exceptions.) |
| IOException | An I/O error occurred. |
LoadText(TextReader)
Loads configurations in the JSON format from the specified TextReader.
This method is thread-safe.
Declaration
public JsonConfigurationService LoadText(TextReader textReader)
Parameters
| Type | Name | Description |
|---|---|---|
| TextReader | textReader | The text reader to load from. |
Returns
| Type | Description |
|---|---|
| JsonConfigurationService | The configuration instance itself, which allows chaining method calls. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| Exception | (Various JsonReaderException JSON parsing exceptions.) |
| IOException | An I/O error occurred. |
LoadText(String)
Loads configurations from the specified JSON string.
This method is thread-safe.
Declaration
public JsonConfigurationService LoadText(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| String | text | The JSON string to load from. |
Returns
| Type | Description |
|---|---|
| JsonConfigurationService | The configuration instance itself, which allows chaining method calls. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| Exception | (Various JsonReaderException JSON parsing exceptions.) |
| IOException | An I/O error occurred. |
SetValue(String, String, String)
Creates or updates a configuration value.
This method is thread-safe.
Declaration
public IConfigurationService SetValue(string configurationName, string applyTo, string valueString)
Parameters
| Type | Name | Description |
|---|---|---|
| String | configurationName | Name of the configuration. |
| String | applyTo | What part of the worker hierarchy this configuration applies to. Use |
| String | valueString | The value as a string. |
Returns
| Type | Description |
|---|---|
| IConfigurationService | The |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
ToString()
Returns a String that represents this instance.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String |
Overrides
TryGetValue<T>(String, String, CultureInfo)
Attempts to get a configuration value, returning an IGetValueOutcome
instance describing the outcome. To instead throw an exception on any failure, use the
AConfig GetValue and GetValueWithDefault methods.
On success, ApplyToMatched describes whether ApplyTo was both used and matched, or not. This is typically used to give configurations with ApplyTo higher precedence vs. non-ApplyTo configurations.
This method is thread-safe.
Declaration
public IGetValueOutcome TryGetValue<T>(string configurationName, string applyTo, CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| String | configurationName | Name of the configuration. Cannot be |
| String | applyTo | What part of the worker hierarchy the configuration applies to. If set, first looks for
a matching
Use |
| CultureInfo | culture | The culture to use when converting a string to a typed value. Defaults to
InvariantCulture if |
Returns
| Type | Description |
|---|---|
| IGetValueOutcome | The outcome is returned in a class instance with the marker interface IGetValueOutcome:
Typical usage is to call |
Type Parameters
| Name | Description |
|---|---|
| T | The target value type. The following are supported:
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
TryLoadAll(String[])
Loads any specified JSON configuration files, returning an OutcomeStatus
reporting any file reading errors.
This method is thread-safe.
Declaration
public OutcomeStatus TryLoadAll(params string[] fileNames)
Parameters
| Type | Name | Description |
|---|---|---|
| String[] | fileNames | The file names to be loaded. |
Returns
| Type | Description |
|---|---|
| OutcomeStatus |
|