コード例 #1
0
 /// <summary>
 /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
 /// Adds a handler to be called when changes to section <code>sectionName</code> are detected.
 /// </summary>
 /// <param name="sectionName">The name of the section to watch for.</param>
 /// <param name="handler">The handler.</param>
 public void AddSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     lock (eventHandlersLock)
     {
         eventHandlers.AddHandler(sectionName, handler);
     }
 }
コード例 #2
0
 private void CheckHandler(ConfigurationChangedEventHandler handler)
 {
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
 }
コード例 #3
0
        private void DoNotifyUpdatedSection(string sectionName)
        {
            Delegate[] invocationList;

            lock (eventHandlersLock)
            {
                ConfigurationChangedEventHandler callbacks = (ConfigurationChangedEventHandler)eventHandlers[sectionName];
                if (callbacks == null)
                {
                    return;
                }
                invocationList = callbacks.GetInvocationList();
            }

            ConfigurationChangedEventArgs eventData = new ConfigurationChangedEventArgs(sectionName);

            try
            {
                foreach (ConfigurationChangedEventHandler callback in invocationList)
                {
                    if (callback != null)
                    {
                        callback(this, eventData);
                    }
                }
            }
            catch // (Exception e)
            {
                //EventLog.WriteEntry(GetEventSourceName(), Resources.ExceptionEventRaisingFailed + GetType().FullName + " :" + e.Message);
            }
        }
		public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
		{
			lock (eventHandlersLock)
			{
				eventHandlers.RemoveHandler(CanonicalizeSectionName(sectionName), handler);
			}
		}
コード例 #5
0
        // must be called outside lock
        private void NotifyUpdatedSections(IEnumerable <string> sectionsToNotify)
        {
            foreach (string sectionName in sectionsToNotify)
            {
                ConfigurationChangedEventHandler callbacks = (ConfigurationChangedEventHandler)eventHandlers[sectionName];
                if (callbacks == null)
                {
                    continue;
                }

                ConfigurationSqlChangedEventArgs eventData = new ConfigurationSqlChangedEventArgs(this.data.ConnectionString, this.data.GetStoredProcedure, sectionName);
                try
                {
                    foreach (ConfigurationChangedEventHandler callback in callbacks.GetInvocationList())
                    {
                        if (callback != null)
                        {
                            callback(this, eventData);
                        }
                    }
                }
                catch                // (Exception e)
                {
                    //EventLog.WriteEntry(GetEventSourceName(), Resources.ExceptionEventRaisingFailed + GetType().FullName + " :" + e.Message);
                }
            }
        }
 public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     lock (eventHandlersLock)
     {
         eventHandlers.RemoveHandler(CanonicalizeSectionName(sectionName), handler);
     }
 }
 public void AddSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     lock (this.eventHandlersLock)
     {
         this.eventHandlers.AddHandler(sectionName, handler);
     }
 }
コード例 #8
0
        /// <summary>
        /// Adds a handler to be called when changes to section <code>sectionName</code> are detected.
        /// This call should always be followed by a <see cref="RemoveSectionChangeHandler"/>. Failure to remove change
        /// handlers will result in .Net resource leaks.
        /// </summary>
        /// <param name="sectionName">The name of the section to watch for.</param>
        /// <param name="handler">The handler.</param>
        public void AddSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
        {
            CheckSectionName(sectionName);
            CheckHandler(handler);

            implementation.AddSectionChangeHandler(sectionName, handler);
        }
コード例 #9
0
 public ConfigurationFileSourceWatcher(string configurationFilepath, string configSource, bool refresh, ConfigurationChangedEventHandler changed) : base(configSource, refresh, changed)
 {
     this.configurationFilepath = configurationFilepath;
     if (refresh)
     {
         this.SetUpWatcher(changed);
     }
 }
コード例 #10
0
 private void SetUpWatcher(int refreshInterval, ConfigurationChangedEventHandler changed)
 {
     this.configWatcher =
         new ConfigurationChangeFileWatcher(
             GetFullFileName(this.configurationFilepath, this.ConfigSource),
             this.ConfigSource);
     this.configWatcher.SetPollDelayInMilliseconds(refreshInterval);
     this.configWatcher.ConfigurationChanged += changed;
 }
コード例 #11
0
        /// <summary>
        /// Raises the <see cref="ConfigurationSourceHandler.ConfigurationSectionChanged"/> event.
        /// </summary>
        /// <param name="sectionName">The name of the section that was changed.</param>
        protected void DoConfigurationSectionChanged(string sectionName)
        {
            ConfigurationChangedEventHandler handler = ConfigurationSectionChanged;

            if (handler != null)
            {
                handler(this, new ConfigurationChangedEventArgs(sectionName));
            }
        }
