private void AddSectionsToUpdate(ConfigurationSourceWatcher watcher, IDictionary <string, string> sectionsToUpdate) { foreach (string section in watcher.WatchedSections) { sectionsToUpdate.Add(section, watcher.ConfigSource); } }
// must be called inside lock private void UnlinkWatcherForSection(ConfigurationSourceWatcher watcher, string sectionName) { this.watchedSectionMapping.Remove(sectionName); watcher.WatchedSections.Remove(sectionName); if (watcher.WatchedSections.Count == 0 && configSqlWatcher != watcher) { RemoveConfigSourceWatcher(watcher); } }
// must be called inside lock private void SetWatcherForSection(string sectionName, string configSource) { ConfigurationSourceWatcher currentConfigSourceWatcher = null; this.watchedConfigSourceMapping.TryGetValue(configSource, out currentConfigSourceWatcher); if (currentConfigSourceWatcher == null) { currentConfigSourceWatcher = CreateWatcherForConfigSource(configSource, sectionName); } else { currentConfigSourceWatcher.StopWatching(); } LinkWatcherForSection(currentConfigSourceWatcher, sectionName); currentConfigSourceWatcher.StartWatching(); }
// must be called outside lock private void UpdateWatcherForSection(string sectionName, string configSource) { ConfigurationSourceWatcher currentSectionWatcher = null; this.watchedSectionMapping.TryGetValue(sectionName, out currentSectionWatcher); if (currentSectionWatcher == null || currentSectionWatcher.ConfigSource != configSource) { if (currentSectionWatcher != null) { UnlinkWatcherForSection(currentSectionWatcher, sectionName); } if (configSource != null) { SetWatcherForSection(sectionName, configSource); } } }
/// <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); } } }
// must be called inside lock private ConfigurationSourceWatcher CreateWatcherForConfigSource(string configSource, string sectionName) { ConfigurationSourceWatcher watcher = null; if (string.Empty == configSource) { watcher = new ConfigurationSqlSourceWatcher(this.data.ConnectionString, this.data.GetStoredProcedure, sectionName, this.refresh, new ConfigurationChangedEventHandler(OnConfigurationChanged)); configSqlWatcher = watcher; } else { watcher = new ConfigurationSqlSourceWatcher(this.data.ConnectionString, this.data.GetStoredProcedure, sectionName, this.refresh && !NullConfigSource.Equals(configSource), new ConfigurationChangedEventHandler(OnExternalConfigurationChanged)); } this.watchedConfigSourceMapping.Add(configSource, watcher); return(watcher); }
// must be called inside lock private void LinkWatcherForSection(ConfigurationSourceWatcher watcher, string sectionName) { this.watchedSectionMapping.Add(sectionName, watcher); watcher.WatchedSections.Add(sectionName); }
// must be called inside lock private void RemoveConfigSourceWatcher(ConfigurationSourceWatcher watcher) { this.watchedConfigSourceMapping.Remove(watcher.ConfigSource); (watcher as IDisposable).Dispose(); }