Esempio n. 1
0
        // 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);
                }
            }
        }
Esempio n. 2
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);
        }