コード例 #12
0
 private void SetUpWatcher(int refreshInterval, ConfigurationChangedEventHandler changed)
 {
     this.configWatcher =
         new ConfigurationChangeFileWatcher(
             GetFullFileName(this.configurationFilepath, this.ConfigSource),
             this.ConfigSource);
     this.configWatcher.SetPollDelayInMilliseconds(refreshInterval);
     this.configWatcher.ConfigurationChanged += changed;
 }
コード例 #13
0
        /// <summary>
        /// 
        /// </summary>
        public ConfigurationSqlSourceWatcher(string connectString, string getStoredProc, string configSource, bool refresh, ConfigurationChangedEventHandler changed)
            : base(configSource, refresh, changed)
        {
            this.connectString = connectString;
            this.getStoredProc = getStoredProc;

            if (refresh)
            {
                SetUpWatcher(changed);
            }
        }
コード例 #14
0
        public void AddSection(string sectionName, object configurationSection, ConfigurationChangedEventHandler changed, IConfigurationChangeWatcherFactory factory)
        {
            lock (lockMe)
            {
                if (DoesWatcherExistFor(sectionName) == false)
                {
                    IConfigurationChangeWatcher watcher = factory.CreateConfigurationChangeWatcher();
                    AddConfigurationWatcherForSection(changed, watcher);
                }

                AddSection(sectionName, configurationSection);
            }
        }
コード例 #15
0
        public void AddSection(string sectionName, object configurationSection, ConfigurationChangedEventHandler changed, IConfigurationChangeWatcherFactory factory)
        {
            lock (lockMe)
            {
                if (DoesWatcherExistFor(sectionName) == false)
                {
                    IConfigurationChangeWatcher watcher = factory.CreateConfigurationChangeWatcher();
                    AddConfigurationWatcherForSection(changed, watcher);
                }

                AddSection(sectionName, configurationSection);
            }
        }
コード例 #16
0
        internal void DoSourceSectionChanged(string section)
        {
            if (DisposeCallCount > 0)
            {
                throw new Exception();
            }

            ConfigurationChangedEventHandler handler = SectionChangedHandlers[section] as ConfigurationChangedEventHandler;

            if (handler != null)
            {
                handler(this, new ConfigurationChangedEventArgs(section));
            }
        }
コード例 #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationFileSourceWatcher"/> class.
        /// </summary>
        /// <param name="configurationFilepath">The path for the configuration file to watch.</param>
        /// <param name="configSource">The identification of the configuration source.</param>
        /// <param name="refresh"><b>true</b> if changes should be notified, <b>false</b> otherwise.</param>
        /// <param name="refreshInterval">The poll interval in milliseconds.</param>
        /// <param name="changed">The callback for changes notification.</param>
        public ConfigurationFileSourceWatcher(
            string configurationFilepath,
            string configSource,
            bool refresh,
            int refreshInterval,
            ConfigurationChangedEventHandler changed)
            : base(configSource, refresh, changed)
        {
            this.configurationFilepath = configurationFilepath;

            if (refresh)
            {
                SetUpWatcher(refreshInterval, changed);
            }
        }
コード例 #18
0
        internal void FireConfigurationSectionChangedNotification(string sectionName)
        {
            ConfigurationChangedEventHandler callbacks = (ConfigurationChangedEventHandler)eventHandlers[sectionName];

            if (callbacks != null)
            {
                ConfigurationChangedEventArgs eventData = new ConfigurationChangedEventArgs(sectionName);
                foreach (ConfigurationChangedEventHandler callback in callbacks.GetInvocationList())
                {
                    if (callback != null)
                    {
                        callback(this, eventData);
                    }
                }
            }
        }
コード例 #19
0
        protected virtual void OnConfigurationChanged()
        {
            ConfigurationChangedEventHandler callbacks = (ConfigurationChangedEventHandler)eventHandlers[configurationChangedKey];
            ConfigurationChangedEventArgs    eventData = new ConfigurationChangedEventArgs(Path.GetFullPath(configFilePath), configurationSectionName);

            try
            {
                if (callbacks != null)
                {
                    callbacks(this, eventData);
                }
            }
            catch (Exception e)
            {
                EventLog.WriteEntry(eventSourceName, SR.ExceptionEventRaisingFailed + ":" + e.Message);
            }
        }
