Exemple #1
0
 private void AddSectionsToUpdate(ConfigurationSourceWatcher watcher, IDictionary <string, string> sectionsToUpdate)
 {
     foreach (string section in watcher.WatchedSections)
     {
         sectionsToUpdate.Add(section, watcher.ConfigSource);
     }
 }
Exemple #2
0
 // 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);
     }
 }
Exemple #3
0
        // 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();
        }
Exemple #4
0
        // 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);
                }
            }
        }
Exemple #5
0
        /// <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);
        }
Exemple #6
0
        /// <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);
                }
            }
        }
Exemple #7
0
        // 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);
        }
Exemple #8
0
 // must be called inside lock
 private void LinkWatcherForSection(ConfigurationSourceWatcher watcher, string sectionName)
 {
     this.watchedSectionMapping.Add(sectionName, watcher);
     watcher.WatchedSections.Add(sectionName);
 }
Exemple #9
0
 // must be called inside lock
 private void RemoveConfigSourceWatcher(ConfigurationSourceWatcher watcher)
 {
     this.watchedConfigSourceMapping.Remove(watcher.ConfigSource);
     (watcher as IDisposable).Dispose();
 }