Library for simple configuration management
In your web.config
or app.config
make sure you have a custom section:
<configuration>
<ExtConfigure>
<IncludeFile Path="etc\externalConfig.xml" Search="All" Include="All" Required="true"/>
<IncludeFile Path="etc\machineSpecific.xml" Search="All" Include="All" Required="true"/>
</ExtConfigure>
</configuration>
Find and download all of the files in the parent directory. Tracking changed included files.
public IAppSettings LoadSettings()
{
var path = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location).FilePath;
var loader = new SettingsLoader();
loader.XmlFileBySection();
var result = loader.LoadSettings(new XmlFileSettings(path, "ExtConfigure"));
var fileCheckers = FileChecker.TryCreate(result.Sources).ToArray();
new FirstChange(fileCheckers).Changed += SettingsChanged;
return result.Joined.ToAppSettings();
}
private void SettingsChanged(object sender, EventArgs e)
{
//TODO: reload settings or application
}
Watch file configuration:
<WatchFile Mode='Auto' Delay='0:0:30' Check='Attr,Hash' />
- Mode - mode of watch from file
Auto
- try create FileSystemWatcher, otherwise create delayed monitorSystem
- create FileSystemWatcherTime
- create delayed monitorNone
- not watching, default value- Delay - delay between checking of monitored file
- Check - what is required to check
None
- only exists file and lenghtAttr
- last write time and other file attributesHash
- MD5 hash sum of reader fileAll
orAttr,Hash
- check same as inAttr
andHash
Deserialization section with the name of all downloaded files.
var configs = settings.Get<ConfigClass>("MyConfig");