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 && configFileWatcher != watcher) { RemoveConfigSourceWatcher(watcher); } }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// </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); } RefreshExternalSections(sectionsToNotify); NotifyUpdatedSections(sectionsToNotify); }
// 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); } } }
// 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); } else { currentConfigSourceWatcher.StopWatching(); } LinkWatcherForSection(currentConfigSourceWatcher, sectionName); currentConfigSourceWatcher.StartWatching(); // must watch the app.config if not watching already if ((string.Empty != configSource) && (!IsWatchingConfigSource(string.Empty))) { CreateWatcherForConfigSource(string.Empty).StartWatching(); } }
// must be called inside lock private ConfigurationSourceWatcher CreateWatcherForConfigSource(string configSource) { ConfigurationSourceWatcher watcher = null; if (string.Empty == configSource) { watcher = new ConfigurationFileSourceWatcher(this.configurationFilepath, configSource, this.refresh, new ConfigurationChangedEventHandler(OnConfigurationChanged)); configFileWatcher = watcher; } else { watcher = new ConfigurationFileSourceWatcher(this.configurationFilepath, configSource, 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(); }