private List<CompareResult> CompareRow(DataRow rowOld, DataRow rowNew) { var compareResults = new List<CompareResult>(); for (int i = 0; i < rowNew.Table.Columns.Count; i++) { string cellNew = !Convert.IsDBNull(rowNew[i]) ? rowNew[i].ToString() : string.Empty; string cellOld = !Convert.IsDBNull(rowOld[i]) ? rowOld[i].ToString() : string.Empty; bool equal = CompareCell(cellOld, cellNew); if (!equal) { var compareResult = new CompareResult { AreEqual = false, Id = (string)rowNew[_unqiueColumn], ResultsNew = cellNew, ResultsOld = cellOld, ColumnNumber = i + 1 }; compareResults.Add(compareResult); } } return compareResults; }
public static CompareResult And(CompareResult a, CompareResult b) { if(a==b) { return a; } if(a==CompareResult.Equal) { return b; } if(b==CompareResult.Equal) { return a; } return CompareResult.Unequal; }
public static bool AllCompare(float[] lhs, float[] rhs, CompareOption comparison, out CompareResult compareResult) { compareResult = CompareResult.Equal; if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null)) return false; if (lhs.Length != rhs.Length) return false; bool allowLessThan = (comparison & CompareOption.LessThan) == CompareOption.LessThan; bool allowEqual = (comparison & CompareOption.Equal) == CompareOption.Equal; bool allowGreaterThan = (comparison & CompareOption.GreaterThan) == CompareOption.GreaterThan; if (allowEqual && ReferenceEquals(lhs, rhs)) return true; bool haveGreaterThan = false, haveLessThan = false; for (int i = 0; i < lhs.Length; i++) { int val = lhs[i].CompareTo(rhs[i]); if (val < 0) { haveLessThan = true; if (!allowLessThan) return false; if (haveGreaterThan) { compareResult = CompareResult.Unequal; return allowGreaterThan || allowLessThan || allowEqual; } } else if (val > 0) { haveGreaterThan = true; if (!allowGreaterThan) return false; if (haveLessThan) { compareResult = CompareResult.Unequal; return allowGreaterThan || allowLessThan || allowEqual; } } } if (haveGreaterThan && haveLessThan) compareResult = CompareResult.Unequal; else if (haveGreaterThan) compareResult = CompareResult.GreaterThan; else if (haveLessThan) compareResult = CompareResult.LessThan; else compareResult = CompareResult.Equal; return (allowGreaterThan && haveGreaterThan) || (allowLessThan && haveLessThan) || allowEqual; }
static void ShowCompareResult(CompareResult compareResult) { Console.WriteLine(); Console.WriteLine(compareResult.IsEqual); Console.WriteLine("======================================================="); Console.WriteLine("DifferentPropertyList:"); compareResult.DifferentPropertyList.ForEach(p => { Console.WriteLine("ObjectAPropertyName = {0}, ObjectBPropertyName = {1}, ValueA = {2}, ValueB = {3}", p.ObjectAPropertyName, p.ObjectBPropertyName, p.ObjectAValue, p.ObjectBValue); }); Console.WriteLine("======================================================="); Console.WriteLine("SamePropertyList:"); compareResult.SamePropertyList.ForEach(p => { Console.WriteLine("ObjectAPropertyName = {0}, ObjectBPropertyName = {1}, ValueA = {2}, ValueB = {3}", p.ObjectAPropertyName, p.ObjectBPropertyName, p.ObjectAValue, p.ObjectBValue); }); Console.WriteLine("Exception:{0}", compareResult.Exception); }
//Transform numeric result into string description public String GetResult(CompareResult result) { String retVal = null; for (int i = 0; i < 8; i++) { if (((int)result & (0x01 << i)) == (0x01 << i)) { if (retVal == null) { retVal = "{" + ((CompareResult)(0x01 << i)).ToString(); } else { retVal = retVal + "," + ((CompareResult)(0x01 << i)).ToString(); } } } if (retVal == null) { retVal = "{Equal}"; } else { retVal = retVal + "}"; } return retVal; }
private void WriteSummaryResultLine(StreamWriter html, CompareResult result, string diffName) { var format = @"<tr class=""summary-table-row""> <td><a href=""{6}"">{0}</a></td> <td class=""right"">{1:n2}</td> <td><a href=""{7}"">{2}</a></td> <td class=""right"">{3:n2}</td> <td class=""right"">{4}</td> <td class=""right"">{5}</td> <td class=""right"">{8:n2}</td> <td><a href=""{9}"">Diff</a></td> </tr>"; if (result.SimilarityA >= result.SimilarityB) { html.WriteLine(format, result.A.FilePath.MaxLength(17, "...", true), 100.0 * result.SimilarityA, result.B.FilePath.MaxLength(17, "...", true), 100.0 * result.SimilarityB, result.MatchCount, result.TokenCount, result.A.FilePath, result.B.FilePath, (double)result.TokenCount / (double)result.MatchCount, diffName); } else { // This is a little lie, as it does not match the table headers. // But to the user the lables A and B are not important html.WriteLine(format, result.B.FilePath.MaxLength(17, "...", true), 100.0 * result.SimilarityB, result.A.FilePath.MaxLength(17, "...", true), 100.0 * result.SimilarityA, result.MatchCount, result.TokenCount, result.B.FilePath, result.A.FilePath, (double)result.TokenCount / (double)result.MatchCount, diffName); } }
private void WriteDetailB(CompareResult result, StreamWriter html) { html.WriteLine("<div class=\"detail-col\">"); html.WriteLine("<h2>{0}</h2>", Path.GetFileName(result.B.FilePath)); html.WriteLine("<div class=\"detail-submission-summary\"><a href=\"{0}\">{0}</a><br/>Similarity: {1:n2} %<br/>Token: {2}</div>", result.B.FilePath, result.SimilarityB * 100.0, result.B.Tokens.Length); html.WriteLine("<div class=\"detail-code\">"); using (var rd = new StreamReader(result.B.FilePath)) { ColorDiff(html, result, rd, m => m.TokensB); } html.WriteLine("</div></div>"); }
private void WriteDetail(CompareResult result, string diffName) { using (var html = new StreamWriter(Path.Combine(OutPath, diffName))) { WriteHeader(html, diffName, "../", new TupleList<string, string>() { { "index.html", "Results" }, { "friendfinder.html", "Friend Finder" } }); html.WriteLine("<h1>Details</h2>"); html.WriteLine("<p id=\"detail-summary\">Matches: {0}<br/>Common token: {1}<br/>Token / match: {2:n2}</p>", result.MatchCount, result.TokenCount, (double)result.TokenCount / (double)result.MatchCount); if (result.SimilarityA >= result.SimilarityB) { WriteDetailA(result, html); WriteDetailB(result, html); } else { WriteDetailB(result, html); WriteDetailA(result, html); } WriteFooter(html); html.Flush(); } }
private void ColorDiff(StreamWriter diffHtml, CompareResult result, StreamReader rd, Func<Match, LinkedList<Token>> tokenExtractor) { var content = rd.ReadToEnd(); int idx = 0; var currentMatch = result.Matches.OrderBy(m => tokenExtractor(m).First.Value.Start).ToList().GetEnumerator(); currentMatch.MoveNext(); while (idx < content.Length) { int start = currentMatch.Current != null ? tokenExtractor(currentMatch.Current).First.Value.Start : content.Length; if (start > idx) { // not in match diffHtml.Write(System.Web.HttpUtility.HtmlEncode(content.Substring(idx, start - idx))); idx = start; } else { int end = tokenExtractor(currentMatch.Current).Last.Value.End; // in match diffHtml.Write("<span class=\"highlight color-{0}\">", Colors[currentMatch.Current.Index % Colors.Length]); diffHtml.Write(System.Web.HttpUtility.HtmlEncode(content.Substring(idx, end - idx))); diffHtml.Write("</span>"); currentMatch.MoveNext(); idx = end; } } }
private static string GetDetailFileName(CompareResult result) { return string.Format("Matches/Match_{0:00000}.html", result.Index + 1); }
public CompareOp(CompareResult compareResult) { _compareResult = compareResult; }
private static CompareResult NegateCompareResult(CompareResult result) { switch (result) { case CompareResult.Less: return CompareResult.Greater; case CompareResult.Greater: return CompareResult.Less; } return result; }
private static string CompareResultToString(CompareResult result, string less, string greater, string equals) { switch (result) { case CompareResult.Less: return less; case CompareResult.Greater: return greater; case CompareResult.Equal: return equals; } return "?"; }