private void button2_Click(object sender, EventArgs e) { Func f = ef.FuncList[0]; Func f1 = ef1.FuncList[0]; diff_match_patch dfp = new diff_match_patch(); List<Diff> dfresult = new List<Diff>(); dfresult = dfp.diff_lineMode(f.BusinFlow.ToString(), f1.BusinFlow.ToString()); //dfresult = dfp.diff_main("good well \r\ntest", "test well \r\ntest"); foreach (Diff d in dfresult) { if (d.operation != Operation.EQUAL) { rtbLog.AppendText(d.operation.ToString() + " " + d.text); } } //IDiffer df = new Differ(); //DiffPlex.Model.DiffResult dfresult = df.CreateLineDiffs(f.BusinFlow.ToString(), f1.BusinFlow.ToString(), false); //DiffPlex.Model.d dfresult = df.CreateLineDiffs(f.BusinFlow.ToString(), f1.BusinFlow.ToString(), false); // 分析对比结果,怎么分析? // 以eques 为分界 // 到下一个 equas 为止 // 如何界定多少行 // return; }
private static List <Diff> Compare(IEnumerable <Spell> setA, IEnumerable <Spell> setB, Func <Spell, string> getTextA, Func <Spell, string> getTextB) { var dmp = new DiffMatchPatch.diff_match_patch(); var diffs = new List <Diff>(); // compare the same spell ID in each list one by one, then each line by line var A = setA.Where(x => x.ID > 0).OrderBy(x => x.ID).ToList(); var B = setB.Where(x => x.ID > 0).OrderBy(x => x.ID).ToList(); int a = 0; // current index in list A int b = 0; // current index in list B int count = 0; int id = 0; while (true) { id++; if (a >= A.Count && b >= B.Count) { break; } // reached end of list A, treat remainder of list B as inserts if (a >= A.Count) { while (b < B.Count) { diffs.Add(new Diff(Operation.INSERT, getTextB(B[b++]))); } break; } // reached end of list B, treat remainder of list A as deletes if (b >= B.Count) { while (a < A.Count) { diffs.Add(new Diff(Operation.DELETE, getTextA(A[a++]))); } break; } // id doesn't exist in either list if (A[a].ID > id && B[b].ID > id) { continue; } // id exists in both lists if (A[a].ID == id && B[b].ID == id) { var textA = getTextA(A[a++]); var textB = getTextB(B[b++]); // ignore equal spells if (textA == textB) { continue; } diffs.AddRange(dmp.diff_lineMode(textA, textB)); count++; continue; } // id exist only in list A if (A[a].ID == id) { diffs.Add(new Diff(Operation.DELETE, getTextA(A[a++]))); count++; continue; } // id exists only in list B if (B[b].ID == id) { diffs.Add(new Diff(Operation.INSERT, getTextB(B[b++]))); count++; continue; } throw new NotImplementedException(); // should never get here } return(diffs); }
private static List<Diff> Compare(IEnumerable<Spell> setA, IEnumerable<Spell> setB, Func<Spell, string> getTextA, Func<Spell, string> getTextB) { var dmp = new DiffMatchPatch.diff_match_patch(); var diffs = new List<Diff>(); // compare the same spell ID in each list one by one, then each line by line var A = setA.Where(x => x.ID > 0).OrderBy(x => x.ID).ToList(); var B = setB.Where(x => x.ID > 0).OrderBy(x => x.ID).ToList(); int a = 0; // current index in list A int b = 0; // current index in list B int count = 0; int id = 0; while (true) { id++; if (a >= A.Count && b >= B.Count) break; // reached end of list A, treat remainder of list B as inserts if (a >= A.Count) { while (b < B.Count) diffs.Add(new Diff(Operation.INSERT, getTextB(B[b++]))); break; } // reached end of list B, treat remainder of list A as deletes if (b >= B.Count) { while (a < A.Count) diffs.Add(new Diff(Operation.DELETE, getTextA(A[a++]))); break; } // id doesn't exist in either list if (A[a].ID > id && B[b].ID > id) continue; // id exists in both lists if (A[a].ID == id && B[b].ID == id) { var textA = getTextA(A[a++]); var textB = getTextB(B[b++]); // ignore equal spells if (textA == textB) continue; diffs.AddRange(dmp.diff_lineMode(textA, textB)); count++; continue; } // id exist only in list A if (A[a].ID == id) { diffs.Add(new Diff(Operation.DELETE, getTextA(A[a++]))); count++; continue; } // id exists only in list B if (B[b].ID == id) { diffs.Add(new Diff(Operation.INSERT, getTextB(B[b++]))); count++; continue; } throw new NotImplementedException(); // should never get here } return diffs; }