コード例 #20
0
        public void NotifyUpdatedSections(IEnumerable <string> sectionsToNotify)
        {
            foreach (string rawSectionName in sectionsToNotify)
            {
                String sectionName = CanonicalizeSectionName(rawSectionName);

                Delegate[] invocationList = null;

                lock (eventHandlersLock)
                {
                    ConfigurationChangedEventHandler callbacks = (ConfigurationChangedEventHandler)eventHandlers[sectionName];
                    if (callbacks == null)
                    {
                        continue;
                    }
                    invocationList = callbacks.GetInvocationList();
                }

                ConfigurationChangedEventArgs eventData = new ConfigurationChangedEventArgs(sectionName);
                foreach (ConfigurationChangedEventHandler callback in invocationList)
                {
                    try
                    {
                        if (callback != null)
                        {
                            callback(this, eventData);
                        }
                    }
                    catch (Exception e)
                    {
                        ManageabilityExtensionsLogger.LogException(e,
                                                                   String.Format(Resources.Culture,
                                                                                 Resources.ExceptionErrorOnCallbackForSectionUpdate,
                                                                                 sectionName,
                                                                                 callback.ToString()));
                    }
                }
            }
        }
コード例 #21
0
        /// <summary>
        /// <para>Raises the <see cref="ConfigurationChanged"/> event.</para>
        /// </summary>
        protected virtual void OnConfigurationChanged()
        {
            ConfigurationChangedEventHandler callbacks = (ConfigurationChangedEventHandler)eventHandlers[configurationChangedKey];
            ConfigurationChangedEventArgs    eventData = this.BuildEventData();

            try
            {
                if (callbacks != null)
                {
                    foreach (ConfigurationChangedEventHandler callback in callbacks.GetInvocationList())
                    {
                        if (callback != null)
                        {
                            callback(this, eventData);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogException(e);
            }
        }
コード例 #22
0
        /// <summary>
        /// <para>
        /// Reads configuration settings for a user-defined configuration section.
        /// </para>
        /// </summary>
        /// <param name="sectionName">
        /// <para>The configuration section to read.</para>
        /// </param>
        /// <returns>
        /// <para>The configuration settings for <paramref name="sectionName"/>.</para>
        /// </returns>
        /// <exception cref="ArgumentException">
        /// <para><paramref name="sectionName"/>can not be <see langword="null"/> (Nothing in Visual Basic).</para>
        /// </exception>
        /// <exception cref="ConfigurationException">
        /// <para><paramref name="sectionName"/> is not valid for this configuration.</para>
        /// </exception>
        public object ReadConfiguration(string sectionName)
        {
            ValidateSection(sectionName);

            object configurationSection = sections.GetSection(sectionName);

            if (IsConfigurationSectionCached(configurationSection))
            {
                return(configurationSection);
            }

            IStorageProviderReader storageProviderReader = CreateStorageProvider(sectionName);

            object configurationSettings = storageProviderReader.Read();

            if (configurationSettings == null)
            {
                return(null);
            }

            ITransformer transformer = CreateTransformer(sectionName);

            if (transformer != null)
            {
                configurationSection = transformer.Deserialize(configurationSettings);
            }
            else
            {
                configurationSection = configurationSettings;
            }

            ConfigurationChangedEventHandler changed = new ConfigurationChangedEventHandler(OnExternalConfigurationChanged);

            sections.AddSection(sectionName, configurationSection, changed, storageProviderReader);

            return(configurationSection);
        }
コード例 #23
0
		/// <summary>
		/// Remove a handler to be called when changes to section <code>sectionName</code> are detected.
		/// </summary>
		/// <param name="sectionName">The name of the section to watch for.</param>
		/// <param name="handler">The handler.</param>
		public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
		{
            implementationByConnectionString[data.ConnectionString].RemoveSectionChangeHandler(sectionName, handler);
		}
コード例 #24
0
 void IConfigurationSource.RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     throw new NotImplementedException();
 }
コード例 #25
0
 /// <summary>
 /// Adds a handler to be called when changes to section <code>sectionName</code> are detected.
 /// This call should always be followed by a <see cref="RemoveSectionChangeHandler"/>. Failure to remove change
 /// handlers will result in .Net resource leaks.
 /// </summary>
 /// <param name="sectionName">The name of the section to watch for.</param>
 /// <param name="handler">The handler.</param>
 public void AddSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     implementationByFilepath[configurationFilepath].AddSectionChangeHandler(sectionName, handler);
 }
コード例 #26
0
 private void SetUpWatcher(ConfigurationChangedEventHandler changed)
 {
     this.configWatcher = new ConfigurationChangeFileWatcher(GetFullFileName(this.configurationFilepath, this.ConfigSource), this.ConfigSource);
     this.configWatcher.ConfigurationChanged += changed;
 }
コード例 #27
0
 public void AddSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     throw new NotImplementedException();
 }
 public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     this.notificationCoordinator.RemoveSectionChangeHandler(sectionName, handler);
 }
