当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationBuilder.ClearSectionCache方法代码示例

本文整理汇总了C#中ConfigurationBuilder.ClearSectionCache方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.ClearSectionCache方法的具体用法?C# ConfigurationBuilder.ClearSectionCache怎么用?C# ConfigurationBuilder.ClearSectionCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigurationBuilder的用法示例。


在下文中一共展示了ConfigurationBuilder.ClearSectionCache方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadAndWriteToEncryptedConfiguration

        public void ReadAndWriteToEncryptedConfiguration()
        {
            const string sectionName = "MyEncryptedConfig";

            KeyAlgorithmPair keyAlgorithmPair = new KeyAlgorithmPair();
            keyAlgorithmPair.Key = new SymmetricAlgorithmKeyCreator(typeof(RijndaelManaged).AssemblyQualifiedName).GenerateKey();
            keyAlgorithmPair.AlgorithmTypeName = typeof(RijndaelManaged).AssemblyQualifiedName;

            FileKeyAlgorithmPairStorageProvider provider = new FileKeyAlgorithmPairStorageProvider();
            provider.ConfigurationName = "FileKeyAlgorithmPairStorageProviderData";

            using (ConfigurationBuilder builder = new ConfigurationBuilder())
            {
                // change wher the file is
                RuntimeConfigurationView view = new RuntimeConfigurationView(new ConfigurationContext(new NonDisposingWrapper(builder)));

                FileKeyAlgorithmPairStorageProviderData fileData = (FileKeyAlgorithmPairStorageProviderData)view.GetKeyAlgorithmPairStorageProviderData();
                fileData.Path = Path.GetTempFileName();
                provider.Initialize(view);
                provider.Save(keyAlgorithmPair);
                builder.WriteConfiguration(sectionName, data);
                MockConfigurationData myData = (MockConfigurationData)builder.ReadConfiguration(sectionName);
                Assert.AreEqual(myData.ToString(), data.ToString());
                builder.ClearSectionCache();
                myData = (MockConfigurationData)builder.ReadConfiguration(sectionName);
                Assert.AreEqual(myData.ToString(), data.ToString());
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:28,代码来源:ConfigurationBuilderFixture.cs

示例2: ClearCacheTest

 public void ClearCacheTest()
 {
     using (ConfigurationBuilder builder = new ConfigurationBuilder(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
     {
         builder.WriteConfiguration(mockConfigSection, data);
         MockConfigurationData readData = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;
         MockConfigurationData readData2 = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;
         Assert.AreSame(readData, readData2);
         builder.ClearSectionCache();
         readData2 = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;
         Assert.IsFalse(Object.Equals(readData, readData2));
     }
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:13,代码来源:ConfigurationBuilderFixture.cs

示例3: ClearingSectionFromCacheShouldPreventAnyChangeEventsForThatSection

        public void ClearingSectionFromCacheShouldPreventAnyChangeEventsForThatSection()
        {
            using (ConfigurationBuilder builder = new ConfigurationBuilder(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
            {
                builder.WriteConfiguration(mockConfigSection, data);
                builder.ConfigurationChanged += new ConfigurationChangedEventHandler(OnMockConfigConfigurationChanged);

                builder.ClearSectionCache(mockConfigSection);
            }

            FileUtility.OpenAndChangeFile(Path.GetFullPath(myConfigFile));

            Thread.Sleep(500);
            Assert.IsFalse(eventFired);
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:15,代码来源:ConfigurationBuilderFixture.cs

示例4: ChangingMetaConfigAfterClearSectionCacheStillCausesEvent

        public void ChangingMetaConfigAfterClearSectionCacheStillCausesEvent()
        {
            //myconfig.xml
            builder.WriteConfiguration(mockConfigSection, data);
            using (ConfigurationBuilder newBuilder = new ConfigurationBuilder(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
            {
                newBuilder.ConfigurationChanged += new ConfigurationChangedEventHandler(OnMetaDataConfigurationChanged);
                Thread.Sleep(150);
                newBuilder.ClearSectionCache();
                Thread.Sleep(150);

                FileUtility.OpenAndChangeFile(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                for (int wait = 0; (!eventFired) && (wait < 10); ++wait)
                {
                    Thread.Sleep(500);
                }
                newBuilder.ConfigurationChanged -= new ConfigurationChangedEventHandler(OnMetaDataConfigurationChanged);
            }
            Assert.IsTrue(eventFired);
            Assert.AreEqual(ConfigurationSettings.SectionName, changedSectionName);
            Assert.AreEqual(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile.ToLower(), changedConfigurationFile.ToLower());
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:22,代码来源:ConfigurationBuilderFixture.cs


注:本文中的ConfigurationBuilder.ClearSectionCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。