Exemplo n.º 1
0
        private ObjectDiff NormalizeValues(ObjectDiff objDiff)
        {
            objDiff.Items.ForEach(delegate(ItemDiff item)
            {
                string modifValue = item.Values[0];
                switch (item.Values.Count)
                {
                case 1:
                    item.Values.RemoveAt(0);
                    item.Values.Add(string.Empty);
                    item.Values.Add(modifValue);
                    break;

                case 3:
                    item.Values.RemoveAt(0);
                    item.Values.RemoveAt(0);
                    item.Values.RemoveAt(0);
                    item.Values.Add(modifValue);
                    item.Values.Add(string.Empty);
                    break;

                default:
                    break;
                }
            });
            return(objDiff);
        }
Exemplo n.º 2
0
 public ObjectDiff TrackChanges(string StrOriginalJSON, string StrModifiedJSON, List <string> IgnoreAttribs)
 {
     try
     {
         return(new ConvertJsonToObject(StrOriginalJSON, StrModifiedJSON, IgnoreAttribs).DiffObj());
     }
     catch (Exception e)
     {
         ObjectDiff objectDiff_Excetion = new ObjectDiff
         {
             ObjectName = e.Message
         };
         return(objectDiff_Excetion);
     }
 }
Exemplo n.º 3
0
 public ObjectDiff DiffJSON()
 {
     try
     {
         return(new ConvertJsonToObject(stringOriginalJSON, stringModifiedJSON, ignoreAttributies).DiffObj());
     }
     catch (Exception e)
     {
         ObjectDiff objectDiff_Excetion = new ObjectDiff
         {
             ObjectName = e.Message
         };
         return(objectDiff_Excetion);
     }
 }
Exemplo n.º 4
0
        public ObjectDiff DiffObj()
        {
            ObjectDiff objectDiff = new ObjectDiff();
            string     varAttrib  = null;

            using (StringReader reader = new StringReader(ReturnJsonTransformed()))
            {
                WhatInstanceOf(ReturnJsonTransformed());
                string line;
                if (IsEntityType)
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line != string.Empty)
                        {
                            if ((line.Length > 1) && !line.Equals("    ],") && !line.Equals("    ]") && !line.Equals("  }"))
                            {
                                if (line.Substring(0, 3).Equals("  \""))
                                {
                                    objectDiff.ObjectName = line.Split(CHAR_DOUBLE_QUOTE)[1];
                                }
                                else
                                {
                                    if (line.Substring(0, 5).Equals("    \""))
                                    {
                                        varAttrib = line.Split(CHAR_DOUBLE_QUOTE)[1];
                                    }
                                    else
                                    {
                                        if (!IsIgnoreAttribute(varAttrib))
                                        {
                                            if (line.Substring(0, 6).Equals("      "))
                                            {
                                                string sValue = line.EndsWith(",") ? line.Substring(0, line.Length - 1).Trim() : line.Trim();
                                                sValue = (sValue.StartsWith(STRING_DOUBLE_QUOTE) && sValue.EndsWith(STRING_DOUBLE_QUOTE)) ? sValue = sValue.Substring(1, sValue.Length - 2).Trim() : sValue;
                                                ItemDiff dJsonDiffItemFIND = objectDiff.Items.Find(item => item.AttributeName == varAttrib);
                                                if (dJsonDiffItemFIND == null)
                                                {
                                                    ItemDiff itemDiff = new ItemDiff
                                                    {
                                                        AttributeName = varAttrib
                                                    };
                                                    itemDiff.Values.Add(sValue);
                                                    objectDiff.Items.Add(itemDiff);
                                                }
                                                else
                                                {
                                                    dJsonDiffItemFIND.Values.Add(sValue);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (IsStructureType)
                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            if ((line != null) && (line.Length > 1) && !line.Equals("  ],") && !line.Equals("  ]"))
                            {
                                if (line.Substring(0, 3).Equals("  \""))
                                {
                                    varAttrib = line.Split(CHAR_DOUBLE_QUOTE)[1];
                                }
                                else
                                {
                                    if (!IsIgnoreAttribute(varAttrib))
                                    {
                                        if (line.Substring(0, 4).Equals("    "))
                                        {
                                            string sValue = line.EndsWith(",") ? line.Substring(0, line.Length - 1).Trim() : line.Trim();
                                            sValue = (sValue.StartsWith(STRING_DOUBLE_QUOTE) && sValue.EndsWith(STRING_DOUBLE_QUOTE)) ? sValue = sValue.Substring(1, sValue.Length - 2).Trim() : sValue;
                                            ItemDiff dJsonDiffItemFIND = objectDiff.Items.Find(item => item.AttributeName == varAttrib);
                                            if (dJsonDiffItemFIND == null)
                                            {
                                                ItemDiff itemDiff = new ItemDiff
                                                {
                                                    AttributeName = varAttrib
                                                };
                                                itemDiff.Values.Add(sValue);
                                                objectDiff.Items.Add(itemDiff);
                                            }
                                            else
                                            {
                                                dJsonDiffItemFIND.Values.Add(sValue);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        objectDiff.ObjectName = "Structure";
                    }
                }
                objectDiff = NormalizeValues(objectDiff);
                if (objectDiff.Items.Count < 1)
                {
                    objectDiff = new ObjectDiff();
                }
            }
            return(objectDiff);
        }