Click or drag to resize

BasicAppSettings class

Retrieves application settings from various sources: Command line, app.config, if necessary app.config.user, Environment.
Also implements registry reading, but does not yet use this itself. Under certain circumstances, also evaluates public properties (DumpAppSettings=true). Does not access the database, but provides corresponding properties.
The properties and the filling of the same are not mandatory, they serve for convenience only; alternatively, it can also be accessed directly from the application via the interfaces IGetStringValue and IGetValue<T> can be used to access the application/system environment.
The application settings implemented here should be generally valid for standalone applications; for application-specific settings, this class should be can be derived. Sources are analysed in the following order (the 1st hit wins):
1. command line parameters (not for .NetCore web applications)
2. settings in the app.config (not for .NetCore web applications, then appsettings.json instead)
3. settings in the app.Config.user if necessary
4. environment
5th registry
6. possibly public properties (DumpAppSettings=true).
Time-critical Initializations should generally be avoided in derived AppSettings. However, the corresponding properties can be defined and implemented lazily if necessary.
The "DumpAppSettings" and "DumpLoadedAssemblies" properties can be used to debug all properties with their sources and the FullNames of all assemblies loaded at runtime are logged.
Inheritance hierarchy
SystemObject
  NetEti.ApplicationEnvironmentBasicAppSettings
    Vishnu.InterchangeAppSettings

Namespace: NetEti.ApplicationEnvironment
Assembly: NetEti.BasicAppSettings (in NetEti.BasicAppSettings.dll) Version: 1.0.0+fc721cf1d38e1de155fd33971356662ac9c21f21
Syntax
public class BasicAppSettings : IGetStringValue,
	 
	IGetValue, IDisposable

The BasicAppSettings Type exposes the following members.

Constructors
 NameDescription of the
Protected MethodBasicAppSettings constructor, may be used via reflection from the external static GenericSingletonProvider is called via GetInstance(). Get all the information and make it available as properties.
Back to the top
Properties
 NameDescription of the