コード例 #29
0
		private void CheckHandler(ConfigurationChangedEventHandler handler)
		{
			if (handler == null)
			{
				throw new ArgumentNullException("handler");
			}
		}
コード例 #30
0
 public ConfigurationSourceWatcher(string configSource, bool refresh, ConfigurationChangedEventHandler changed)
 {
     this.configurationSource = configSource;
     this.watchedSections     = new List <string>();
 }
コード例 #31
0
 public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
 }
 ///<summary>
 /// Removes a change handler from a section.
 ///</summary>
 ///<param name="sectionName">
 /// The section to remove the handler.
 /// </param>
 ///<param name="handler">
 /// The handler to remove.
 /// </param>
 public void RemoveSectionChangeHandler(string sectionName,
                                        ConfigurationChangedEventHandler handler)
 {
     notificationCoordinator.RemoveSectionChangeHandler(sectionName, handler);
 }
コード例 #33
0
 private void AddConfigurationWatcherForSection(ConfigurationChangedEventHandler changed, IConfigurationChangeWatcher watcher)
 {
     watcher.ConfigurationChanged += changed;
     watcher.StartWatching();
     ConfigurationWatcherCache.Add(watcher.SectionName, watcher);
 }
コード例 #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationSourceWatcher"/> class.
 /// </summary>
 /// <param name="configSource">The identification of the medium.</param>
 /// <param name="refresh"><b>true</b> if changes should be notified, <b>false</b> otherwise.</param>
 /// <param name="changed">The callback for changes notification.</param>
 protected ConfigurationSourceWatcher(string configSource, bool refresh, ConfigurationChangedEventHandler changed)
 {
     this.configurationSource = configSource;
     this.watchedSections = new List<string>();
 }
コード例 #35
0
 /// <summary>
 /// Remove a handler to be called when changes to section <code>sectionName</code> are detected.
 /// </summary>
 /// <param name="sectionName">The name of the section to watch for.</param>
 /// <param name="handler">The handler.</param>
 public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     implementationByConnectionString[data.ConnectionString].RemoveSectionChangeHandler(sectionName, handler);
 }
コード例 #36
0
 public void AddSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     this.notificationCoordinator.AddSectionChangeHandler(sectionName, handler);
 }
 /// <summary>
 /// Adds a change handler for a section.
 /// </summary>
 /// <param name="sectionName">
 /// The section to add the handler.
 /// </param>
 /// <param name="handler">
 /// The handler to add.
 /// </param>
 public void AddSectionChangeHandler(string sectionName,
                                     ConfigurationChangedEventHandler handler)
 {
     notificationCoordinator.AddSectionChangeHandler(sectionName, handler);
 }
コード例 #38
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="changed"></param>
 private void SetUpWatcher(ConfigurationChangedEventHandler changed)
 {
     this.configWatcher = new ConfigurationChangeSqlWatcher(connectString, getStoredProc, this.ConfigSource);
     this.configWatcher.ConfigurationChanged += changed;
 }
コード例 #39
0
 public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
         
 }
コード例 #40
0
 /// <summary>
 /// Removes a handler to be called when changes to section <paramref name="sectionName"/> are detected.
 /// </summary>
 /// <param name="sectionName">The name of the watched section.</param>
 /// <param name="handler">The handler for the change event to remove.</param>
 public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     implementation.RemoveSectionChangeHandler(sectionName, handler);
 }
コード例 #41
0
 /// <summary>
 /// Removes a handler to be called when changes to section are detected.
 /// </summary>
 /// <param name="sectionName">The name of the watched section.</param>
 /// <param name="handler">The handler for the change event to remove.</param>
 public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     throw new NotSupportedException();
 }
