public void Clear()
        {
            var collection = new KeyValueConfigurationCollection();

            collection.Add("foo", "foo");
            Assert.Equal("foo", collection["foo"].Value);
            collection.Clear();
            Assert.Null(collection["foo"]);
        }
        public override void Save(IKeyedDataStore store)
        {
            KeyValueConfigurationCollection appSettings = _configuration.AppSettings.Settings;

            appSettings.Clear();
            foreach (string key in store.Keys)
            {
                appSettings.Add(key, store[key]);
            }
        }
Exemple #3
0
        private void InitConfig()
        {
            Configuration manager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            KeyValueConfigurationCollection configCollection = manager.AppSettings.Settings;

            configCollection.Clear();
            configCollection.Add("keybind", "146");
            configCollection.Add("mean", "0.16");
            configCollection.Add("sigma", "0.02");
            configCollection.Add("clickOption", "left");
            manager.Save(ConfigurationSaveMode.Full);
            ReadConfig();
        }
        public static void SaveIpRangeSettings(NameValueCollection ipRanges)
        {
            // Open the application configuration file and get the IP Ranges Section
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            KeyValueConfigurationCollection ipRangeSettings = OpenIpRangeSettings(config);

            // Clear out the existing ranges to fill with the new ones
            ipRangeSettings.Clear();

            // Add the IP ranges and save the config file
            foreach (string key in ipRanges.AllKeys)
            {
                ipRangeSettings.Add(key, ipRanges[key]);
            }
            config.Save();
        }
Exemple #5
0
        public static void SaveAppSetting(string fileName, Dictionary <string, string> keyValues)
        {
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();

            configFileMap.ExeConfigFilename = fileName;
            Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            KeyValueConfigurationCollection settings = configuration.AppSettings.Settings;

            settings.Clear();

            foreach (KeyValuePair <string, string> item in keyValues)
            {
                settings.Add(item.Key, item.Value);
            }

            configuration.Save();
        }
Exemple #6
0
        private void Save(KeyValuePair <string, IDictionary <string, object> > section)
        {
            IDictionary <string, object> settings = section.Value;

            if (section.Key == "appSettings")
            {
                KeyValueConfigurationCollection appSettings = _configuration.AppSettings.Settings;
                appSettings.Clear();
                foreach (string key in settings.Keys)
                {
                    appSettings.Add(key, settings[key].ToString());
                }
            }
            else
            {
                // TODO: At the moment, we are only going to reserialize the 'appSettings' section
            }
        }