示例#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);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Retrieves a section from SqlConfiguration, and starts watching for
        /// its changes if not watching already.
        /// </summary>
        /// <param name="sectionName">The section name.</param>
        /// <returns>The section, or null if it doesn't exist.</returns>
        public ConfigurationSection GetSection(string sectionName)
        {
            object section = SqlConfigurationManager.GetSection(sectionName, data);
            ConfigurationSection configurationSection = section as ConfigurationSection;

            if (configurationSection != null)
            {
                lock (lockMe)
                {
                    if (!IsWatchingSection(sectionName))                        // should only be true sporadically
                    {
                        SetWatcherForSection(sectionName, this.data.ConnectionString);
                    }
                }
            }

            return(configurationSection);
        }