Exemplo n.º 1
0
 public bool LoadPartialConfig(ref string partialConfigXml)
 {
     if (string.IsNullOrEmpty(partialConfigXml))
     {
         var partialConfigFile = FindPartialConfigFile();
         if (partialConfigFile == null)
         {
             return(true);
         }
         try
         {
             using (var reader = partialConfigFile.OpenText())
                 partialConfigXml = reader.ReadToEnd();
         }
         catch (Exception ex)
         {
             Logger.LogError(Message.ConfigReadPartialError, ex);
             return(false);
         }
     }
     try
     {
         if (_mergeUtil.Merge(partialConfigXml, _currentConfigXml))
         {
             string resXml;
             using (var memStream = new MemoryStream())
             {
                 using (var xmlWriter = new PrettyPrintXmlWriter(memStream))
                 {
                     _mergeUtil.Result.WriteTo(xmlWriter);
                     resXml = xmlWriter.ToFormatString();
                 }
             }
             _currentConfig    = ApplicationConfig.FromXml(resXml);
             _currentConfigXml = resXml;
         }
         return(true);
     }
     catch (Exception ex)
     {
         Logger.LogError(Message.ConfigLoadPartialError, ex);
         return(false);
     }
 }
Exemplo n.º 2
0
        public void MergeTest()
        {
            var xml1 = ReadXmlFromStream("Moonlit.TestFixtures.Xml.Xmls.merge1.xml");
            var xml2 = ReadXmlFromStream("Moonlit.TestFixtures.Xml.Xmls.merge2.xml");

            var ele = XmlMerge.Merge(XElementFinder, xml1, xml2);

            var book = ele.Elements().FirstOrDefault(x => (string)x.Attribute("name") == "c#");

            AssertAttributes(book, true, "1990");
            AssertChild(book, "name", "c#");
            AssertChild(book, "publish", "1984");

            book = ele.Elements().FirstOrDefault(x => (string)x.Attribute("name") == "c++");
            AssertAttributes(book, true, "2009");
            AssertChild(book, "name", "C++");
            AssertChild(book, "publish", "1990");

            book = ele.Elements().FirstOrDefault(x => (string)x.Attribute("name") == "c");
            AssertAttributes(book, false, "2000");
            AssertChild(book, "name", "C Language");
            AssertChild(book, "publish", "1980");
        }