public void MultiChange()
        {
            var xmlFileLoader = new XmlFileSettingsLoader(Global.GenericDeserializer, Global.PlainConverter);

            string cfgMainFile = Path.GetTempFileName();
            string cfgAdditionalFile = Path.GetTempFileName();

            File.WriteAllText(cfgAdditionalFile, _xmlCfgAutoOrigin);
            File.WriteAllText(cfgMainFile, string.Format(_xmlCfgMain, cfgAdditionalFile));

            var loader = new SettingsLoader(xmlFileLoader);
            loader.LoadSettings(xmlFileLoader.LoadFile(cfgMainFile));

            IAppSettings settings = loader.Settings;

            var wait = new ManualResetEvent(false);
            ((IChangeable)settings).Changed += (s, e) => { wait.Set(); };

            var t = Task.Factory.StartNew(() =>
            {
                File.WriteAllText(cfgAdditionalFile, _xmlCfgAutoModify);
            }, TaskCreationOptions.LongRunning);

            Task.WaitAll(t);

            Assert.IsTrue(wait.WaitOne(10000), "10 sec elapsed");
        }
        public void AutoChange()
        {
            string cfgFile = Path.GetTempFileName();
            File.WriteAllText(cfgFile, _xmlCfgAutoOrigin);

            var xmlFileLoader = new XmlFileSettingsLoader(Global.GenericDeserializer, Global.PlainConverter);

            IAppSettings settings = xmlFileLoader.LoadFile(cfgFile);

            var wait = new ManualResetEvent(false);
            ((IChangeable)settings).Changed += (a, e) => { wait.Set(); };

            var t = Task.Factory.StartNew(() =>
            {
                File.WriteAllText(cfgFile, _xmlCfgAutoModify);
            }, TaskCreationOptions.LongRunning);

            Task.WaitAll(t);

            Assert.IsTrue(wait.WaitOne(10000), "10 sec elapsed");

            settings = xmlFileLoader.LoadFile(cfgFile);
            Assert.That(settings.First<ExampleCombineConfig>("AdditionalConfig").F, Is.EqualTo("Modify"));
        }
        private static IAppSettings LoadSettings(string file)
        {
            var xmlFileLoader = new XmlFileSettingsLoader(Global.GenericDeserializer, Global.PlainConverter);
            var jsonFileLoader = new JsonFileSettingsLoader(Global.GenericDeserializer, Global.PlainConverter);
            var iniFileLoader = new IniFileSettingsLoader(Global.GenericDeserializer, Global.PlainConverter);

            var loader = new SettingsLoader(xmlFileLoader, jsonFileLoader, iniFileLoader);
            loader.Loaded += (s, e) =>
            {
                Console.WriteLine("Loaded: {0} ({1})", e.Settings.GetType(), e.Settings.Identity);
            };

            if (Path.GetExtension(file) == ".xml")
                loader.LoadSettings(xmlFileLoader.LoadFile(Path.Combine("Including", file)));
            else
                loader.LoadSettings(jsonFileLoader.LoadFile(Path.Combine("Including", file)));

            return loader.Settings;
        }
        public void Load()
        {
            var xmlFileLoader = new XmlFileSettingsLoader(Global.GenericDeserializer, Global.PlainConverter);

            var loader = new SettingsLoader(xmlFileLoader);
            loader.Loaded += (s,e) =>
            {
                Console.WriteLine("Loaded: {0} ({1})", e.Settings.GetType(), e.Settings.Identity);
            };

            loader.LoadSettings(xmlFileLoader.LoadFile("Examples/AppDirectory/main.config"));

            IAppSettings settings = loader.Settings;

            var addCfg = settings.TryCombine<ExampleCombineConfig>("AdditionalConfig");

            Assert.IsNotNull(addCfg);
            Assert.AreEqual("InAppDirectory", addCfg.F);
        }
        public void AutoCombineLoad()
        {
            var xmlFileLoader = new XmlFileSettingsLoader(Global.GenericDeserializer, Global.PlainConverter);

            var loader = new SettingsLoader(xmlFileLoader);
            loader.Loaded += (s, e) =>
            {
                Console.WriteLine("Loaded: {0} ({1})", e.Settings.GetType(), e.Settings.Identity);
            };

            loader.LoadSettings(xmlFileLoader.LoadFile("Examples/AppDirectory/autoMain.config"));

            var settings = new CombinableAppSettings(loader.Settings, Global.GenericCombiner);

            var cfg = settings.TryGet<ChildAutoCombinableConnectionConfig>();

            var cfgs = settings.Settings.LoadCollection<ChildAutoCombinableConnectionConfig>().ToArray();

            Assert.IsNotNull(cfg);
            Assert.AreEqual("Server=localhost;Database=workDb;User ID=admin;Password=pass;Trusted_Connection=True;Connection Timeout=60", cfg.ConnectionString);
        }
        public void SecureLoad()
        {
            KeyManager.Create();

            var providerLoader = new ProviderLoader();
            var xmlFileLoader = new XmlFileSettingsLoader(Global.GenericDeserializer, Global.PlainConverter);

            var loader = new SettingsLoader(xmlFileLoader);
            loader.Loaded += providerLoader.TryExtractConfigProtectedData;

            loader.Loaded += (s, e) =>
            {
                Console.WriteLine("Loaded: {0} ({1})", e.Settings.GetType(), e.Settings.Identity);
            };

            loader.LoadSettings(xmlFileLoader.LoadFile("Examples/AppDirectory/secureMain.config"));

            IAppSettings settings = loader.Settings;

            var addCfg = settings.TryCombine<ExampleCombineConfig>("AdditionalConfig");

            Assert.IsNotNull(addCfg);
            Assert.AreEqual("InUpDirectory", addCfg.F);

            Assert.AreEqual("Server=localhost;Database=workDb;User ID=admin;Password=pass;", settings.TryFirst<ConnectionConfig>("MyExtConnection").ConnectionString);
            Assert.AreEqual("Server=localhost;Database=workDb;User ID=admin;Password=pass;", settings.TryFirst<ConnectionConfig>("MySecuredConnection").ConnectionString);

            KeyManager.Delete();
        }