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(); }
public void SaveToNewPath() { string filePath = "Test.xml"; string newPath = "TestNew.xml"; StreamWriter textWriter = new StreamWriter(filePath); XmlTextWriter xmlWriter = NiniWriter(textWriter); WriteSection(xmlWriter, "Pets"); WriteKey(xmlWriter, "cat", "Muffy"); WriteKey(xmlWriter, "dog", "Rover"); xmlWriter.WriteEndDocument(); xmlWriter.Close(); XmlConfigSource source = new XmlConfigSource(filePath); IConfig config = source.Configs["Pets"]; Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Muffy", config.Get("cat")); source.Save(newPath); source = new XmlConfigSource(newPath); config = source.Configs["Pets"]; Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Muffy", config.Get("cat")); File.Delete(filePath); File.Delete(newPath); }
public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName) { // m_configSource = configSource; if (filename.ToLower().EndsWith(".ini")) { if (!File.Exists(filename)) // New region config request { IniConfigSource newFile = new IniConfigSource(); ReadNiniConfig(newFile, String.Empty); newFile.Save(filename); RegionFile = filename; return; } IniConfigSource source = new IniConfigSource(filename); bool saveFile = false; if (source.Configs[configName] == null) { saveFile = true; } ReadNiniConfig(source, configName); if (configName != String.Empty && saveFile) { source.Save(filename); } RegionFile = filename; return; } try { // This will throw if it's not legal Nini XML format // and thereby toss it to the legacy loader // IConfigSource xmlsource = new XmlConfigSource(filename); ReadNiniConfig(xmlsource, configName); RegionFile = filename; return; } catch (Exception) { } configMember = new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig); configMember.performConfigurationRetrieve(); RegionFile = filename; }
public void EmptyConstructor() { string filePath = "EmptyConstructor.xml"; XmlConfigSource source = new XmlConfigSource(); IConfig config = source.AddConfig("Pets"); config.Set("cat", "Muffy"); config.Set("dog", "Rover"); config.Set("bird", "Tweety"); source.Save(filePath); Assert.AreEqual(3, config.GetKeys().Length); Assert.AreEqual("Muffy", config.Get("cat")); Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Tweety", config.Get("bird")); source = new XmlConfigSource(filePath); config = source.Configs["Pets"]; Assert.AreEqual(3, config.GetKeys().Length); Assert.AreEqual("Muffy", config.Get("cat")); Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Tweety", config.Get("bird")); File.Delete(filePath); }
public void LoadReader() { StringWriter textWriter = new StringWriter(); XmlTextWriter writer = NiniWriter(textWriter); WriteSection(writer, "Pets"); WriteKey(writer, "cat", "muffy"); WriteKey(writer, "dog", "rover"); WriteKey(writer, "bird", "tweety"); writer.WriteEndDocument(); StringReader reader = new StringReader(textWriter.ToString()); XmlTextReader xmlReader = new XmlTextReader(reader); XmlConfigSource source = new XmlConfigSource(xmlReader); IConfig config = source.Configs["Pets"]; Assert.AreEqual(3, config.GetKeys().Length); Assert.AreEqual("rover", config.Get("dog")); config.Set("dog", "new name"); config.Remove("bird"); reader = new StringReader(textWriter.ToString()); xmlReader = new XmlTextReader(reader); source.Load(xmlReader); config = source.Configs["Pets"]; Assert.AreEqual(3, config.GetKeys().Length); Assert.AreEqual("rover", config.Get("dog")); }
public void RemoveConfigAndKeyFromFile() { string filePath = "Test.xml"; StreamWriter xmlWriter = new StreamWriter(filePath); XmlTextWriter writer = NiniWriter(xmlWriter); WriteSection(writer, "test 1"); WriteKey(writer, "dog", "Rover"); writer.WriteEndElement(); WriteSection(writer, "test 2"); WriteKey(writer, "cat", "Muffy"); WriteKey(writer, "lizard", "Lizzy"); writer.WriteEndDocument(); xmlWriter.Close(); XmlConfigSource source = new XmlConfigSource(filePath); Assert.IsNotNull(source.Configs["test 1"]); Assert.IsNotNull(source.Configs["test 2"]); Assert.IsNotNull(source.Configs["test 2"].Get("cat")); source.Configs.Remove(source.Configs["test 1"]); source.Configs["test 2"].Remove("cat"); source.AddConfig("cause error"); source.Save(); source = new XmlConfigSource(filePath); Assert.IsNull(source.Configs["test 1"]); Assert.IsNotNull(source.Configs["test 2"]); Assert.IsNull(source.Configs["test 2"].Get("cat")); File.Delete(filePath); }
public static IConfigSource LoadInitialConfig(string url) { IConfigSource source = new XmlConfigSource(); m_log.InfoFormat("[SERVER UTILS]: {0} is a http:// URI, fetching ...", url); // The ini file path is a http URI // Try to read it try { IConfigSource cs; using (XmlReader r = XmlReader.Create(url)) { cs = new XmlConfigSource(r); source.Merge(cs); } } catch (Exception e) { m_log.FatalFormat("[SERVER UTILS]: Exception reading config from URI {0}\n" + e.ToString(), url); Environment.Exit(1); } return(source); }
public void GetInt() { StringWriter textWriter = new StringWriter(); XmlTextWriter writer = NiniWriter(textWriter); WriteSection(writer, "Pets"); WriteKey(writer, "value 1", "49588"); writer.WriteEndDocument(); StringReader reader = new StringReader(textWriter.ToString()); XmlTextReader xmlReader = new XmlTextReader(reader); XmlConfigSource source = new XmlConfigSource(xmlReader); IConfig config = source.Configs["Pets"]; Assert.AreEqual(49588, config.GetInt("value 1")); Assert.AreEqual(12345, config.GetInt("Not Here", 12345)); try { config.GetInt("Not Here Also"); Assert.Fail(); } catch { } }
public void Initialize() { ConfigSource = new XmlConfigSource("Config.xml") { AutoSave = true }; }
/// <summary> /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http /// </summary> /// <param name="iniPath">Full path to the ini</param> /// <returns></returns> private bool ReadConfig(string iniPath) { bool success = false; if (!IsUri(iniPath)) { m_log.InfoFormat("[CONFIG]: Reading configuration file {0}", Path.GetFullPath(iniPath)); m_config.Source.Merge(new IniConfigSource(iniPath)); success = true; } else { m_log.InfoFormat("[CONFIG]: {0} is a http:// URI, fetching ...", iniPath); // The ini file path is a http URI // Try to read it try { XmlReader r = XmlReader.Create(iniPath); XmlConfigSource cs = new XmlConfigSource(r); m_config.Source.Merge(cs); success = true; } catch (Exception e) { m_log.FatalFormat("[CONFIG]: Exception reading config from URI {0}\n" + e.ToString(), iniPath); Environment.Exit(1); } } return(success); }
/// <summary> /// 지정된 Resouce 파일에 대한 NIni 용 <see cref="IConfigSource"/> 인스턴스를 생성, 반환한다. /// 속도를 위해 한번 생성된 인스턴스는 캐시된다. /// </summary> /// <param name="path"></param> /// <returns></returns> private static IConfigSource GetConfigSource(string path) { IConfigSource configSource; lock (_configSourceMap) { if (_configSourceMap.TryGetValue(path, out configSource) == false) { if (Path.GetExtension(path).ToLower().Contains("xml")) { configSource = new XmlConfigSource(path); } else { configSource = new IniConfigSource(path); } configSource.ExpandKeyValues(); _configSourceMap.Add(path, configSource); if (IsDebugEnabled) { log.Debug("Nini.IConfigSource 인스턴스를 생성하여 캐시에 저장했습니다. path=[{0}]", path); } } } return(configSource); }
IConfigSource ReadConfigSource(string iniFile) { // Find out of the file name is a URI and remote load it if possible. // Load it as a local file otherwise. Uri configUri; IConfigSource s = null; try { if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp) { XmlReader r = XmlReader.Create(iniFile); s = new XmlConfigSource(r); } else { s = new IniConfigSource(iniFile); } } catch (Exception e) { System.Console.WriteLine("Error reading from config source. {0}", e.Message); Environment.Exit(1); } return(s); }
private DbConfig() { SetupPaths(); Source = new XmlConfigSource(FullConfigFilename); Source.AutoSave = true; CreateSectionsIfNeeded(); }
public void ToStringTest() { StringWriter writer = new StringWriter(); XmlTextWriter xmlWriter = NiniWriter(writer); WriteSection(xmlWriter, "Pets"); WriteKey(xmlWriter, "cat", "Muffy"); WriteKey(xmlWriter, "dog", "Rover"); xmlWriter.WriteEndDocument(); xmlWriter.Close(); StringReader reader = new StringReader(writer.ToString()); XmlTextReader xmlReader = new XmlTextReader(reader); XmlConfigSource source = new XmlConfigSource(xmlReader); string eol = Environment.NewLine; string compare = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" + eol + "<Nini>" + eol + " <Section Name=\"Pets\">" + eol + " <Key Name=\"cat\" Value=\"Muffy\" />" + eol + " <Key Name=\"dog\" Value=\"Rover\" />" + eol + " </Section>" + eol + "</Nini>"; Assert.AreEqual(compare, source.ToString()); }
public void SaveToStream() { string filePath = "SaveToStream.ini"; FileStream stream = new FileStream(filePath, FileMode.Create); // Create a new document and save to stream XmlConfigSource source = new XmlConfigSource(); IConfig config = source.AddConfig("Pets"); config.Set("dog", "rover"); config.Set("cat", "muffy"); source.Save(stream); stream.Close(); XmlConfigSource newSource = new XmlConfigSource(filePath); config = newSource.Configs["Pets"]; Assert.IsNotNull(config); Assert.AreEqual(2, config.GetKeys().Length); Assert.AreEqual("rover", config.GetString("dog")); Assert.AreEqual("muffy", config.GetString("cat")); stream.Close(); File.Delete(filePath); }
public void SaveNewSection() { string filePath = "Test.xml"; StringWriter textWriter = new StringWriter(); XmlTextWriter writer = NiniWriter(textWriter); WriteSection(writer, "new section"); WriteKey(writer, "dog", "Rover"); WriteKey(writer, "cat", "Muffy"); writer.WriteEndDocument(); XmlDocument doc = new XmlDocument(); doc.LoadXml(textWriter.ToString()); doc.Save(filePath); XmlConfigSource source = new XmlConfigSource(filePath); IConfig config = source.AddConfig("test"); Assert.IsNotNull(source.Configs["test"]); source.Save(); source = new XmlConfigSource(filePath); config = source.Configs["new section"]; Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Muffy", config.Get("cat")); Assert.IsNotNull(source.Configs["test"]); File.Delete(filePath); }
public string CheckForUpdates(string clientVersion) { var response = string.Empty; try { if (!Directory.Exists(_dir + @"\Ester")) { throw new Exception("Cannot find Ester folder on server"); } _clientConfigSource = new XmlConfigSource(Path.Combine(HttpRuntime.AppDomainAppPath, @"Resources\Ester\Config.xml")) { AutoSave = true }; int clientVersionNumber; if (int.TryParse(clientVersion, out clientVersionNumber)) { if (clientVersionNumber < GetLastVersionNumber()) { response = _configSource.Configs["Update"].Get("UpdateFileUrl"); } } } catch (Exception exception) { WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.InternalServerError; WebOperationContext.Current.OutgoingResponse.StatusDescription = exception.Message; } return(response); }
public void ReplaceText() { StringWriter textWriter = new StringWriter(); XmlTextWriter xmlWriter = NiniWriter(textWriter); WriteSection(xmlWriter, "Test"); WriteKey(xmlWriter, "author", "Brent"); WriteKey(xmlWriter, "domain", "${protocol}://nini.sf.net/"); WriteKey(xmlWriter, "apache", "Apache implements ${protocol}"); WriteKey(xmlWriter, "developer", "author of Nini: ${author} !"); WriteKey(xmlWriter, "love", "We love the ${protocol} protocol"); WriteKey(xmlWriter, "combination", "${author} likes ${protocol}"); WriteKey(xmlWriter, "fact", "fact: ${apache}"); WriteKey(xmlWriter, "protocol", "http"); xmlWriter.WriteEndDocument(); StringReader reader = new StringReader(textWriter.ToString()); XmlTextReader xmlReader = new XmlTextReader(reader); XmlConfigSource source = new XmlConfigSource(xmlReader); source.ReplaceKeyValues(); IConfig config = source.Configs["Test"]; Assert.AreEqual("http", config.Get("protocol")); Assert.AreEqual("fact: Apache implements http", config.Get("fact")); Assert.AreEqual("http://nini.sf.net/", config.Get("domain")); Assert.AreEqual("Apache implements http", config.Get("apache")); Assert.AreEqual("We love the http protocol", config.Get("love")); Assert.AreEqual("author of Nini: Brent !", config.Get("developer")); Assert.AreEqual("Brent likes http", config.Get("combination")); }
public void SaveToWriter() { string newPath = "TestNew.xml"; StringWriter writer = new StringWriter(); XmlTextWriter xmlWriter = NiniWriter(writer); WriteSection(xmlWriter, "Pets"); WriteKey(xmlWriter, "cat", "Muffy"); WriteKey(xmlWriter, "dog", "Rover"); xmlWriter.WriteEndDocument(); xmlWriter.Close(); StringReader reader = new StringReader(writer.ToString()); XmlTextReader xmlReader = new XmlTextReader(reader); XmlConfigSource source = new XmlConfigSource(xmlReader); IConfig config = source.Configs["Pets"]; Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Muffy", config.Get("cat")); StreamWriter textWriter = new StreamWriter(newPath); source.Save(textWriter); textWriter.Close(); // save to disk source = new XmlConfigSource(newPath); config = source.Configs["Pets"]; Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Muffy", config.Get("cat")); File.Delete(newPath); }
/// <summary> /// Creates a new config file. /// </summary> private void CreateNewFile() { string type = null;; if (IsArg("set-type")) { type = GetArg("set-type").ToLower(); } else { ThrowError("You must supply a type (--set-type)"); } switch (type) { case "ini": IniConfigSource iniSource = new IniConfigSource(); iniSource.Save(configPath); break; case "xml": XmlConfigSource xmlSource = new XmlConfigSource(); xmlSource.Save(configPath); break; case "config": DotNetConfigSource dotnetSource = new DotNetConfigSource(); dotnetSource.Save(configPath); break; default: ThrowError("Unknown type"); break; } }
public void ForEachDefaultXmlAsset(string assetSetFilename, Action <AssetBase> action) { List <AssetBase> assets = new List <AssetBase>(); if (File.Exists(assetSetFilename)) { string assetSetPath = "ERROR"; string assetRootPath = String.Empty; try { XmlConfigSource source = new XmlConfigSource(assetSetFilename); assetRootPath = Path.GetFullPath(source.SavePath); assetRootPath = Path.GetDirectoryName(assetRootPath); for (int i = 0; i < source.Configs.Count; i++) { assetSetPath = source.Configs[i].GetString("file", String.Empty); LoadXmlAssetSet(Path.Combine(assetRootPath, assetSetPath), assets); } } catch (XmlException e) { m_log.ErrorFormat("[ASSETS]: Error loading {0} : {1}", assetSetPath, e); } } else { m_log.ErrorFormat("[ASSETS]: Asset set control file {0} does not exist! No assets loaded.", assetSetFilename); } assets.ForEach(action); }
/// <summary> /// Use the asset set information at path to load assets /// </summary> /// <param name="assetSetPath"></param> /// <param name="assets"></param> protected static void LoadXmlAssetSet(string assetSetPath, List <AssetBase> assets) { //m_log.InfoFormat("[ASSETS]: Loading asset set {0}", assetSetPath); if (File.Exists(assetSetPath)) { try { XmlConfigSource source = new XmlConfigSource(assetSetPath); String dir = Path.GetDirectoryName(assetSetPath); for (int i = 0; i < source.Configs.Count; i++) { string assetIdStr = source.Configs[i].GetString("assetID", UUID.Random().ToString()); string name = source.Configs[i].GetString("name", String.Empty); sbyte type = (sbyte)source.Configs[i].GetInt("assetType", 0); string assetPath = Path.Combine(dir, source.Configs[i].GetString("fileName", String.Empty)); AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, false); newAsset.Type = type; assets.Add(newAsset); } } catch (XmlException e) { m_log.ErrorFormat("[ASSETS]: Error loading {0} : {1}", assetSetPath, e); } } else { m_log.ErrorFormat("[ASSETS]: Asset set file {0} does not exist!", assetSetPath); } }
// File based loading // public RegionInfo LoadRegionFromFile(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName) { // m_configSource = configSource; RegionInfo region = new RegionInfo(); if (filename.ToLower().EndsWith(".ini")) { if (!File.Exists(filename)) // New region config request { IniConfigSource newFile = new IniConfigSource(); region.RegionFile = filename; ReadNiniConfig(region, newFile, configName); newFile.Save(filename); return(region); } IniConfigSource m_source = new IniConfigSource(filename, Nini.Ini.IniFileType.AuroraStyle); bool saveFile = false; if (m_source.Configs[configName] == null) { saveFile = true; } region.RegionFile = filename; bool update = ReadNiniConfig(region, m_source, configName); if (configName != String.Empty && (saveFile || update)) { m_source.Save(filename); } return(region); } try { // This will throw if it's not legal Nini XML format // and thereby toss it to the legacy loader // IConfigSource xmlsource = new XmlConfigSource(filename); ReadNiniConfig(region, xmlsource, configName); region.RegionFile = filename; return(region); } catch (Exception) { } return(null); }
private void WriteDefaultConfig() { _configSource = new XmlConfigSource(); _configSource.AddConfig("Main"); try { _configSource.Save(Path.Combine(StartupPath, "Config.xml")); _configSource.AutoSave = true; } catch { } }
// The web loader uses this // public RegionInfo(string description, XmlNode xmlNode, bool skipConsoleConfig, IConfigSource configSource) { XmlElement elem = (XmlElement)xmlNode; string name = elem.GetAttribute("Name"); string xmlstr = "<Nini>" + xmlNode.OuterXml + "</Nini>"; XmlConfigSource source = new XmlConfigSource(XmlReader.Create(new StringReader(xmlstr))); ReadNiniConfig(source, name); m_serverURI = string.Empty; }
public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName) { // m_configSource = configSource; if (filename.ToLower().EndsWith(".ini")) { if (!File.Exists(filename)) // New region config request { IniConfigSource newFile = new IniConfigSource(); ReadNiniConfig(newFile, configName); newFile.Save(filename); RegionFile = filename; return; } IniConfigSource source = new IniConfigSource(filename); bool saveFile = false; if (source.Configs[configName] == null) { saveFile = true; } ReadNiniConfig(source, configName); if (configName != String.Empty && saveFile) { source.Save(filename); } RegionFile = filename; return; } try { // This will throw if it's not legal Nini XML format // IConfigSource xmlsource = new XmlConfigSource(filename); ReadNiniConfig(xmlsource, configName); RegionFile = filename; return; } catch (Exception) { } }
/// <summary> /// Initializes a new instance of the <see cref="PluginSettingsBase"/> class. /// </summary> /// <param name="pluginName">Name of the plugin.</param> public PluginSettingsBase(string pluginName) { var fileName = string.Format("{0}\\Probel\\nDoctor\\{1}.plugin.config" , Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) , pluginName); if (!File.Exists(fileName)) { this.BuildDefaultFileStream(fileName); } Source = new XmlConfigSource(fileName); }
public void Save(string path) { if (Source is IniConfigSource) { IniConfigSource iniCon = (IniConfigSource)Source; iniCon.Save(path); } else if (Source is XmlConfigSource) { XmlConfigSource xmlCon = (XmlConfigSource)Source; xmlCon.Save(path); } }
// Nini (config) related Methods public static IConfigSource ConvertDataRowToXMLConfig(DataRow row, string fileName) { if (!File.Exists(fileName)) { //create new file } XmlConfigSource config = new XmlConfigSource(fileName); AddDataRowToConfig(config, row); config.Save(); return(config); }
/// <summary> /// Initialize config file /// </summary> /// <param name="file"> /// A <see cref="System.String"/> /// </param> public static void setCfgFile(string file) { SBConfig.cfg_file = file; if (!File.Exists(file)) { FileStream stream = File.Create(file); byte[] text = System.Text.Encoding.ASCII.GetBytes("<Nini></Nini>"); stream.Write(text, 0, text.Length); stream.Close(); } SBConfig.cfg = new XmlConfigSource(SBConfig.cfg_file); cfg.AutoSave = true; }
public void BasicStreamTestBase(string xml, string xpath) { using (MemoryStream mem = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { IXPathConfigSource<BasicTypesSampleWithoutAttr, Stream> src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src.Load(new XPathParameter<Stream>(mem, xpath)).Get()); } }
public void BasicStringTestBase(string xml, string xpath) { IXPathConfigSource<BasicTypesSampleWithoutAttr, string> src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src.Load(new XPathParameter<string>(xml, xpath)).Get()); }
public void BasicXmlElementTestBase(string xml, string xpath) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); IXPathConfigSource<BasicTypesSampleWithoutAttr, XmlElement> src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src.Load(new XPathParameter<XmlElement>( doc.DocumentElement, xpath)).Get()); }
public void BasicXmlContentHolderTestBase(string xml, string xpath) { IXPathConfigSource<XmlContainerSample, string> src = new XmlConfigSource<XmlContainerSample>(); XmlContainerSample samp = src.Load(new XPathParameter<string>(xml, xpath)).Get(); IXPathConfigSource<BasicTypesSampleWithoutAttr, XmlElement> src2 = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src2.Load(samp.Element).Get()); }
public void BasicXmlReaderTestBase(string xml, string xpath) { StringReader reader = new StringReader(xml); XmlTextReader reader2 = new XmlTextReader(reader); IXPathConfigSource<BasicTypesSampleWithoutAttr, XmlReader> src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src.Load(new XPathParameter<XmlReader>(reader2, xpath)).Get()); }
public void MissingAStringTest() { string brokenXml = @"<BasicTypesSampleWithoutAttr> <AnIntegral>42</AnIntegral> <AFloat>42.42</AFloat> </BasicTypesSampleWithoutAttr>"; var src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); var cfg = src.Load(brokenXml).Get(); cfg.AString.Should().Be.Null(); }
public void MoreInformationThanCanHandle() { string mySample = @"<BasicTypesSampleWithoutAttr> <AString>whatever</AString> <NotKnown>asd</NotKnown> </BasicTypesSampleWithoutAttr>"; ; IXPathConfigSource<BasicTypesSampleWithoutAttr, string> src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); src.Load(mySample).Get().AString.Should().Be("whatever"); }
public void NotKnownTypesTest() { XmlDocument doc = new XmlDocument(); doc.LoadXml(SAMPLE_XML); string complexXml = @"<NotKnownTypeSample><Basic>%s</Basic><Basics>%s%s%s</Basics></NotKnownTypeSample>" .Replace("%s", doc.DocumentElement.OuterXml) .Replace("%z", doc.DocumentElement.InnerXml); var src = new XmlConfigSource<NotKnownTypeSample>(); var cfg = src.Load(complexXml).Get(); var src2 = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); TestCreatedSimpleSample(src2.Load(cfg.Basic).Get()); cfg.Basics.Length.Should().Be(3); foreach (var simple in cfg.Basics) { TestCreatedSimpleSample(src2.Load(cfg.Basic).Get()); } }
public void UsingTransformationEarlyInsert() { string mySample = @"<BasicTypesSampleWithoutAttr> <AString>whatever</AString> </BasicTypesSampleWithoutAttr>"; ; var src = new XmlConfigSource<BasicTypesSampleWithoutAttr>(); src.AddTransform(x => x.AString = "42"); src.Get().Should().Be.Null(); src.Load(mySample); src.Get().Should().Not.Be.Null(); src.Get().AString.Should().Be("42"); }