Example #1
0
        private void Collect(DiffPair pair, ConcurrentDictionary <string, DataDiffTable> result)
        {
            var basis         = pair.Base ?? new XElement("stub");
            var updated       = pair.Updated ?? new XElement("stub");
            var baseTableName = pair.Updated.Attr("table");
            var mixed         = pair.Updated.Attr("mixed").ToBool();
            var dynamicname   = mixed || string.IsNullOrWhiteSpace(baseTableName);
            var hierarchy     = pair.Updated.Attr("tree").ToBool();
            var script        = pair.Updated.Attr("script");

            if (string.IsNullOrWhiteSpace(script))
            {
                script = "10_Main";
            }
            var diffconfig = new XDiffOptions {
                IsHierarchy                    = hierarchy,
                MergeAttributeChanges          = true,
                TreatNewAttributesAsChanges    = true,
                TreatDeleteAttributesAsChanges = _context.EmptyAttributesAsUpdates,
                IncludeActions                 = XDiffAction.RenameElement | XDiffAction.MainCreateOrUpdate
            };
            var sw   = Stopwatch.StartNew();
            var diff = new XDiffGenerator(diffconfig).GetDiff(basis, updated).ToArray();

            Collect(dynamicname, baseTableName, diff, result, script);
            sw.Stop();
            _context.Log.Debug("diff of " + baseTableName + " : " + sw.Elapsed);
        }
Example #2
0
        private static string GetResult(XElement b, XElement n, XDiffOptions opts = null)
        {
            var result = new XDiffGenerator(opts).GetDiff(b, n).LogToString().Replace("\"", "'").Trim();

            Console.WriteLine(result);
            return(result);
        }
Example #3
0
        public void CanAppplyPatch()
        {
            var b = XElement.Parse("<a><z id='1' code='2' name='2'/><z id='3' code='3' name='4'/></a>");
            var n = XElement.Parse("<a><z id='3' set-code='4' name='2'/><z id='1' set-code='3' name='4'/></a>");

            Assert.True(new XDiffGenerator().IsDiff(b, n));
            var result = new XDiffGenerator().GetDiff(b, n).Apply(b);

            Console.WriteLine(result.ToString());
            Assert.False(new XDiffGenerator().IsDiff(b, n));
        }
Example #4
0
        public void CanAppplyPatchHierarchcallyWithNameChanges()
        {
            var b    = XElement.Parse("<a><z code='2' name='y'/><z id='3' code='4'><x id='5' name='x'/></z></a>");
            var n    = XElement.Parse("<a><u code='2' name='y'><y id='5' name='x'/></u><z id='3' code='4'></z></a>");
            var opts = new XDiffOptions {
                IsHierarchy = true, IsNameIndepended = true
            };

            GetResult(b, n, opts);
            Assert.True(new XDiffGenerator(opts).IsDiff(b, n));
            var result = new XDiffGenerator(opts).GetDiff(b, n).Apply(b, opts);

            Console.WriteLine(result.ToString());
            Assert.False(new XDiffGenerator(opts).IsDiff(b, n));
        }
Example #5
0
        public void LargeXmlPerformanceTest()
        {
            var sb = new StringBuilder();

            for (var c = 500; c <= 100000; c += 500)
            {
                var x1  = new XElement("x1");
                var x2  = new XElement("x2");
                var rnd = new Random();
                for (var i = 0; i < c; i++)
                {
                    var id1 = i + 3;
                    var id2 = c - i + 4;
                    var n1  = rnd.Next(1000000);
                    var n2  = rnd.Next(1000000);
                    x1.Add(new XElement("x", new XAttribute("id", id1)
                                        , new XAttribute("name", n1)
                                        , new XAttribute("name1", n1)
                                        , new XAttribute("name2", n1)
                                        , new XAttribute("name3", n1)
                                        ));

                    x2.Add(new XElement("x", new XAttribute("id", id2)
                                        , new XAttribute("name", n2)
                                        , new XAttribute("name1", n2)
                                        , new XAttribute("nam2", n2)
                                        , new XAttribute("nam3", n2)
                                        , new XAttribute("name4", n2)
                                        ));
                }
                var gen = new XDiffGenerator(new XDiffOptions {
                    MergeAttributeChanges = true, TreatNewAttributesAsChanges = true
                });
                var sw   = Stopwatch.StartNew();
                var diff = gen.GetDiff(x1, x2).ToArray();
                sw.Stop();
                sb.AppendFormat("{0};{1}\r\n", c, sw.Elapsed.TotalMilliseconds);
                Console.WriteLine("{0}\t\t{1}", c, sw.Elapsed.TotalMilliseconds);
            }

            Console.WriteLine(sb.ToString());
            File.WriteAllText(@"g:\repos\xdifftiming.csv", sb.ToString());
        }