Public PropertyAppConfigUser Path of an XML file in the format of app.config with user-specific settings.
Public PropertyAppConfigUserInfo Info text with extended status information on the AppConfigUser loading attempt.
Public PropertyAppConfigUserLoaded True if an XML file in the format of the app.config with user-specific settings could be loaded.
Public PropertyAppEnvAccessor Implements IGetStringValue for encapsulating access via concrete Readers such as CommandLineAccess, SettingsAccess, EnvAccess.
Public PropertyApplicationName Application.ProductName
Public PropertyApplicationRootPath The directory in which the application was started as an absolute path.
Public PropertyBreakAlwaysAllowed If true, can always be cancelled - for debugging purposes.
Default: false
Public PropertyCheckVersion Can be used for a later version check if necessary.
Default: true
Public PropertyClickOnceDataDirectory directory in which the installation data is stored during a ClickOnce installation (EnvAccess:ISNETWORKDEPLOYED = true).
Protected PropertyCommandLineAccessor Implements IGetStringValue for accessing the command line.
Public PropertyConnectionString Connection string for a database connection.
Protected PropertyCreatedDirectoryRoot Contains the path of the lowest directory that was created in the last "Directory.Create" was newly created. This
Public PropertyCreateWorkingDirectoryIfNotExists If True, the currently set WorkingDirectory is created if it does not yet exist.
Default: true
Public PropertyDataSource The customised database server instance name.
Default: = (local)
Public PropertyDebugArchiveMaxCount Maximum number of archived logs (debug files, etc.). If there is a surplus, the oldest ones are deleted. Default: 20.
Public PropertyDebugArchivingInterval Time interval at which the current log (DebugFile, etc.) is archived and emptied. Default: 24 hours.
Public PropertyDebugFile Path and name of the log file
Default: WorkingDirectory + \ + ApplicationName + .log
Public PropertyDebugFileRegexFilter Filter that limits the lines to be logged. Default: "" - everything is logged.
Public PropertyDebugInfo The types of information to be logged
public enum InfoType
{ DEBUG, INFO, WARN, MILESTONE, ERROR, EXCEPTION, USERTYPE1, USERTYPE2 };
as a string, such as: "DEBUG|INFO|WARN|MILESTONE|ERROR".
Default: is set in the start program, usually InfoType.ALL (InfoType.ALL contains everything except the USERTYPEs).
Public PropertyDebugMode If True, applications can generate debug output. Default: False.
Public PropertyDefaultDatabase The default database.
Default: zero
Public PropertyDefaultSqlDataDirectory The default directory for SQL Server data files
Public PropertyDefaultSqlLogDirectory The default directory for the SQL server log files
Public PropertyDescription Returns a descriptive name of this StringValueGetter, e.g. name plus source path if applicable.
Public PropertyDumpAppSettings If true, BasicAppSettings returns the following via the InfoController at the end of the Processing all AppSetting properties with value and source. Default: false.
Public PropertyDumpLoadedAssemblies If true, BasicAppSettings returns the following via the InfoController at the end of the Processing the full names of all assemblies loaded in the AppDomain. Default: false.
Protected PropertyEnvAccessor Implements IGetStringValue for accessing the environment.
Public PropertyFrameworkVersionMajor The version of the highest installed .Net framework
Protected PropertyIniAccessor Implements IGetStringValue for accessing INI files.
Public PropertyIsClickOnce True, if the application was installed via ClickOnce (see also ClickOnceDataDirectory).
Public PropertyIsFrameworkAssembly True if the application is based on .Net framework.
Public PropertyIsFullFramework True if the application is based on a complete .Net framework.
Public PropertyIsNetCore True if the application is a .Net Core application.
Public PropertyIsNetNative True if the application is a UWP application.
Public PropertyKillChildProcessesOnApplicationExit With True, all child processes of the application at the end of the program should be can be scheduled recursively after a certain waiting time. Attention: BasicAppSettings only provides the property. The respective application must take care of terminating the processes. by integrating NetEti.ProcessTools and calling up ProcessWorker.FinishChildProcesses() yourself. Default: false.
Public PropertyKillWorkingDirectoryAtShutdown If True, the WorkingDirectory is removed at the end of the program. For safety reasons, this should only be done if the program start was also generated. The WorkingDirectory is not created or deleted by BasicAppSettings, but can also be used by the application or logging. Default: true.
Public PropertyLogSql If true, every sql command should be written to the log file. For free use.
Default: false
Public PropertyMachineName The computer name
Public PropertyMinProgramVersion Required minimum version for later checking against the program version.
Default: "1.0.0.0"
Public PropertyOS version The complete operating system version
Public PropertyOSVersionMajor Numerical main operating system version
> 5 => at least Vista
Public PropertyProcessId The process ID of the current process.
Public PropertyProcessor The processor type
Public PropertyProcessorCount The number of processors
Public PropertyProgram version The current program version = Application.ProductVersion
Protected PropertyPropertyAccessor Implements IGetStringValue for accessing public properties of the AppSettings.
Protected PropertyRegAccessor Implements IGetStringValue for accessing the registry.
Public PropertyRegistryBasePath Base path in which a setting is searched for in the registry. If the path contains one of the RegistryRoots, e.g. "HKEY_CURRENT_USER", then the internally set RegistryRoot has also been changed. The default for the internally set RegistryRoot is "HKEY_LOCAL_MACHINE". Default: ""
Public PropertySearchDirectory An optional search directory for various purposes.
Default: WorkingDirectory
Protected PropertySettingsAccessor Implements IGetStringValue for accessing the app.config.
Public PropertySingleInstance If true, the application can only be started once.
Default: false
Public PropertyStatisticsFile Path and name of the statistics log file
Default: WorkingDirectory + \ + ApplicationName + .stat
Public PropertyStatisticsFileRegexFilter Filter that limits the lines to be logged. Default: "" - everything is logged. e.g: @"(?:_NOPPES_)" - Nothing is logged, or only lines that contain "_NOPPES_"
Public PropertyTempDirectory Environment: "TEMP"
Public PropertyUserDomainName The Windows domain name
Public PropertyUserName The Windows user name
Protected PropertyUserSettingsAccessor Implements IGetStringValue for accessing the app.config.user.
Public PropertyWorkingDirectory The working directory
Default:
If "SingleInstance=true: C:\Users\<user>\AppData\Local\Temp\<ApplicationName>
With "SingleInstance=false: C:\Users\<user>\AppData\Local\Temp\<ApplicationName>\<ProcessId>
Public PropertyWorkingDirectoryCreated True if the WorkingDirectory was created when the program was started. The WorkingDirectory is not created or deleted by BasicAppSettings, but can also be used by the application or logging. Default: false.
Back to the top
Methods
 NameDescription of the
