// must be called outside of lock private void RefreshAndValidateSections(IDictionary <string, string> localSectionsToRefresh, IDictionary <string, string> externalSectionsToRefresh, out ICollection <string> sectionsToNotify, out IDictionary <string, string> sectionsWithChangedConfigSource) { sectionsToNotify = new List <string>(); sectionsWithChangedConfigSource = new Dictionary <string, string>(); // refresh local sections and determine what to do. foreach (KeyValuePair <string, string> sectionMapping in localSectionsToRefresh) { SqlConfigurationManager.RefreshSection(sectionMapping.Key, this.data); ConfigurationSection section = SqlConfigurationManager.GetSection(sectionMapping.Key, this.data) as ConfigurationSection; string refreshedConfigSource = section != null ? section.SectionInformation.ConfigSource : NullConfigSource; if (!sectionMapping.Value.Equals(refreshedConfigSource)) { sectionsWithChangedConfigSource.Add(sectionMapping.Key, refreshedConfigSource); } // notify anyway, since it might have been updated. sectionsToNotify.Add(sectionMapping.Key); } // refresh external sections and determine what to do. foreach (KeyValuePair <string, string> sectionMapping in externalSectionsToRefresh) { SqlConfigurationManager.RefreshSection(sectionMapping.Key, this.data); ConfigurationSection section = SqlConfigurationManager.GetSection(sectionMapping.Key, this.data) as ConfigurationSection; string refreshedConfigSource = (section != null) ? section.SectionInformation.ConfigSource : NullConfigSource; if (!sectionMapping.Value.Equals(refreshedConfigSource)) { sectionsWithChangedConfigSource.Add(sectionMapping.Key, refreshedConfigSource); // notify only if che config source changed sectionsToNotify.Add(sectionMapping.Key); } } }
private static void PrepareConfigSystem(SqlConfigurationData data) { if (SqlConfigurationManager.initState < SqlConfigurationManager.InitState.Usable) { SqlConfigurationManager.EnsureConfigurationSystem(data); } }
/// <summary> /// /// </summary> /// <param name="sectionName"></param> /// <param name="section"></param> /// <param name="data"></param> public static void SaveSection(string sectionName, SerializableConfigurationSection section, SqlConfigurationData data) { if (!string.IsNullOrEmpty(sectionName)) { SqlConfigurationManager.PrepareConfigSystem(data); SqlConfigurationManager.configSystem.SaveSection(sectionName, section); } }
/// <summary> /// /// </summary> /// <param name="sectionName"></param> /// <param name="data"></param> public static void RemoveSection(string sectionName, SqlConfigurationData data) { if (!string.IsNullOrEmpty(sectionName)) { SqlConfigurationManager.PrepareConfigSystem(data); SqlConfigurationManager.configSystem.RemoveSection(sectionName); } }
/// <summary> /// Retrieves a specified configuration section for the current application's configuration /// </summary> /// <param name="sectionName">The configuration section name.</param> /// <param name="data">The configuration data for this connection.</param> /// <returns>The specified System.Configuration.ConfigurationSection object, or null if the section does not exist.</returns> public static object GetSection(string sectionName, SqlConfigurationData data) { if (string.IsNullOrEmpty(sectionName)) { return(null); } SqlConfigurationManager.PrepareConfigSystem(data); return(SqlConfigurationManager.configSystem.GetSection(sectionName)); }
/// <summary> /// Retrieves a section from SqlConfiguration, and starts watching for /// its changes if not watching already. /// </summary> /// <param name="sectionName">The section name.</param> /// <returns>The section, or null if it doesn't exist.</returns> public ConfigurationSection GetSection(string sectionName) { object section = SqlConfigurationManager.GetSection(sectionName, data); ConfigurationSection configurationSection = section as ConfigurationSection; if (configurationSection != null) { lock (lockMe) { if (!IsWatchingSection(sectionName)) // should only be true sporadically { SetWatcherForSection(sectionName, this.data.ConnectionString); } } } return(configurationSection); }
/// <summary> /// <exclude/> /// </summary> /// <param name="configSource">The name of the updated configuration source.</param> public void ExternalConfigSourceChanged(string configSource) { string[] sectionsToNotify; lock (lockMe) { ConfigurationSourceWatcher watcher = null; this.watchedConfigSourceMapping.TryGetValue(configSource, out watcher); sectionsToNotify = new string[watcher.WatchedSections.Count]; watcher.WatchedSections.CopyTo(sectionsToNotify, 0); } foreach (string sectionName in sectionsToNotify) { SqlConfigurationManager.RefreshSection(sectionName, this.data); } NotifyUpdatedSections(sectionsToNotify); }
/// <summary> /// /// </summary> /// <param name="sectionName"></param> public void RemoveSection(string sectionName) { if ((sectionName == null) || (sectionName.Trim().Equals(String.Empty))) { throw new ArgumentNullException(sectionName); } SqlConfigurationManager.RemoveSection(sectionName, data); lock (lockMe) { if (IsWatchingSection(sectionName)) { ConfigSourceChanged(sectionName); ConfigurationSourceWatcher watcher = this.watchedSectionMapping[sectionName]; UnlinkWatcherForSection(watcher, sectionName); } } }
/// <summary> /// Saves a section from SqlConfiguration, and starts watching for /// its changes if not watching already. /// </summary> /// <param name="sectionName">The section name.</param> /// <param name="section">The section.</param> /// <returns></returns> public void SaveSection(string sectionName, SerializableConfigurationSection section) { if (section == null) { throw new ArgumentNullException("section"); } if ((sectionName == null) || (sectionName.Trim().Equals(String.Empty))) { throw new ArgumentNullException(sectionName); } SqlConfigurationManager.SaveSection(sectionName, section, data); lock (lockMe) { if (!IsWatchingSection(sectionName)) { SetWatcherForSection(sectionName, section.SectionInformation.ConfigSource); } } }