private void AddSectionsToUpdate(ConfigurationSourceWatcher watcher, IDictionary <string, string> sectionsToUpdate)
 {
     foreach (string section in watcher.WatchedSections)
     {
         sectionsToUpdate.Add(section, watcher.ConfigSource);
     }
 }
Ejemplo n.º 2
0
        private ConfigurationSourceWatcher CreateWatcherForConfigSource(string configSource)
        {
            ConfigurationSourceWatcher watcher;

            if (string.Empty == configSource)
            {
                watcher = new ConfigurationFileSourceWatcher(configurationFilepath,
                                                             configSource,
                                                             refresh,
                                                             this.refreshInterval,
                                                             OnConfigurationChanged);
                configFileWatcher = watcher;
            }
            else
            {
                watcher = new ConfigurationFileSourceWatcher(configurationFilepath,
                                                             configSource,
                                                             refresh && !NullConfigSource.Equals(configSource),
                                                             this.refreshInterval,
                                                             OnExternalConfigurationChanged);
            }

            watchedConfigSourceMapping.Add(configSource, watcher);

            return(watcher);
        }
 private void AddSectionsToUpdate(ConfigurationSourceWatcher watcher, IDictionary<string, string> sectionsToUpdate)
 {
     foreach (string str in watcher.WatchedSections)
     {
         sectionsToUpdate.Add(str, 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);
     }
 }
 private ConfigurationSourceWatcher CreateWatcherForConfigSource(string configSource)
 {
     ConfigurationSourceWatcher watcher = null;
     if (string.Empty == configSource)
     {
         watcher = new ConfigurationFileSourceWatcher(this.configurationFilepath, configSource, this.refresh, new ConfigurationChangedEventHandler(this.OnConfigurationChanged));
         this.configFileWatcher = watcher;
     }
     else
     {
         watcher = new ConfigurationFileSourceWatcher(this.configurationFilepath, configSource, this.refresh && !"__null__".Equals(configSource), new ConfigurationChangedEventHandler(this.OnExternalConfigurationChanged));
     }
     this.watchedConfigSourceMapping.Add(configSource, watcher);
     return 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 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 RemoveConfigSourceWatcher(ConfigurationSourceWatcher watcher)
 {
     this.watchedConfigSourceMapping.Remove(watcher.ConfigSource);
     (watcher as IDisposable).Dispose();
 }
 // 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 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();
 }
        private ConfigurationSourceWatcher CreateWatcherForConfigSource(string configSource)
        {
            ConfigurationSourceWatcher watcher;

            if (string.Empty == configSource)
            {
                watcher = new ConfigurationFileSourceWatcher(configurationFilepath,
                                                             configSource,
                                                             refresh,
                                                             this.refreshInterval,
                                                             OnConfigurationChanged);
                configFileWatcher = watcher;
            }
            else
            {
                watcher = new ConfigurationFileSourceWatcher(configurationFilepath,
                                                             configSource,
                                                             refresh && !NullConfigSource.Equals(configSource),
                                                             this.refreshInterval,
                                                             OnExternalConfigurationChanged);
            }

            watchedConfigSourceMapping.Add(configSource, watcher);

            return watcher;
        }