Add() public method

public Add ( KeyValueConfigurationElement keyValue ) : void
keyValue KeyValueConfigurationElement
return void
        private static KeyValueConfigurationCollection GetKeyValueCollection()
        {
            var collection = new KeyValueConfigurationCollection();
            collection.Add("Name", "Value");
            collection.Add("Email", "*****@*****.**");
            collection.Add("Company", "IBM");
            collection.Add("Year", "2011");

            return collection;
        }
 protected override void AddAppConfigSpecificItems(KeyValueConfigurationCollection kvcc)
 {
     // NOTE: insert a valid connection string to a SqlServer 2008 db
     try
     {
         if (kvcc["SqlServer2008ConnectionString"] == null) 
             kvcc.Add("SqlServer2008ConnectionString", "Data Source=localhost\\SQLEXPRESS;Database=NTSTests;Integrated Security=SSPI;");
     }
     catch
     {
         kvcc.Add("SqlServer2008ConnectionString", "Data Source=localhost\\SQLEXPRESS;Database=NTSTests;Integrated Security=SSPI;");
     }
 }
        public void Should_map_features()
        {
            var settings = new KeyValueConfigurationCollection();
            settings.Add(new KeyValueConfigurationElement("Feature", "true"));
            settings.Add(new KeyValueConfigurationElement("Feature1", "false"));
            var mapper = new KeyValueFeatureMapper();

            var feature = mapper.Map(settings).ToList();

            feature.Count.ShouldBe(2);

            feature[0].Name.ShouldBe("Feature");
            feature[0].State.ShouldBe(true);
        }
Beispiel #4
0
        public static KeyValueConfigurationCollection ToConfig(
            IDictionary<string, string> dictionary)
        {
            KeyValueConfigurationCollection keyValueConfigurationCollection = new KeyValueConfigurationCollection();

            foreach (var item in dictionary)
            {
                keyValueConfigurationCollection.Add(item.Key, item.Value);
            }
            return keyValueConfigurationCollection;
        }
Beispiel #5
0
        public FDUserSettings()
        {
            localConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
            settings = localConfig.AppSettings.Settings;
            RestoresEnabled = false;

            if(settings["DataStoreFile"] != null)
                DataStoreFile = settings["DataStoreFile"].Value;
            else {
                settings.Add ("DataStoreFile", "index.sqlite");
                DataStoreFile = settings["DataStoreFile"].Value;
            }

            if (localConfig.AppSettings.Settings["DataStorePath"] != null)
                DataStorePath = settings["DataStorePath"].Value;
            else {
                settings.Add ("DataStorePath", System.IO.Path.GetDirectoryName(localConfig.FilePath));
                DataStorePath = settings["DataStorePath"].Value;
            }

            if(settings["AWSAccessKey"] != null)
                AWSAccessKey = settings["AWSAccessKey"].Value;
            else {
                settings.Add ("AWSAccessKey", "");
                AWSAccessKey = settings["AWSAccessKey"].Value;
            }

            if(settings["AWSSecretKey"] != null)
                AWSSecretKey = settings["AWSSecretKey"].Value;
            else {
                settings.Add ("AWSSecretKey", "");
                AWSSecretKey = settings["AWSSecretKey"].Value;
            }

            string AWSRegionTemp;
            if(settings["AWSRegion"] != null)
                    AWSRegionTemp = settings["AWSRegion"].Value;
            else {
                settings.Add ("AWSRegion", "");
                AWSRegionTemp = settings["AWSRegion"].Value;
            }

            if(!String.IsNullOrWhiteSpace(AWSRegionTemp)) AWSRegion = int.Parse(AWSRegionTemp);
            else AWSRegion = 0;

            if(settings["AWSGlacierVaultName"] != null)
                AWSGlacierVaultName = settings["AWSGlacierVaultName"].Value;
            else {
                settings.Add ("AWSGlacierVaultName", "");
                AWSGlacierVaultName = settings["AWSGlacierVaultName"].Value;
            }

            CurrentDataStore = DataStorePath + System.IO.Path.DirectorySeparatorChar + DataStoreFile;

            localConfig.Save (ConfigurationSaveMode.Modified);
        }
        /// <summary>
        /// Returns merged settings collection
        /// </summary>
        private KeyValueConfigurationCollection Merge(List<String> paths)
        {
            var mergedSettings = new KeyValueConfigurationCollection();

            foreach (var path in paths)
            {
                var settings = GetApplicationSettingsFromDirectory(path);

                if (settings == null)
                    continue;

                foreach (var key in settings.AllKeys)
                {
                    var value = settings[key].Value;

                    mergedSettings.Remove(key);
                    mergedSettings.Add(key, value);
                }                
            }

            return mergedSettings;
        }
 private static void replaceSetting(KeyValueConfigurationCollection appSettings, string key, string value)
 {
     appSettings.Remove(key);
     appSettings.Add(key, value);
 }
        protected override ConfigurationSection Arrange_GetLocalSourceSection()
        {
            KeyValueConfigurationCollection localSettings = new KeyValueConfigurationCollection();
            localSettings.Add(new KeyValueConfigurationElement("key1", "overwrite"));
            localSettings.Add(new KeyValueConfigurationElement("key3", "connstr3"));
            localSettings.EmitClear = true;

            return new DummySectionWithCollections
            {
                AppSettingsLikeCollection = localSettings
            };
        }
        protected override ConfigurationSection Arrange_GetParentSourceSection()
        {
            KeyValueConfigurationCollection parentSettings = new KeyValueConfigurationCollection();
            parentSettings.Add(new KeyValueConfigurationElement("key1", "value1"));
            parentSettings.Add(new KeyValueConfigurationElement("key2", "value2"));

            return new DummySectionWithCollections
            {
                AppSettingsLikeCollection = parentSettings
            };
        }
 private static KeyValueConfigurationCollection Convert(NameValueCollection collection)
 {
     var settings = new KeyValueConfigurationCollection();
     foreach (var key in collection.AllKeys)
     {
         settings.Add(key, ConfigurationManager.AppSettings[key]);
     }
     return settings;
 }
 public void Test()
 {
     KeyValueConfigurationCollection collection = new KeyValueConfigurationCollection();
     collection.Add("key", "value");
 }
Beispiel #12
0
 private void updateKV(KeyValueConfigurationCollection kv, string key_name, string value_string)
 {
     kv.Remove(key_name);
     kv.Add(key_name, value_string);
 }
 protected override void AddAppConfigSpecificItems(KeyValueConfigurationCollection kvcc)
 {
     // NOTE: insert a valid connection string to a postgis db
     if (kvcc["PostGisConnectionString"] == null)
         kvcc.Add("PostGisConnectionString", "Server=ivv-sqlt3.ivv-aachen.de;Port=5432;Database=obe;Integrated Security=SSPI;");            
 }