Example #6
0
        public void CanMergeNonSeparateNewAndUpdatedAttributes()
        {
            var b    = XElement.Parse("<a><z id='1' name='2' a='3' b='4' c='5'/></a>");
            var n    = XElement.Parse("<a><z id='1' name='2' a='6' b='4' c='7' d='8' e='9'/></a>");
            var opts = new XDiffOptions {
                MergeAttributeChanges = true, TreatNewAttributesAsChanges = true
            };
            var diff = new XDiffGenerator(opts).GetDiff(b, n).ToArray();
            var log  = diff.LogToString();

            Console.WriteLine(log);
            Assert.AreEqual(1, diff.Length);
            Assert.AreEqual(@"ChangeAttribute n0
	BasisElement name=z id=1
	NewestElement : (<update a=""6"" c=""7"" d=""8"" e=""9"" />)
", log);

            diff.Apply(b, opts);
            Assert.False(new XDiffGenerator().IsDiff(b, n));
        }
Example #7
0
		public void LargeXmlPerformanceTest(){
			var sb = new StringBuilder();
			for (var c = 500; c <= 100000; c+=500){
				var x1 = new XElement("x1");
				var x2 = new XElement("x2");
				var rnd = new Random();
				for (var i = 0; i < c; i++){
					var id1 = i + 3;
					var id2 = c - i + 4;
					var n1 = rnd.Next(1000000);
					var n2 = rnd.Next(1000000);
					x1.Add(new XElement("x", new XAttribute("id", id1)
					                    , new XAttribute("name", n1)
					                    , new XAttribute("name1", n1)
					                    , new XAttribute("name2", n1)
					                    , new XAttribute("name3", n1)
						       ));

					x2.Add(new XElement("x", new XAttribute("id", id2)
					                    , new XAttribute("name", n2)
					                    , new XAttribute("name1", n2)
					                    , new XAttribute("nam2", n2)
					                    , new XAttribute("nam3", n2)
					                    , new XAttribute("name4", n2)
						       ));
				}
				var gen = new XDiffGenerator(new XDiffOptions{MergeAttributeChanges = true, TreatNewAttributesAsChanges = true});
				var sw = Stopwatch.StartNew();
				var diff = gen.GetDiff(x1, x2).ToArray();
				sw.Stop();
				sb.AppendFormat("{0};{1}\r\n",c,sw.Elapsed.TotalMilliseconds);
				Console.WriteLine("{0}\t\t{1}", c, sw.Elapsed.TotalMilliseconds);
				
			}

			Console.WriteLine(sb.ToString());
			File.WriteAllText(@"g:\repos\xdifftiming.csv",sb.ToString());
		}
Example #8
0
        public void CanMergeNonSeparateDeleteAsChangesAttributes()
        {
            var b    = XElement.Parse("<a><z id='1' name='2' a='3' b='4' c='5' x='aaa6'/></a>");
            var n    = XElement.Parse("<a><z id='1' name='2' a='3' b='3' /></a>");
            var opts = new XDiffOptions {
                MergeAttributeChanges = true, TreatDeleteAttributesAsChanges = true
            };
            var diff = new XDiffGenerator(opts).GetDiff(b, n).ToArray();
            var log  = diff.LogToString();

            Console.WriteLine(log);
            Assert.AreEqual(1, diff.Length);
            Assert.AreEqual(@"ChangeAttribute n0
	BasisElement name=z id=1
	NewestElement : (<update b=""3"" c=""0"" x="""" />)
".LfOnly().Trim(), log.LfOnly().Trim());

            diff.Apply(b, opts);
            Console.WriteLine(b);
            Assert.AreEqual(@"<a>
  <z id=""1"" name=""2"" a=""3"" b=""3"" c=""0"" x="""" />
</a>".Trim().LfOnly(), b.ToString().Trim().LfOnly());
        }
Example #9
0
		private static string GetResult(XElement b, XElement n, XDiffOptions opts = null){
			var result = new XDiffGenerator(opts).GetDiff(b, n).LogToString().Replace("\"", "'").Trim();
			Console.WriteLine(result);
			return result;
		}
Example #10
0
		public void CanAppplyPatchHierarchcallyWithNameChanges()
		{
			var b = XElement.Parse("<a><z code='2' name='y'/><z id='3' code='4'><x id='5' name='x'/></z></a>");
			var n = XElement.Parse("<a><u code='2' name='y'><y id='5' name='x'/></u><z id='3' code='4'></z></a>");
			var opts = new XDiffOptions{IsHierarchy = true, IsNameIndepended = true};
			GetResult(b, n, opts);
			Assert.True(new XDiffGenerator(opts).IsDiff(b, n));
			var result = new XDiffGenerator(opts).GetDiff(b, n).Apply(b,opts);
			Console.WriteLine(result.ToString());
			Assert.False(new XDiffGenerator(opts).IsDiff(b, n));
		}
Example #11
0
		public void CanAppplyPatch()
		{
			var b = XElement.Parse("<a><z id='1' code='2' name='2'/><z id='3' code='3' name='4'/></a>");
			var n = XElement.Parse("<a><z id='3' set-code='4' name='2'/><z id='1' set-code='3' name='4'/></a>");
			Assert.True(new XDiffGenerator().IsDiff(b, n));
			var result = new XDiffGenerator().GetDiff(b,n).Apply(b);
			Console.WriteLine(result.ToString());
			Assert.False(new XDiffGenerator().IsDiff(b,n));
		}
Example #12
0
		public void CanMergeNonSeparateDeleteAsChangesAttributes()
		{
			var b = XElement.Parse("<a><z id='1' name='2' a='3' b='4' c='5' x='aaa6'/></a>");
			var n = XElement.Parse("<a><z id='1' name='2' a='3' b='3' /></a>");
			var opts = new XDiffOptions { MergeAttributeChanges = true, TreatDeleteAttributesAsChanges = true };
			var diff = new XDiffGenerator(opts).GetDiff(b, n).ToArray();
			var log = diff.LogToString();
			Console.WriteLine(log);
			Assert.AreEqual(1, diff.Length);
			Assert.AreEqual(@"ChangeAttribute n0
	BasisElement name=z id=1
	NewestElement : (<update b=""3"" c=""0"" x="""" />)
".LfOnly().Trim(), log.LfOnly().Trim());

			diff.Apply(b, opts);
			Console.WriteLine(b);
			Assert.AreEqual(@"<a>
  <z id=""1"" name=""2"" a=""3"" b=""3"" c=""0"" x="""" />
</a>".Trim().LfOnly(),b.ToString().Trim().LfOnly());
		}
Example #13
0
		public void CanMergeNonSeparateNewAndUpdatedAttributes()
		{
			var b = XElement.Parse("<a><z id='1' name='2' a='3' b='4' c='5'/></a>");
			var n = XElement.Parse("<a><z id='1' name='2' a='6' b='4' c='7' d='8' e='9'/></a>");
			var opts = new XDiffOptions { MergeAttributeChanges = true,TreatNewAttributesAsChanges = true};
			var diff = new XDiffGenerator(opts).GetDiff(b, n).ToArray();
			var log = diff.LogToString();
			Console.WriteLine(log);
			Assert.AreEqual(1, diff.Length);
			Assert.AreEqual(@"ChangeAttribute n0
	BasisElement name=z id=1
	NewestElement : (<update a=""6"" c=""7"" d=""8"" e=""9"" />)
", log);

			diff.Apply(b, opts);
			Assert.False(new XDiffGenerator().IsDiff(b, n));
		}