コード例 #42
0
        /// <summary>
        /// <para>
        /// Reads configuration settings for a user-defined configuration section.
        /// </para>
        /// </summary>
        /// <param name="sectionName">
        /// <para>The configuration section to read.</para>
        /// </param>
        /// <returns>
        /// <para>The configuration settings for <paramref name="sectionName"/>.</para>
        /// </returns>
        /// <exception cref="ArgumentException">
        /// <para><paramref name="sectionName"/>can not be <see langword="null"/> (Nothing in Visual Basic).</para>
        /// </exception>
        /// <exception cref="ConfigurationException">
        /// <para><paramref name="sectionName"/> is not valid for this configuration.</para>
        /// </exception>
        public object ReadConfiguration(string sectionName)
        {
            ValidateSection(sectionName);

            object configurationSection = sections.GetSection(sectionName);
            if (IsConfigurationSectionCached(configurationSection))
            {
                return configurationSection;
            }

            IStorageProviderReader storageProviderReader = CreateStorageProvider(sectionName);

            object configurationSettings = storageProviderReader.Read();
            if (configurationSettings == null)
            {
                return null;
            }

            ITransformer transformer = CreateTransformer(sectionName);
            if (transformer != null)
            {
                configurationSection = transformer.Deserialize(configurationSettings);
            }
            else
            {
                configurationSection = configurationSettings;
            }

            ConfigurationChangedEventHandler changed = new ConfigurationChangedEventHandler(OnExternalConfigurationChanged);
            sections.AddSection(sectionName, configurationSection, changed, storageProviderReader);

            return configurationSection;
        }
コード例 #43
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="changed"></param>
		private void SetUpWatcher(ConfigurationChangedEventHandler changed)
		{
            this.configWatcher = new ConfigurationChangeSqlWatcher(connectString, getStoredProc, this.ConfigSource);
			this.configWatcher.ConfigurationChanged += changed;
		}
コード例 #44
0
#pragma warning restore 67

        /// <summary>
        /// Adds a handler to be called when changes to section <code>sectionName</code> are detected.
        /// This call should always be followed by a <see cref="RemoveSectionChangeHandler"/>. Failure to remove change
        /// handlers will result in .NET resource leaks.
        /// </summary>
        /// <param name="sectionName">The name of the section to watch for.</param>
        /// <param name="handler">The handler.</param>
        public void AddSectionChangeHandler(string sectionName,
                                            ConfigurationChangedEventHandler handler)
        {
            CheckSectionName(sectionName);
            CheckHandler(handler);

            implementation.AddSectionChangeHandler(sectionName, handler);
        }
コード例 #45
0
        /// <summary>
        ///
        /// </summary>
        public ConfigurationSqlSourceWatcher(string connectString, string getStoredProc, string configSource, bool refresh, ConfigurationChangedEventHandler changed)
            : base(configSource, refresh, changed)
        {
            this.connectString = connectString;
            this.getStoredProc = getStoredProc;

            if (refresh)
            {
                SetUpWatcher(changed);
            }
        }
コード例 #46
0
		/// <summary>
		/// Remove a handler to be called when changes to section <code>sectionName</code> are detected.
		/// This class should always follow a call to <see cref="AddSectionChangeHandler"/>. Failure
		/// to call these methods in pairs will result in .Net resource leaks.
		/// </summary>
		/// <param name="sectionName">The name of the section to watch for.</param>
		/// <param name="handler">The handler.</param>
		public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
		{
			implementationByFilepath[configurationFilepath].RemoveSectionChangeHandler(sectionName, handler);
		}
コード例 #47
0
 /// <summary>
 /// Initializes a new instance of <see cref="ConfigurationChangedProxy"/> for specified <see cref="ConfigurationChangedEventHandler"/>.
 /// </summary>
 /// <param name="action">Event action</param>
 public ConfigurationChangedProxy(ConfigurationChangedEventHandler action)
 {
     EventHandler += action;
 }
コード例 #48
0
 private void SetUpWatcher(ConfigurationChangedEventHandler changed)
 {
     this.configWatcher = new ConfigurationChangeFileWatcher(GetFullFileName(this.configurationFilepath, this.ConfigSource), this.ConfigSource);
     this.configWatcher.ConfigurationChanged += changed;
 }
コード例 #49
0
 public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     throw new NotImplementedException();
 }
コード例 #50
0
 /// <summary>
 /// Adds a handler to be called when changes to section <code>sectionName</code> are detected.
 /// </summary>
 /// <param name="sectionName">The name of the section to watch for.</param>
 /// <param name="handler">The handler.</param>
 public void AddSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     eventHandlers.AddHandler(sectionName, handler);
 }
コード例 #51
0
 public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
 {
     this.eventHandlers.RemoveHandler(sectionName, handler);
 }