public void BasicMerge() { var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1); var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml2); var conf3 = NFX.Environment.XMLConfiguration.CreateFromXML(xml4); var conf = new NFX.Environment.MemoryConfiguration(); conf.CreateFromMerge(conf1.Root, conf2.Root); var conf4 = new NFX.Environment.MemoryConfiguration(); conf4.CreateFromMerge(conf.Root, conf3.Root); Aver.AreEqual("Sub Value 1", conf.Root["section-a"]["sub1"].Value); Aver.AreEqual("Sub Value 2 ammended", conf.Root["section-a"]["sub2"].Value); Aver.AreEqual("Sub Value 3", conf.Root["section-a"]["sub3"].Value); Aver.AreEqual("CSVFile", conf.Root["section-a"].Children.FirstOrDefault(n => n.IsSameName("destination") && n.AttrByName("name").Value == "A").AttrByName("type").Value); Aver.AreEqual("Clock", conf.Root["section-a"].Children.FirstOrDefault(n => n.IsSameName("destination") && n.AttrByName("name").Value == "B").AttrByName("type").Value); Aver.AreEqual("SMTPMail", conf1.Root["section-a"].Children.FirstOrDefault(n => n.IsSameName("destination") && n.AttrByName("name").Value == "B").AttrByName("type").Value); Aver.IsTrue(conf4.Root["section-b"].AttrCount == 1); Aver.IsTrue(!conf4.Root["section-a"].Exists); }
public void MergeStop() { var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1); var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml2); var conf = new NFX.Environment.MemoryConfiguration(); conf.CreateFromMerge(conf1.Root, conf2.Root); Assert.AreEqual("This can not be overridden and no exception will be thrown", conf.Root["section-d"].Value); Assert.AreEqual(1, conf.Root["section-d"].Attributes.Count()); Assert.AreEqual(OverrideSpec.Stop, NodeOverrideRules.Default.StringToOverrideSpec(conf.Root["section-d"].AttrByName("_override").Value)); }
public void ExpectOverrideException() { var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1); var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml3); var conf = new NFX.Environment.MemoryConfiguration(); try { conf.CreateFromMerge(conf1.Root, conf2.Root); } catch (Exception error) { Console.WriteLine("Expected and got: " + error.Message); throw error; } }
public void Performance() { const int CNT = 10000; var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(largexml1); var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(largexml2); var clock = System.Diagnostics.Stopwatch.StartNew(); for (var i = 0; i < CNT; i++) { var conf = new NFX.Environment.MemoryConfiguration(); conf.CreateFromMerge(conf1.Root, conf2.Root); } clock.Stop(); Console.WriteLine("Config merge performance. Merged {0} times in {1} ms", CNT, clock.ElapsedMilliseconds); }
public void Performance() { const int CNT = 10000; var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(largexml1); var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(largexml2); var clock = System.Diagnostics.Stopwatch.StartNew(); for(var i=0; i<CNT; i++) { var conf = new NFX.Environment.MemoryConfiguration(); conf.CreateFromMerge(conf1.Root, conf2.Root); } clock.Stop(); Console.WriteLine("Config merge performance. Merged {0} times in {1} ms", CNT, clock.ElapsedMilliseconds); }
public void ExpectOverrideException() { var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1); var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml3); var conf = new NFX.Environment.MemoryConfiguration(); try { conf.CreateFromMerge(conf1.Root, conf2.Root); } catch(Exception error) { Console.WriteLine("Expected and got: "+error.Message); throw error; } }
public void BasicMerge() { var conf1 = NFX.Environment.XMLConfiguration.CreateFromXML(xml1); var conf2 = NFX.Environment.XMLConfiguration.CreateFromXML(xml2); var conf = new NFX.Environment.MemoryConfiguration(); conf.CreateFromMerge(conf1.Root, conf2.Root); Assert.AreEqual("Sub Value 1", conf.Root["section-a"]["sub1"].Value); Assert.AreEqual("Sub Value 2 ammended", conf.Root["section-a"]["sub2"].Value); Assert.AreEqual("Sub Value 3", conf.Root["section-a"]["sub3"].Value); Assert.AreEqual("CSVFile", conf.Root["section-a"].Children.FirstOrDefault(n=>n.IsSameName("destination") && n.AttrByName("name").Value=="A").AttrByName("type").Value); Assert.AreEqual("Clock", conf.Root["section-a"].Children.FirstOrDefault(n=>n.IsSameName("destination") && n.AttrByName("name").Value=="B").AttrByName("type").Value); Assert.AreEqual("SMTPMail", conf1.Root["section-a"].Children.FirstOrDefault(n=>n.IsSameName("destination") && n.AttrByName("name").Value=="B").AttrByName("type").Value); }
private void btnMerge_Click(object sender, EventArgs e) { try { var confA = LaconicConfiguration.CreateFromString(this.confMergeA.Text); var confB = LaconicConfiguration.CreateFromString(this.confMergeB.Text); var conf = new MemoryConfiguration(); conf.CreateFromMerge(confA.Root, confB.Root); this.resultMerge.Text = conf.ToLaconicString(); } catch (Exception ex) { this.resultMerge.Text = ex.ToMessageWithType(); } }