public static tablediff CompareTable(table left, table right) { tablediff tdiff = new tablediff(); if (left != null && right != null) { for (int i = 0; i < right.configs.Count; i++) { if (left.configsDic.ContainsKey(right.configs[i].key)) { CompareTablerow(left.configsDic[right.configs[i].key], right.configs[i], ref tdiff); } else { tdiff.deletedrows.Add(right.configs[i].key, right.configs[i]); } } } if (left != null) { foreach (var item in left.configsDic) { if (right == null || !right.configsDic.ContainsKey(item.Key)) { tdiff.addedrows.Add(item.Key, item.Value); } } } return(tdiff); }
private static void CompareTablerow(config left, config right, ref tablediff tdiff) { for (int i = 0; i < right.properties.Count; i++) { if (!left.propertiesDic.ContainsKey(right.properties[i].name)) { AddModifiedRow(right.key, right.properties[i], 0, ref tdiff); } else if (!left.propertiesDic[right.properties[i].name].value.Equals(right.properties[i].value)) { AddModifiedRow(right.key, right.properties[i], 2, ref tdiff); } } foreach (var item in left.propertiesDic) { if (!right.propertiesDic.ContainsKey(item.Key)) { AddModifiedRow(left.key, item.Value, 1, ref tdiff); } } }
private static void AddModifiedRow(string rowkey, property property, int type, ref tablediff tdiff) { if (!tdiff.modifiedrows.ContainsKey(rowkey)) { tdiff.modifiedrows.Add(rowkey, new tablerowdiff()); } switch (type) { case 0: //deleted tdiff.modifiedrows[rowkey].deletedcells.Add(property.name, property); break; case 1: //added tdiff.modifiedrows[rowkey].addedcells.Add(property.name, property); break; case 2: //modified tdiff.modifiedrows[rowkey].modifiedcells.Add(property.name, property); break; } }