本文整理汇总了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());
}
}
示例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));
}
}
示例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);
}
示例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());
}