Exemple #1
0
        static void Main(string[] args)
        {
            Pupil pashka = new Pupil
            {
                Name = "Pashka",
                Age  = 15
            };

            Pupil jeka = new Pupil
            {
                Name = "Jeka",
                Age  = 18
            };

            Pupil sashka = new Pupil
            {
                Name = "Sashka",
                Age  = 21
            };

            Pupil stasik = new Pupil
            {
                Name = "Stasik",
                Age  = 35
            };

            School school96 = new School
            {
                Name  = "96",
                Pupil = new List <Pupil>()
                {
                    pashka
                }
            };

            School school143 = new School
            {
                Name  = "143",
                Pupil = new List <Pupil>()
                {
                    pashka, jeka, sashka
                },
                Room = new Room {
                    Color = "red", Table = new Table {
                        Form = "circle"
                    }
                }
            };

            School school54 = new School
            {
                Name  = "54",
                Pupil = new List <Pupil>
                {
                    jeka, pashka
                },
                Room = new Room {
                    Color = "green", Table = new Table {
                        Form = "rectangle"
                    }
                }
            };

            ReadOnlySchool school104 = new ReadOnlySchool
            {
                Name  = "104",
                pupil = new List <Pupil>
                {
                    jeka, pashka
                }
            };

            ComparisonConfig config = new ComparisonConfig();

            config.MaxDifferences  = int.MaxValue;
            config.CompareChildren = true;
            //config.IgnoreCollectionOrder = true;
            config.CustomComparers.Add(new CustomListComparer(RootComparerFactory.GetRootComparer()));
            config.CustomComparers.Add(new CustomExpandoObjectComparer(RootComparerFactory.GetRootComparer()));
            config.CustomComparers.Add(new NullToObjectComparer(RootComparerFactory.GetRootComparer()));
            ////config.CustomComparers = new List<BaseTypeComparer>();
            ////config.CustomComparers.Add(new ExpandoObjectComparer(RootComparerFactory.GetRootComparer()));
            ////config.CustomComparers.Add(new FirstNullClassComparer(RootComparerFactory.GetRootComparer()));
            ////config.CustomComparers.Add(new CollectionComparer(RootComparerFactory.GetRootComparer()));

            CompareLogic compareLogic = new CompareLogic(config);
            //ComparisonResult result = compareLogic.Compare(school143, school54);

            //var diffsResult = Scc.Portal.Orchard.AuditTrails.DiffsBuilder.DiffsBuilder.BuildDiffs(school143, school54);

            dynamic a = new ExpandoObject();
            dynamic b = new ExpandoObject();

            a.Table = "Table";
            b.Table = "Chair";
            b.Wall  = "Rectangle";
            b.Pupil = new HashSet <Pupil>
            {
                jeka, pashka
            };

            ComparisonResult expandoResult = compareLogic.Compare(a, b);

            var diffsResult = Scc.Portal.Orchard.AuditTrails.DiffsBuilder.DiffsBuilder.BuildDiffs(a, b);

            var yes = true;
        }
Exemple #2
0
        static void Maind(string[] args)
        {
            Pupil pashka = new Pupil
            {
                Name = "Pashka",
                Age  = 15
            };

            Pupil jeka = new Pupil
            {
                Name = "Jeka",
                Age  = 18
            };

            Pupil sashka = new Pupil
            {
                Name = "Sashka",
                Age  = 21
            };

            Pupil stasik = new Pupil
            {
                Name = "Stasik",
                Age  = 35
            };

            School school96 = new School
            {
                Name  = "96",
                Pupil = new List <Pupil>()
                {
                    pashka
                }
            };

            School school143 = new School
            {
                Name  = "143",
                Pupil = new List <Pupil>()
                {
                    pashka, jeka, sashka
                }
            };

            School school54 = new School
            {
                Name  = "54",
                Pupil = new List <Pupil>
                {
                    stasik, pashka, sashka
                }
            };

            var serialized96  = JsonConvert.SerializeObject(school96);
            var serialized143 = JsonConvert.SerializeObject(school143);
            var serialized54  = JsonConvert.SerializeObject(school54);

            var    jdp        = new JsonDiffPatch();
            JToken diffResult = jdp.Diff(serialized143, serialized54);

            var output  = jdp.Patch(serialized143, diffResult);
            var output1 = jdp.Patch(serialized54, diffResult);
            var output2 = jdp.Unpatch(serialized143, diffResult);
            var output3 = jdp.Unpatch(serialized54, diffResult);

            var obj1    = new { Key = 1 };
            var obj2    = new { Key = 2 };
            var serObj1 = JsonConvert.SerializeObject(obj1);
            var serObj2 = JsonConvert.SerializeObject(obj2);

            JToken patch     = jdp.Diff(serObj1, serObj2);
            var    output111 = jdp.Patch(serialized143, patch);
            var    output11  = jdp.Patch(serObj1, patch);
            var    output21  = jdp.Unpatch(serObj2, patch);

            var    left   = JToken.FromObject(school143);
            var    right  = JToken.FromObject(school54);
            JToken patch1 = jdp.Diff(left, right);
            var    result = patch1.Values();

            //var output1111 = jdp.Patch(left, patch1);

            Console.WriteLine(patch1.ToString());


            var a = true;
        }