本文整理汇总了C#中ConfigurationBuilder.WriteConfiguration方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.WriteConfiguration方法的具体用法?C# ConfigurationBuilder.WriteConfiguration怎么用?C# ConfigurationBuilder.WriteConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigurationBuilder
的用法示例。
在下文中一共展示了ConfigurationBuilder.WriteConfiguration方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StaticClearCacheTest
public void StaticClearCacheTest()
{
using (ConfigurationBuilder builder = new ConfigurationBuilder(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
{
builder.WriteConfiguration(mockConfigSection, data);
MockConfigurationData readData = ConfigurationManager.GetConfiguration(mockConfigSection) as MockConfigurationData;
MockConfigurationData readData2 = ConfigurationManager.GetConfiguration(mockConfigSection) as MockConfigurationData;
Assert.AreSame(readData, readData2);
ConfigurationManager.ClearSingletonSectionCache();
readData2 = ConfigurationManager.GetConfiguration(mockConfigSection) as MockConfigurationData;
Assert.IsFalse(Object.Equals(readData, readData2));
}
}
示例2: WritingToEmptyConfigFileWithEncryptionOn
public void WritingToEmptyConfigFileWithEncryptionOn()
{
using (ConfigurationBuilder builder = new ConfigurationBuilder(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
{
builder.WriteConfiguration("EncryptedProblem", data);
}
}
示例3: ReadWriteNoTransformerTest
public void ReadWriteNoTransformerTest()
{
string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
using (ConfigurationBuilder builder = new ConfigurationBuilder(configFile))
{
XmlNode writeData = SerializeData(data);
builder.WriteConfiguration(noTransformerSection, writeData);
XmlNode readData = builder.ReadConfiguration(noTransformerSection) as XmlNode;
Assert.IsNotNull(readData);
Assert.AreEqual(writeData.OuterXml, readData.OuterXml);
}
}
示例4: ReadWriteWebConfigTest
public void ReadWriteWebConfigTest()
{
string configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, webConfigFile);
using (ConfigurationBuilder builder = new ConfigurationBuilder(configFile))
{
ConfigurationSettings configData = new ConfigurationSettings(mockConfigSection);
configData.ConfigurationSections.Add(GetConfigurationSection());
builder.WriteMetaConfiguration(configData);
builder.WriteConfiguration(mockConfigSection, data);
MockConfigurationData readData = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;
Assert.IsNotNull(readData);
Assert.AreEqual(data.ToString(), readData.ToString());
}
}
示例5: MakeSureTheChangingEventFires
public void MakeSureTheChangingEventFires()
{
builder.WriteConfiguration(mockConfigSection, data);
using (ConfigurationBuilder newBuilder = new ConfigurationBuilder(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
{
newBuilder.ConfigurationChanging += new ConfigurationChangingEventHandler(OnConfigurationChanging);
newBuilder.WriteConfiguration(mockConfigSection, data);
for (int wait = 0; !eventFired && (wait < 10); ++wait)
{
Thread.Sleep(500);
}
newBuilder.ConfigurationChanging -= new ConfigurationChangingEventHandler(OnConfigurationChanging);
}
Assert.AreEqual(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, changedConfigurationFile);
Assert.AreEqual(mockConfigSection, changedSectionName);
Assert.IsNotNull(changedOldValue);
Assert.IsNotNull(changedNewValue);
Assert.IsTrue(eventFired);
}
示例6: 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());
}
}
示例7: MakeSureTheChangedEventFiresWhenTheDataFileChangesExternally
public void MakeSureTheChangedEventFiresWhenTheDataFileChangesExternally()
{
using (ConfigurationBuilder newBuilder = new ConfigurationBuilder(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
{
newBuilder.WriteConfiguration(mockConfigSection, data);
newBuilder.ConfigurationChanged += new ConfigurationChangedEventHandler(OnDataConfigurationChanged);
Thread.Sleep(100);
FileUtility.OpenAndChangeFile(Path.GetFullPath(myConfigFile));
for (int wait = 0; (!eventFired) && (wait < 10); ++wait)
{
Thread.Sleep(500);
}
newBuilder.ConfigurationChanged -= new ConfigurationChangedEventHandler(OnDataConfigurationChanged);
}
Assert.AreEqual(mockConfigSection, changedSectionName);
Assert.AreEqual(myConfigFile, changedConfigurationFile);
Assert.IsTrue(eventFired);
}
示例8: MakeSureTheChangedEventFires
public void MakeSureTheChangedEventFires()
{
builder.WriteConfiguration(mockConfigSection, data);
using (ConfigurationBuilder newBuilder = new ConfigurationBuilder(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
{
newBuilder.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged);
newBuilder.WriteConfiguration(mockConfigSection, data);
}
for (int wait = 0; (wait < 10); ++wait)
{
Thread.Sleep(500);
}
Assert.AreEqual(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, changedConfigurationFile);
Assert.AreEqual(mockConfigSection, changedSectionName);
Assert.IsTrue(eventFired);
Assert.AreEqual(1, eventCount);
}
示例9: 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);
}
示例10: ClearCacheByNameTest
public void ClearCacheByNameTest()
{
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(mockConfigSection);
readData2 = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;
Assert.IsFalse(Object.Equals(readData, readData2));
}
}
示例11: ChangingConfigurationSectionAfterDisposeDoesNotCauseEvent
public void ChangingConfigurationSectionAfterDisposeDoesNotCauseEvent()
{
builder.WriteConfiguration(mockConfigSection, data);
using (ConfigurationBuilder newBuilder = new ConfigurationBuilder(configFile))
{
newBuilder.WriteConfiguration(mockConfigSection, data);
Thread.Sleep(300);
newBuilder.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged);
}
builder.WriteConfiguration(mockConfigSection, data);
Thread.Sleep(300);
Assert.IsFalse(eventFired);
}