Example #1
0
        private IEnumerable <Difference> _Compare <T>(T initial, T end)
        {
            var comparer = new ObjectsComparer.Comparer();
            IEnumerable <Difference> differences;


            var result = comparer.Compare(initial.ToJson().JsonToObject <ExpandoObject>(), end.ToJson().JsonToObject <ExpandoObject>(), out differences);

            return(differences);
        }
Example #2
0
        private string DBComparer(List <ShopTabData> oldDataObj, List <ShopTabData> newDataObj)
        {
            int    counter1 = 0, counter2 = 0;
            var    key1 = ""; var key2 = "";
            string text     = "";
            var    comparer = new ObjectsComparer.Comparer();

            while (counter1 < oldDataObj.Count() && counter2 < newDataObj.Count())
            {
                var objI1 = oldDataObj[counter1];
                key1 = $"{objI1.Name}";
                var objI2 = newDataObj[counter2];
                key2 = $"{objI2.Name}";

                IEnumerable <Difference> differences;

                var res = key1.CompareTo(key2);

                if (res < 0) // key1 is before key2 ...key1 can be incremented
                {
                    //deleted records
                    var deletedRecord = oldDataObj[counter1];
                    key1 = $"{deletedRecord.Name}";
                    text = text + "{\"Name\":\"" + key1;
                    text = text + "\",\"Operation\" : \"Delete\"},";
                    counter1++;
                    continue;
                }
                else if (res > 0) // key2 is before key1 ...key2 can be incremented
                {
                    //new records
                    var newRecord = newDataObj[counter2];
                    key2 = $"{newRecord.Name}";
                    text = text + "{\"Name\":\"" + key2 + "\"," + "\"Requester\":\"" + newRecord.Requester; // + "\"DepartureDate\":\"" + newRecord.DepartureDate + "\"," + "\"AllotmentAvailable\":\"" + newRecord.AllotmentAvailable + "\"," + "\"SaleStatusId\":\"" + newRecord.SaleStatusId + "\"," + "\"SinglePrice\":\"" + newRecord.SinglePrice + "\"," + "\"DoublePrice\":\"" + newRecord.DoublePrice + "\"," + "\"PriceInterAir\":\"" + newRecord.PriceInterAir + "\"," + "\"PriceAir\":\"" + newRecord.PriceAir + "\"," + "\"PointsOverrideSingle\":\"" + newRecord.PointsOverrideSingle + "\"," + "\"PointsOverrideDouble\":\"" + newRecord.PointsOverrideDouble + "\"," + "\"PriceAdditionalSupplements\":\"" + newRecord.PriceAdditionalSupplements + "\"," + "\"PriceGround\":\"" + newRecord.PriceGround + "\"," + "\"SalesCurrencyId\":\"" + newRecord.SalesCurrencyId;
                    text = text + "\",\"Operation\" : \"Insert\"},";
                    counter2++;
                    continue;
                }
                else
                {
                    var isEqual = comparer.Compare(oldDataObj[counter1], newDataObj[counter2], out differences);

                    if (!isEqual)
                    {
                        int count   = differences.Count();
                        int counter = 1;
                        text = text + "{\"Name\":\"" + key1 + "\",";
                        foreach (var diff in differences)
                        {
                            text    = text + "\"" + diff.MemberPath + "\" :" + "\"" + diff.Value2 + "\"" + ((counter != count) ? "," : ",\"Operation\" : \"Update\"},");
                            counter = counter + 1;
                        }
                    }
                    counter1++;
                    counter2++;
                }
            }
            while (counter1 < oldDataObj.Count())
            {
                var obj = oldDataObj[counter1];
                key1 = $"{obj.Name}";
                text = text + "{\"Name\":\"" + key1;
                text = text + "\",\"Operation\" : \"Delete\"},";
                counter1++;
            }
            while (counter2 < newDataObj.Count())
            {
                var obj = newDataObj[counter2];
                key2 = $"{obj.Name}";
                text = text + "{\"Name\":\"" + key2 + "\"," + "\"Requester\":\"" + obj.Requester;// + "\"DepartureDate\":\"" + obj.DepartureDate + "\"," + "\"AllotmentAvailable\":\"" + obj.AllotmentAvailable + "\"," + "\"SaleStatusId\":\"" + obj.SaleStatusId + "\"," + "\"SinglePrice\":\"" + obj.SinglePrice + "\"," + "\"DoublePrice\":\"" + obj.DoublePrice + "\"," + "\"PriceInterAir\":\"" + obj.PriceInterAir + "\"," + "\"PriceAir\":\"" + obj.PriceAir + "\"," + "\"PointsOverrideSingle\":\"" + obj.PointsOverrideSingle + "\"," + "\"PointsOverrideDouble\":\"" + obj.PointsOverrideDouble + "\"," + "\"PriceAdditionalSupplements\":\"" + obj.PriceAdditionalSupplements + "\"," + "\"PriceGround\":\"" + obj.PriceGround + "\"," + "\"SalesCurrencyId\":\"" + obj.SalesCurrencyId;
                text = text + "\",\"Operation\" : \"Insert\"},";
                counter2++;
            }

            return((text == "")?text:text.Remove(text.Length - 1, 1));
        }