本文整理汇总了C#中Nini.Config.XmlConfigSource.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# XmlConfigSource.Merge方法的具体用法?C# XmlConfigSource.Merge怎么用?C# XmlConfigSource.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nini.Config.XmlConfigSource
的用法示例。
在下文中一共展示了XmlConfigSource.Merge方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Merge
public void Merge ()
{
StringWriter textWriter = new StringWriter ();
XmlTextWriter xmlWriter = NiniWriter (textWriter);
WriteSection (xmlWriter, "Pets");
WriteKey (xmlWriter, "cat", "muffy");
WriteKey (xmlWriter, "dog", "rover");
WriteKey (xmlWriter, "bird", "tweety");
xmlWriter.WriteEndDocument ();
StringReader reader = new StringReader (textWriter.ToString ());
XmlTextReader xmlReader = new XmlTextReader (reader);
XmlConfigSource xmlSource = new XmlConfigSource (xmlReader);
StringWriter writer = new StringWriter ();
writer.WriteLine ("[People]");
writer.WriteLine (" woman = Jane");
writer.WriteLine (" man = John");
IniConfigSource iniSource =
new IniConfigSource (new StringReader (writer.ToString ()));
xmlSource.Merge (iniSource);
IConfig config = xmlSource.Configs["Pets"];
Assert.AreEqual (3, config.GetKeys ().Length);
Assert.AreEqual ("muffy", config.Get ("cat"));
Assert.AreEqual ("rover", config.Get ("dog"));
config = xmlSource.Configs["People"];
Assert.AreEqual (2, config.GetKeys ().Length);
Assert.AreEqual ("Jane", config.Get ("woman"));
Assert.AreEqual ("John", config.Get ("man"));
}
示例2: SaveTo
/// <summary>
/// Saves the peer configuration.
/// </summary>
/// <param name="fileName">The name of the file where to save it.</param>
private void SaveTo(String fileName)
{
// Save the configuration as input for future reconfiguration
try
{
using (FileStream oStream = new FileStream(fileName, FileMode.Create))
{
XmlConfigSource source2 = new XmlConfigSource();
source2.Merge(source);
source2.Save(oStream);
}
}
catch (Exception e)
{
if (log.IsWarnEnabled)
{
log.Warn(e);
log.Warn("Could not save to " + fileName);
}
}
}
示例3: MergeAndSave
public void MergeAndSave()
{
string xmlFileName = "NiniConfig.xml";
StreamWriter textWriter = new StreamWriter (xmlFileName);
XmlTextWriter xmlWriter = NiniWriter (textWriter);
WriteSection (xmlWriter, "Pets");
WriteKey (xmlWriter, "cat", "Muffy");
WriteKey (xmlWriter, "dog", "Rover");
WriteKey (xmlWriter, "bird", "Tweety");
xmlWriter.WriteEndDocument ();
xmlWriter.Close ();
StringWriter writer = new StringWriter ();
writer.WriteLine ("[Pets]");
writer.WriteLine ("cat = Becky"); // overwrite
writer.WriteLine ("lizard = Saurus"); // new
writer.WriteLine ("[People]");
writer.WriteLine (" woman = Jane");
writer.WriteLine (" man = John");
IniConfigSource iniSource = new IniConfigSource
(new StringReader (writer.ToString ()));
XmlConfigSource xmlSource = new XmlConfigSource (xmlFileName);
xmlSource.Merge (iniSource);
IConfig config = xmlSource.Configs["Pets"];
Assert.AreEqual (4, config.GetKeys ().Length);
Assert.AreEqual ("Becky", config.Get ("cat"));
Assert.AreEqual ("Rover", config.Get ("dog"));
Assert.AreEqual ("Saurus", config.Get ("lizard"));
config = xmlSource.Configs["People"];
Assert.AreEqual (2, config.GetKeys ().Length);
Assert.AreEqual ("Jane", config.Get ("woman"));
Assert.AreEqual ("John", config.Get ("man"));
config.Set ("woman", "Tara");
config.Set ("man", "Quentin");
xmlSource.Save ();
xmlSource = new XmlConfigSource (xmlFileName);
config = xmlSource.Configs["Pets"];
Assert.AreEqual (4, config.GetKeys ().Length);
Assert.AreEqual ("Becky", config.Get ("cat"));
Assert.AreEqual ("Rover", config.Get ("dog"));
Assert.AreEqual ("Saurus", config.Get ("lizard"));
config = xmlSource.Configs["People"];
Assert.AreEqual (2, config.GetKeys ().Length);
Assert.AreEqual ("Tara", config.Get ("woman"));
Assert.AreEqual ("Quentin", config.Get ("man"));
File.Delete (xmlFileName);
}
示例4: MergeExisting
public void MergeExisting()
{
StringWriter textWriter = new StringWriter ();
XmlTextWriter xmlWriter = NiniWriter (textWriter);
WriteSection (xmlWriter, "Pets");
WriteKey (xmlWriter, "cat", "muffy");
xmlWriter.WriteEndDocument ();
StringReader reader = new StringReader (xmlWriter.ToString ());
XmlTextReader xmlReader = new XmlTextReader (reader);
XmlConfigSource xmlSource = new XmlConfigSource (xmlReader);
StringWriter writer = new StringWriter ();
writer.WriteLine ("[People]");
writer.WriteLine (" woman = Jane");
IniConfigSource iniSource =
new IniConfigSource (new StringReader (writer.ToString ()));
xmlSource.Merge (iniSource);
xmlSource.Merge (iniSource); // exception
}
示例5: RecordConfiguration
protected void RecordConfiguration(IConfigSource originalConfig)
{
m_xtw.WriteStartElement(ConfigElement);
// Write out game configuration
// We have to transfer this to an xml document to get xml
XmlConfigSource intermediateConfig = new XmlConfigSource();
intermediateConfig.Merge(originalConfig);
// This is a roundabout way to get rid of the top xml processing directive that config.ToString() gives
// us
XmlDocument outputDoc = new XmlDocument();
outputDoc.LoadXml(intermediateConfig.ToString());
// Remove the other document's processing instruction
outputDoc.RemoveChild(outputDoc.FirstChild);
outputDoc.WriteTo(m_xtw);
m_xtw.WriteStartElement(RegionsElement);
// Write region names, positions and IDs
foreach (Scene scene in m_controller.Scenes)
{
m_xtw.WriteStartElement(RegionElement);
m_xtw.WriteAttributeString("Name", scene.RegionInfo.RegionName);
m_xtw.WriteAttributeString("X", scene.RegionInfo.RegionLocX.ToString());
m_xtw.WriteAttributeString("Y", scene.RegionInfo.RegionLocY.ToString());
m_xtw.WriteEndElement();
}
m_xtw.WriteEndElement();
m_xtw.WriteEndElement();
}