コード例 #1
0
        public void StorageFiresEventTest()
        {
            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
            {
                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));

                using (IConfigurationChangeWatcher watcher = storage.CreateConfigurationChangeWatcher())
                {
                    watcher.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged);

                    watcher.StartWatching();
                    Thread.Sleep(100);
                    ((IStorageProviderWriter)storage).Write(GetData());

                    for (int wait = 0; wait < 10 && eventFiredCount < 2; ++wait)
                    {
                        Thread.Sleep(500);
                    }

                    watcher.Dispose();
                }

                Assert.AreEqual(1, eventFiredCount);
            }
        }
コード例 #2
0
 public ConfigurationChangeWatcherPauser(IConfigurationChangeWatcher watcher)
 {
     this.watcher = watcher;
     if (watcher != null)
     {
         watcher.StopWatching();
     }
 }
コード例 #3
0
 public ConfigurationChangeWatcherPauser(IConfigurationChangeWatcher watcher)
 {
     this.watcher = watcher;
     if (watcher != null)
     {
         watcher.StopWatching();
     }
 }
コード例 #4
0
        private void ExecuteWhilePaused(string sectionName, ActionTakenWhilePaused action)
        {
            IConfigurationChangeWatcher sectionWatcher = (IConfigurationChangeWatcher)configurationWatcherCache[sectionName];

            using (new ConfigurationChangeWatcherPauser(sectionWatcher))
            {
                action();
            }
        }
コード例 #5
0
 private void CreateMetaConfigChangeWatcher()
 {
     if (metaConfigChangeWatcher != null)
     {
         metaConfigChangeWatcher.Dispose();
     }
     metaConfigChangeWatcher = configFile.CreateFileWatcher();
     metaConfigChangeWatcher.ConfigurationChanged += new ConfigurationChangedEventHandler(OnMetaConfigurationChanged);
     metaConfigChangeWatcher.StartWatching();
 }
コード例 #6
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);
            }
        }
コード例 #7
0
        public void Remove(string sectionName)
        {
            if (null == sectionName)
            {
                return;
            }

            lock (lockMe)
            {
                Cache.Remove(sectionName);
                IConfigurationChangeWatcher watcher = (IConfigurationChangeWatcher)ConfigurationWatcherCache[sectionName];
                if (watcher != null)
                {
                    ConfigurationWatcherCache.Remove(sectionName);
                    watcher.Dispose();
                }
            }
        }
コード例 #8
0
 /// <summary>
 /// <para>Releases the unmanaged resources used by the <see cref="ConfigurationBuilder"/> and optionally releases the managed resources.</para>
 /// </summary>
 /// <param name="disposing">
 /// <para><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</para>
 /// </param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (null != configFile)
         {
             configFile.Dispose();
         }
         if (null != metaConfigChangeWatcher)
         {
             metaConfigChangeWatcher.Dispose();
             metaConfigChangeWatcher = null;
         }
         if (null != sections)
         {
             sections.Dispose();
         }
     }
 }
コード例 #9
0
        public void StorageFiresEventTest()
        {
            string filename = Path.GetFullPath(myConfigTestFile);
            bool fileExists = File.Exists(filename);
            Assert.IsTrue(fileExists);
            bool loaded = configFile.Load(filename);
            Assert.IsTrue(loaded);

            using (IConfigurationChangeWatcher watcher = configFile.CreateFileWatcher())
            {
                ((ConfigurationChangeFileWatcher)watcher).SetPollDelayInMilliseconds(100);
                watcher.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged);
                watcher.StartWatching();
                Thread.Sleep(150);

                FileUtility.OpenAndChangeFile(myConfigTestFile);
                for (int wait = 0; wait < 10 && eventFiredCount == 0; ++wait)
                {
                    Thread.Sleep(500);
                }
            }

            Assert.AreEqual(1, eventFiredCount);
        }
コード例 #10
0
 private void CreateMetaConfigChangeWatcher()
 {
     if (metaConfigChangeWatcher != null)
     {
         metaConfigChangeWatcher.Dispose();
     }
     metaConfigChangeWatcher = configFile.CreateFileWatcher();
     metaConfigChangeWatcher.ConfigurationChanged += new ConfigurationChangedEventHandler(OnMetaConfigurationChanged);
     metaConfigChangeWatcher.StartWatching();
 }
コード例 #11
0
 /// <summary>
 /// <para>Releases the unmanaged resources used by the <see cref="ConfigurationBuilder"/> and optionally releases the managed resources.</para>
 /// </summary>
 /// <param name="disposing">
 /// <para><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</para>
 /// </param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (null != configFile)
         {
             configFile.Dispose();
         }
         if (null != metaConfigChangeWatcher)
         {
             metaConfigChangeWatcher.Dispose();
             metaConfigChangeWatcher = null;
         }
         if (null != sections)
         {
             sections.Dispose();
         }
     }
 }
コード例 #12
0
 private void AddConfigurationWatcherForSection(ConfigurationChangedEventHandler changed, IConfigurationChangeWatcher watcher)
 {
     watcher.ConfigurationChanged += changed;
     watcher.StartWatching();
     ConfigurationWatcherCache.Add(watcher.SectionName, watcher);
 }
コード例 #13
0
 private void AddConfigurationWatcherForSection(ConfigurationChangedEventHandler changed, IConfigurationChangeWatcher watcher)
 {
     watcher.ConfigurationChanged += changed;
     watcher.StartWatching();
     ConfigurationWatcherCache.Add(watcher.SectionName, watcher);
 }