Next the functions:
2 public functions, one to load the current configuration or to create a standard configuration is none has been found and the second one to save (write) the configuration.
Loading or Creating of the configuration File
/// <summary>
/// Loads the Confiugration if it exists, Creates a Standard-Configuration with default Values
/// if it does not exist
/// </summary>
public void LoadOrCreateConfiguration()
{
_log.Debug("--> LoadOrCreateConfiguration");
if (!ConfigurationSet)
{
ConfigurationItems = new Dictionary<string, object>();
PropertiesToDictionary();
_log.Trace("### Dictonary with the configuration items has been created");
if (ConfigurationExists())
{
ReadConfiguration();
_log.Debug("<-- LoadOrCreateConfiguration");
}
else
{
CreateConfiguration();
_log.Debug("<-- LoadOrCreateConfiguration");
}
}
}
First thing we do, we check if the configuration has been loaded alread (ConfigurationSet is false). Is it not loaded we create a new Dictionary and load all the properties without value into it (Function: PropertiesToDictionary(), we go through it in just a moment). If the configuration file exists, it will be loaded (Function: ReadConfiguration() ), if no file is found a “Standard”-configuration will be created (Function: CreateConfiguration()).
Saving / writing the Configurationfile
/// <summary>
/// Save a current Configuration
/// </summary>
public void SaveConfiuration()
{
_log.Debug("--> SaveConfiguration");
CreateConfiguration();
_log.Debug("<-- Save Configuration");
}
Writing the file and “creating” the standard configuration is the same function, saving encapsulates the “CreateConfiguration” function.
next are the private functions.