/// <summary>
 /// <inheritdoc />
 /// </summary>
 public void Remove(IConnectionStringSettings settings)
 {
     if (settings != null)
     {
         cnxSettingsCollection.Remove(
             (ConnectionStringSettings)settings.GetObject());
     }
 }
Пример #2
0
 /// <summary>
 /// Change the value for specified key
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public static void ChangeKeyValue(string key, string value, bool isConnectionString, bool isAppSetting)
 {
     if (isAppSetting)
     {
         Configuration      config      = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         AppSettingsSection App_Section = (AppSettingsSection)config.GetSection("appSettings");
         KeyValueConfigurationCollection app_settings = App_Section.Settings;
         KeyValueConfigurationElement    element      = app_settings[key];
         if (element != null)
         {
             element.Value = value;
             app_settings.Remove(key);
             app_settings.Add(element);
             config.Save(ConfigurationSaveMode.Full, true);
             ConfigurationManager.RefreshSection("appSettings");
         }
     }
     if (isConnectionString)
     {
         Configuration                      config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         ConnectionStringsSection           connectionString_Section  = (ConnectionStringsSection)config.GetSection("appSettings");
         ConnectionStringSettingsCollection connectionString_settings = connectionString_Section.ConnectionStrings;
         ConnectionStringSettings           element = connectionString_settings[key];
         if (element != null)
         {
             element.ConnectionString = "blah";
             connectionString_settings.Remove(key);
             connectionString_settings.Add(element);
             config.Save(ConfigurationSaveMode.Full, true);
             ConfigurationManager.RefreshSection("appSettings");
         }
     }
 }
Пример #3
0
        //</Snippet11>

        //<Snippet12>
        static void RemoveConnectionStrings2()
        {
            try
            {
                System.Configuration.Configuration config =
                    ConfigurationManager.OpenExeConfiguration(
                        ConfigurationUserLevel.None);

                // Clear the connection strings collection.
                ConnectionStringsSection csSection =
                    config.ConnectionStrings;
                ConnectionStringSettingsCollection csCollection =
                    csSection.ConnectionStrings;

                // Remove the element.
                csCollection.Remove("ConnStr0");


                // Save the configuration file.
                config.Save(ConfigurationSaveMode.Modified);

                Console.WriteLine(
                    "Connection string settings removed.");
            }
            catch (ConfigurationErrorsException err)
            {
                Console.WriteLine(err.ToString());
            }
        }
Пример #4
0
        public void TestInvalidClientSecret()
        {
            var clientSecretKey       = BuildConfigKey(ClientSecretKeySuffix, WebApp1);
            var sharedClientSecretKey = BuildConfigKey(ClientSecretKeySuffix);

            m_connectionStrings.Remove(clientSecretKey);
            m_connectionStrings.Remove(sharedClientSecretKey);
            AssertInvalidConfigCore("clientSecret");

            m_connectionStrings.Add(new ConnectionStringSettings(clientSecretKey, String.Empty));
            AssertInvalidConfigCore("clientSecret");

            m_connectionStrings.Remove(clientSecretKey);
            m_connectionStrings.Add(new ConnectionStringSettings(sharedClientSecretKey, String.Empty));
            AssertInvalidConfigCore("clientSecret, shared");
        }
Пример #5
0
        public void TestInvalidClientSecret()
        {
            var clientSecretKey = KeyPrefix + WebApp1 + ClientSecretKeySuffix;

            m_connectionStrings.Remove(clientSecretKey);
            m_connectionStrings.Add(new ConnectionStringSettings(clientSecretKey, " "));
            AssertExtensions.Throws <ConfigurationErrorsException>(() => m_renewer.Renew());
        }
 public static void Set(this ConnectionStringSettingsCollection collection, string key, string value)
 {
     collection.Remove(key);
     if (!string.IsNullOrWhiteSpace(value))
     {
         collection.Add(new ConnectionStringSettings(key, value));
     }
 }
Пример #7
0
 public bool Remove(string key)
 {
     if (!Keys.Contains(key))
     {
         return(false);
     }
     _actual.Remove(key);
     return(true);
 }
Пример #8
0
        //</Snippet10>


        //<Snippet11>
        static void RemoveConnectionStrings()
        {
            try
            {
                System.Configuration.Configuration config =
                    ConfigurationManager.OpenExeConfiguration(
                        ConfigurationUserLevel.None);

                // Clear the connection strings collection.
                ConnectionStringsSection csSection =
                    config.ConnectionStrings;
                ConnectionStringSettingsCollection csCollection =
                    csSection.ConnectionStrings;

                // Get the connection string setting element
                // with the specified name.
                ConnectionStringSettings cs =
                    csCollection["ConnStr0"];

                // Remove it.
                if (cs != null)
                {
                    // Remove the element.
                    csCollection.Remove(cs);

                    // Save the configuration file.
                    config.Save(ConfigurationSaveMode.Modified);

                    Console.WriteLine(
                        "Connection string settings removed.");
                }
                else
                {
                    Console.WriteLine(
                        "Connection string settings does not exist.");
                }
            }
            catch (ConfigurationErrorsException err)
            {
                Console.WriteLine(err.ToString());
            }
        }
        /// <summary>
        /// Merges two ConnectionStringSettingsCollections.
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <remarks>Used by <see cref="Williablog.Core.Configuration.ConfigSystem">ConfigSystem</c> to merge ConnectionStrings</remarks>
        public static ConnectionStringSettingsCollection Merge(this ConnectionStringSettingsCollection first, ConnectionStringSettingsCollection second)
        {
            if (second == null)
            {
                return(first);
            }

            foreach (ConnectionStringSettings item in second)
            {
                ConnectionStringSettings itemInSecond = item;
                ConnectionStringSettings existingItem = first.Cast <ConnectionStringSettings>().FirstOrDefault(x => x.Name == itemInSecond.Name);

                if (existingItem != null)
                {
                    first.Remove(item);
                }

                first.Add(item);
            }

            return(first);
        }