Protected MethodDirectoryCreate Creates a complete directory path if this path or a part of it is of which does not exist. Returns the part of the directory path, which goes up to and including the first of the newly created directories or zero. The result of this routine can be used to precisely determine the part of a directory path that has been newly created.
Public MethodDispose Public method for cleaning up.
Protected MethodDispose(Boolean) Finalise work, reset timer if necessary.
Protected MethodFinalise Destructor
(Overwrites ObjectFinalise)
Public MethodGetLoadedAssemblies Returns a dictionary that is used for all assemblies loaded in the application. contains the FullName and the assembly. Can be helpful for troubleshooting in certain cases.
Note: If the switch "DumpLoadedAssemblies" = true, the keys of this dictionary (FullName) are logged in "Dispose".
Public MethodGetParametersSources Returns a dictionary containing the name of the source for each parameter. Can be helpful for troubleshooting in certain cases.
Note: If the switch "DumpAppSettings" = true, this dictionary is logged in "Dispose".
Public MethodGetStringValue Returns exactly one value for a key. If there is no value for the key, defaultValue is returned.
Public MethodGetStringValues Returns a string array for a key. If there is no value for the key, defaultValue is returned.
Public MethodGetValueT Returns exactly one value for a key. If there is no value for the key, defaultValue is returned. Wildcards of the form %Name% are replaced recursively if possible; An attempt is made to cast the determined string value to the return type T.
Public MethodGetValuesT NOT IMPLEMENTED! Returns an array of values for a key. If there is no value for the key, defaultValue is returned. Wildcards of the form %Name% are replaced recursively if possible; An attempt is made to cast the determined string value to the return type T.
Public MethodLoadSettings Loads the system settings during Initialization or loads them again on request.
Public MethodReplaceWildcards Replaces wildcards in the format %Name% with their runtime values.
Protected MethodSetDefaultSQLDirectories Sets the default directories for the Microsoft SQL Server.
Public MethodSetRegistryBasePath Sets the registry access key for all subsequent accesses to the passed base path, if the passed registryBasePath can be converted error-free into a corresponding equivalent from registry keys.
Back to the top
Remarks
File: BasicAppSettings.cs
Author: Erik Nagel, NetEti

05.07.2011 Erik Nagel: created.
08.03.2012 Erik Nagel: Singleton functionality removed, now runs via external NetEti.Globals.GenericSingletonProvider. This makes AppSettings inheritable; completely revised, renamed BasicAppSettings and all application-specific properties are thrown out (lie now in the application-specific AppSettings).
2014-01-23 Erik Nagel: ProcessId added; Accessors moved to the protected area as simple properties.
10.06.2014 Erik Nagel: IGetValue implemented.
31.12.2014 Erik Nagel: DebugMode implemented.
04.10.2015 Erik Nagel: AppConfigUser implemented.
14.07.2016 Erik Nagel: AppEnvAccessor changed from protected to public.
15 Oct 2017 Erik Nagel: RegistryBasePath introduced.
09.03.2019 Erik Nagel: DumpAppSettings and DumpLoadedAssemblies introduced.
2020-04-05 Erik Nagel: .NetCore-enabled; Newtosoft.json integrated; Version 4.6.1.
See also