Class SettingsHelper
A settings helper class that allows access to common settings along with methods for other libraries to load their settings from
Inheritance
Inherited Members
Namespace: LemonEdge.Utils
Assembly: Utils.dll
Syntax
public static class SettingsHelper
Remarks
By default the settings helper looks to load an associated settings.config xml files. SetCustomSettingRetriever(ICustomSettingRetriever) can be used to override this functionality
Fields
ConnectionDBStringSetting
The setting key name for the connection string to the database
Declaration
public const string ConnectionDBStringSetting = "ConString"
Field Value
Type | Description |
---|---|
System.String |
ConnectionDBValidDatabasesSetting
The setting key name for the list of valid databases
Declaration
public const string ConnectionDBValidDatabasesSetting = "ValidDatabases"
Field Value
Type | Description |
---|---|
System.String |
ConnectionDBVisibleDatabasesSetting
The setting key name for the list of visible databases
Declaration
public const string ConnectionDBVisibleDatabasesSetting = "VisibleDatabases"
Field Value
Type | Description |
---|---|
System.String |
ConnectionServiceURISetting
The setting key name for the uri for connecting to the web service
Declaration
public const string ConnectionServiceURISetting = "ServiceURI"
Field Value
Type | Description |
---|---|
System.String |
LogDatabaseSQLSetting
The setting key name for inidicating database sql commands should be logged
Declaration
public const string LogDatabaseSQLSetting = "LogDatabaseSQL"
Field Value
Type | Description |
---|---|
System.String |
LogToConsoleSetting
The setting key name for inidicating logs should be sent to the console
Declaration
public const string LogToConsoleSetting = "LogToConsole"
Field Value
Type | Description |
---|---|
System.String |
LogToFileSetting
The setting key name for inidicating to log to a file
Declaration
public const string LogToFileSetting = "LogToFile"
Field Value
Type | Description |
---|---|
System.String |
MinLogLevelSetting
The setting key name for log level
Declaration
public const string MinLogLevelSetting = "MinLogLevel"
Field Value
Type | Description |
---|---|
System.String |
Properties
HasSettingsFile
Indicates if the system found an associated settings.config file alongside this running process
Not necessary if running inside a cloud enviroment as settings can be pulled from config settings in cloud, not a file
Declaration
public static bool HasSettingsFile { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsManualDBConnection
Indicates the client is directly connected to the database rather than working through a web service
Declaration
public static bool IsManualDBConnection { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
LogDatabaseSQL
Indicates if sql commands against the database should also be logged
Declaration
public static bool LogDatabaseSQL { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
LogToConsole
Indicates if the logs should be sent to the console
Declaration
public static bool LogToConsole { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
LogToFile
Indicates if the system should log to a file
Declaration
public static string LogToFile { get; }
Property Value
Type | Description |
---|---|
System.String |
MinLogLevel
Holds the level below which log entries will be supressed
Declaration
public static Extensions.Logging.LogLevel MinLogLevel { get; }
Property Value
Type | Description |
---|---|
Microsoft.Extensions.Logging.LogLevel |
Methods
GetAppSetting<T>(String)
Retrieves an associated setting for the given key
and converts it to the specified T
type
Declaration
public static T GetAppSetting<T>(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key that holds the associated setting value |
Returns
Type | Description |
---|---|
T | The setting associated with the |
Type Parameters
Name | Description |
---|---|
T | The type to convert the specified setting result into |
GetAppSetting<T>(String, T)
Retrieves an associated setting (converted to type T
) for the given key
and returns the specified missingOrEmptyValue
if no associated setting key exists
Declaration
public static T GetAppSetting<T>(string key, T missingOrEmptyValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key that holds the associated setting value |
T | missingOrEmptyValue | If the setting isn't specified this value is returned instead |
Returns
Type | Description |
---|---|
T | The setting associated with the |
Type Parameters
Name | Description |
---|---|
T | The type to convert the specified setting result into |
ReloadSettings()
Forces all settings to be reloaded from the settings source, and all dependant settings for other libraries
Declaration
public static void ReloadSettings()
SetAppSetting<T>(String, T)
Sets the specified setting key to the specified value. This does not write to any setting file, but is just retained in memory for the life of the application.
Declaration
public static void SetAppSetting<T>(string key, T value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key for the setting to change |
T | value | The value to be associated with the specified setting key |
Type Parameters
Name | Description |
---|---|
T | The type of the setting value |
Remarks
This is typically used for settings the user can change - such as database connections
SetCustomSettingRetriever(ICustomSettingRetriever)
Provides a custom settings retriever so libraries can load the settings from a different propeitary source rather than the settings.config file or enviroment
Declaration
public static void SetCustomSettingRetriever(ICustomSettingRetriever retriever)
Parameters
Type | Name | Description |
---|---|---|
ICustomSettingRetriever | retriever | An implementation of ICustomSettingRetriever to provide setting values for given keys from a custom source |
Events
ReloadedSettings
Indicates settings have changed and all associated setting handlers should reload their settings
Declaration
public static event EventHandler ReloadedSettings
Event Type
Type | Description |
---|---|
System.EventHandler |