public static bool PostFilter(string key, string content) { object cache = CacheHelper.Cache_Get(key); int cacheTimes = 1; string cacheContent = ""; if (cache != null) { cacheTimes = int.Parse(((object[])cache)[0].ToString()); cacheContent = ((object[])cache)[1].IsNotNull()? ((object[])cache)[1].ToString():""; decimal similarity = TextDiff.Similar(content, cacheContent); if (similarity == 1M) { return(false); } else if (similarity > Max_Content_Similarity) { cacheTimes += 1; if (cacheTimes > Max_Similar_Submit_Times) { return(false); } } else { cacheTimes = 1; } } CacheHelper.Cache_Store(key, new object[] { cacheTimes, content }, TimeSpan.FromHours(5)); return(true); }
private void btnCompare_Click(object sender, EventArgs e) { DiffControl diffControl = new DiffControl(); diffControl.Dock = DockStyle.Fill; panel.Controls.Clear(); panel.Controls.Add(diffControl); bool chkIgnoreCase = false; bool chkIgnoreWhitespace = true; bool chkSupportChangeEditType = false; List<string> code1, code2; code1 = GetContent(tbSrcDir.Text); for (int i = 0; i < code1.Count; i++) code1[i] = code1[i].Substring(tbSrcDir.Text.Length); code2 = GetContent(tbDstDir.Text); for (int i = 0; i < code2.Count; i++) code2[i] = code2[i].Substring(tbDstDir.Text.Length); try { TextDiff diff = new TextDiff(HashType.CRC32, chkIgnoreCase, chkIgnoreWhitespace, 0, chkSupportChangeEditType); EditScript script = diff.Execute(code1, code2); diffControl.SetData(code1, code2, script);//, strA, strB); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnCompare_Click(object sender, EventArgs e) { DiffControl diffControl = new DiffControl(); diffControl.Dock = DockStyle.Fill; panel.Controls.Clear(); panel.Controls.Add(diffControl); bool chkIgnoreCase = false; bool chkIgnoreWhitespace = true; bool chkSupportChangeEditType = true; IList<string> code1, code2; code1 = GetDbDDL((cbSrcDb.SelectedItem as ConnectionSettings).Database); code2 = GetDbDDL((cbDstDb.SelectedItem as ConnectionSettings).Database); try { TextDiff diff = new TextDiff(HashType.CRC32, chkIgnoreCase, chkIgnoreWhitespace, 0, chkSupportChangeEditType); EditScript script = diff.Execute(code1, code2); diffControl.SetData(code1, code2, script);//, strA, strB); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void ChangeEditTypeTests() { bool ignoreCase = true; bool ignoreWhiteSpace = true; int leadingCharactersToIgnore = 0; bool supportChangeEditType = true; var txtDiff = new TextDiff(HashType.HashCode, ignoreCase, ignoreWhiteSpace, leadingCharactersToIgnore, supportChangeEditType); var editScript = txtDiff.Execute(new List <string> { "acc" }, new List <string> { "abc" }); Assert.IsTrue(editScript.TotalEditLength == 2); Assert.IsTrue(editScript.Count != editScript.TotalEditLength); Assert.IsTrue(editScript.Count == 1); Assert.IsTrue(editScript[0].EditType == EditType.Change); Assert.IsTrue(editScript[0].Length == 1); editScript = null; editScript = txtDiff.Execute(new List <string> { "abc" }, new List <string> { "abc" }); Assert.IsTrue(editScript.TotalEditLength == 0); Assert.IsTrue(editScript.Count == editScript.TotalEditLength); }
public string GetComprasonHTML(string tableId, string elementId, string property, string newValue) { Element old = client.GetElement(tableId, client.GetElementbyIDFromIdentifier(elementId)); string oldValue = old.Values[property]; TextDiff diffobj = new TextDiff(new MyersDiff(), new HTMLDiffOutputGenerator("span", "style", "color:#003300;background-color:#ccff66;", "color:#990000;background-color:#ffcc99;text-decoration:line-through;", "")); return(diffobj.GenerateDiffOutput(oldValue, newValue)); }
public static void ShowDiff(this DiffControl ctrl, string a, string b) { TextDiff diff = new TextDiff(HashType.HashCode, true, true, 0, false); List <string> la = new List <string>(a.Split('\n')); List <string> lb = new List <string>(b.Split('\n')); EditScript script = diff.Execute(la, lb); ctrl.SetData(la, lb, script); }
public void ShowDifferences(ShowDiffArgs e) { string textA = e.A; string textB = e.B; DiffType diffType = e.DiffType; IList <string> a, b; int leadingCharactersToIgnore = 0; bool fileNames = diffType == DiffType.File; if (fileNames) { GetFileLines(textA, textB, out a, out b, out leadingCharactersToIgnore); } else { GetTextLines(textA, textB, out a, out b); } bool isBinaryCompare = leadingCharactersToIgnore > 0; bool ignoreCase = isBinaryCompare ? false : Options.IgnoreCase; bool ignoreTextWhitespace = isBinaryCompare ? false : Options.IgnoreTextWhitespace; TextDiff diff = new TextDiff(Options.HashType, ignoreCase, ignoreTextWhitespace, leadingCharactersToIgnore, !Options.ShowChangeAsDeleteInsert); EditScript script = diff.Execute(a, b); string captionA = string.Empty; string captionB = string.Empty; if (fileNames) { captionA = textA; captionB = textB; this.Text = string.Format("{0} : {1}", Path.GetFileName(textA), Path.GetFileName(textB)); } else { this.Text = "Text Comparison"; } // Apply options first since SetData needs to know things // like SpacesPerTab and ShowWhitespace up front, so it // can build display lines, determine scroll bounds, etc. this.ApplyOptions(); this.DiffCtrl.SetData(a, b, script, captionA, captionB, ignoreCase, ignoreTextWhitespace, isBinaryCompare); if (Options.LineDiffHeight != 0) { this.DiffCtrl.LineDiffHeight = Options.LineDiffHeight; } this.Show(); this.currentDiffArgs = e; }
public void Compare() { TextDiff sourceDiffList = new TextDiff(_originalSourceText); TextDiff destDiffList = new TextDiff(_originalDestText); DiffEngine de = new DiffEngine(); de.ProcessDiff(sourceDiffList, destDiffList, DiffEngineLevel.Medium); ArrayList rep = de.DiffReport(); DisplayDiff(sourceDiffList, destDiffList, rep); }
private TextDiff getTextDiff(TextDiff diff, IEnumerable <ClassDeclarationSyntax> stepClass, IEnumerable <string> stubs) { var stepClassPosition = stepClass.First().GetLocation().GetLineSpan().EndLinePosition; diff.Span = new Span { Start = stepClassPosition.Line, StartChar = stepClassPosition.Character - 1, End = stepClassPosition.Line, EndChar = stepClassPosition.Character - 1 }; diff.Content = $"{Environment.NewLine}{string.Join(Environment.NewLine, stubs)}\t"; return(diff); }
/// Sets the diff data private void ShowDifferences(string mine, string theirs) { Collection <string> A, B; GetFileLines(mine, theirs, out A, out B); TextDiff Diff = new TextDiff(HashType.HashCode, false, false); EditScript Script = Diff.Execute(A, B); string strCaptionA = "Mine"; string strCaptionB = "Theirs"; //Ankh.Diff.FileName fnA = new Ankh.Diff.FileName(mine); //Ankh.Diff.FileName fnB = new Ankh.Diff.FileName(theirs); diffControl.SetData(A, B, Script, strCaptionA, strCaptionB); }
private TextDiff getTextDiff(TextDiff diff, SyntaxNode root, IEnumerable <string> stubs, string file) { var stepClassPosition = root.GetLocation().GetLineSpan().EndLinePosition; var className = FileHelper.GetClassName(file); diff.Span = new Span { Start = stepClassPosition.Line + 1, StartChar = stepClassPosition.Character, End = stepClassPosition.Line + 1, EndChar = stepClassPosition.Character }; diff.Content = GetNewClassContent(className, stubs); return(diff); }
public static void CompareCode(string filePath, string modifiedContent) { Form f = new Form(); f.WindowState = FormWindowState.Maximized; f.Text = "[Original] vs. [Modified]"; //ComponentResourceManager resources = new ComponentResourceManager(this.GetType()); //f.Icon = (Icon)(resources.GetObject("$this.Icon")); DiffControl diffControl = new DiffControl(); diffControl.Dock = DockStyle.Fill; f.Controls.Add(diffControl); bool chkIgnoreCase = false; bool chkIgnoreWhitespace = true; bool chkSupportChangeEditType = false; bool chkXML = false; string strA = filePath; try { TextDiff diff = new TextDiff(HashType.CRC32, chkIgnoreCase, chkIgnoreWhitespace, 0, chkSupportChangeEditType); IList<string> code1, code2; if (chkXML) { code1 = Functions.GetXMLTextLines(strA, WhitespaceHandling.All); code2 = modifiedContent.Replace("\r", "").Split('\n'); } else { code1 = Functions.GetFileTextLines(strA); code2 = modifiedContent.Replace("\r", "").Split('\n'); } EditScript script = diff.Execute(code1, code2); diffControl.SetData(code1, code2, script); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } f.Show(); }
/// <summary> /// Parses a list of browser names to use. /// </summary> /// <param name="names">The names to parse.</param> /// <param name="log">A log for sending errors to.</param> /// <returns>A list of web driver builders.</returns> private static IReadOnlyDictionary <string, Func <IWebDriver> > ParseBrowserNames( IEnumerable <string> names, ILog log) { var browsersToUse = new Dictionary <string, Func <IWebDriver> >(); foreach (var name in names.Distinct()) { if (Drivers.ContainsKey(name)) { browsersToUse[name] = Drivers[name]; } else { // Try to guess what the user meant. var suggestion = NameSuggestion.SuggestName(name, Drivers.Keys); if (suggestion == null) { // Log an error if we couldn't find a reasonable guess. log.Log( new Pixie.LogEntry( Severity.Error, "unknown browser", Quotation.QuoteEvenInBold( "specified browser ", name, " is not a known browser."))); } else { // Give the user a hand otherwise. var diff = Diff.Create(name, suggestion); log.Log( new Pixie.LogEntry( Severity.Error, "unknown browser", Quotation.QuoteEvenInBold( "specified browser ", TextDiff.RenderDeletions(diff), " is not a known browser; did you mean ", TextDiff.RenderInsertions(diff), "?"))); } } } return(browsersToUse); }
private void ImplementInExistingClass(FileDiff response, string file, IEnumerable <string> stubs) { var root = CSharpSyntaxTree.ParseText(File.ReadAllText(file)).GetRoot(); var stepClass = root.DescendantNodes().OfType <ClassDeclarationSyntax>(); var diff = new TextDiff(); if (hasStepClass(stepClass)) { diff = getTextDiff(diff, stepClass, stubs); } else { diff = getTextDiff(diff, root, stubs, file); } response.FilePath = file; response.TextDiffs.Add(diff); }
internal void CreateDiffEditor(IAnkhServiceProvider context, AnkhDiffArgs args) { Context = context; DynamicFactory.CreateEditor(args.BaseFile, this); OnFrameCreated(EventArgs.Empty); Collection <string> A, B; GetFileLines(args.BaseFile, args.MineFile, out A, out B); TextDiff Diff = new TextDiff(HashType.HashCode, false, false); EditScript Script = Diff.Execute(A, B); string strCaptionA = args.BaseTitle ?? Path.GetFileName(args.BaseFile); string strCaptionB = args.MineTitle ?? Path.GetFileName(args.MineFile); diffControl1.SetData(A, B, Script, strCaptionA, strCaptionB); }
private void ImplementInNewClass(FileDiff fileDiff, string filepath, IEnumerable <string> stubs) { var className = FileHelper.GetClassName(filepath); var content = GetNewClassContent(className, stubs); var diff = new TextDiff { Span = new Span { Start = 0, StartChar = 0, End = 0, EndChar = 0 }, Content = content }; fileDiff.TextDiffs.Add(diff); fileDiff.FilePath = filepath; }
private void schemaView_OnSelectItem(string ObjectFullName) { txtNewObject.IsReadOnly = false; txtOldObject.IsReadOnly = false; txtNewObject.Text = string.Empty; txtOldObject.Text = string.Empty; Database database = (Database)schemaView.DatabaseSource; if (database.Find(ObjectFullName) != null) { if (database.Find(ObjectFullName).Status != Enums.ObjectStatusType.DropStatus) { txtNewObject.Text = database.Find(ObjectFullName).ToSql(); } } database = (Database)schemaView.DatabaseDestination; if (database.Find(ObjectFullName) != null) { if (database.Find(ObjectFullName).Status != Enums.ObjectStatusType.CreateStatus) { txtOldObject.Text = database.Find(ObjectFullName).ToSql(); } } txtNewObject.IsReadOnly = true; txtOldObject.IsReadOnly = true; //Make sure we have a new and an old object before we try and do a diff. if (!string.IsNullOrEmpty(txtNewObject.Text) && !string.IsNullOrEmpty(txtOldObject.Text)) { TextDiff textDiff = new TextDiff(HashType.HashCode, true, true); //Make 2 lists, containing every line from the old and the new sql queries List <string> oldLines, newLines; newLines = new List <string>(txtNewObject.Text.Split('\n')); oldLines = new List <string>(txtOldObject.Text.Split('\n')); EditScript editScript = textDiff.Execute(newLines, oldLines); diffControl.SetData(newLines, oldLines, editScript, "New", "Old"); } }
private static void ImplementInExistingClass(FileDiff response, string file, IEnumerable <string> stubs) { var root = CSharpSyntaxTree.ParseText(File.ReadAllText(file)).GetRoot(); var stepMethods = root.DescendantNodes().OfType <MethodDeclarationSyntax>(); var lastMethodEndPosition = stepMethods.Last().GetLocation().GetLineSpan().EndLinePosition; var diff = new TextDiff { Span = new Span { Start = lastMethodEndPosition.Line, StartChar = lastMethodEndPosition.Character + 1, End = lastMethodEndPosition.Line, EndChar = lastMethodEndPosition.Character + 1 }, Content = $"{Environment.NewLine}{string.Join(Environment.NewLine, stubs)}" }; response.FilePath = file; response.TextDiffs.Add(diff); }
private void btnCompare_Click(object sender, EventArgs e) { Encoding enc = null; IList<string> code1 = txtUrl1.Text.DownloadPage(ref enc).Replace("\r", "").Split('\n'); IList<string> code2 = txtUrl2.Text.DownloadPage(ref enc).Replace("\r", "").Split('\n'); TextDiff diff = new TextDiff(HashType.CRC32, true, true); EditScript script = diff.Execute(code1, code2); List<MyEdit> diffList = new List<MyEdit>(); for (int editIndex = 0; editIndex < script.Count; editIndex += 2) { Edit edit = script[editIndex]; string strA = ""; for (int i = edit.StartA; i < edit.StartA + edit.Length; i++) strA += code1[i] + Environment.NewLine; string strB = ""; for (int i = edit.StartB; i < edit.StartB + edit.Length; i++) strB += code2[i] + Environment.NewLine; diffList.Add(new MyEdit { Left = strA, Right = strB, Type = edit.Type }); } List<MyEdit> mySubList = getLongestNItems(diffList, 5); DiffControl diffControl = new DiffControl(); diffControl.Dock = DockStyle.Fill; panel.Controls.Clear(); panel.Controls.Add(diffControl); diffControl.SetData(code1, code2, script);//, strA, strB); }
private void DisplayDiff(TextDiff source, TextDiff destination, ArrayList DiffLines) { CleanResultTextEditors(); int cnt = 1; int i; try { _isDisplayingDiff = true; SourceDoc.ReadOnly = false; DestDoc.ReadOnly = false; SourceTextArea.BeginUpdate(); DestTextArea.BeginUpdate(); foreach (DiffResultSpan drs in DiffLines) { switch (drs.Status) { case DiffResultSpanStatus.DeleteSource: for (i = 0; i < drs.Length; i++) { var line = ((DiffTextLine)source.GetByIndex(drs.SourceIndex + i)).Line + "\n"; SourceTextArea.InsertString(line); //SourceDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.MistyRose, false); var segment = SourceDoc.GetLineSegment(cnt - 1); if (segment.Length > 0) { var marker = new TextMarker(segment.Offset, segment.Length, TextMarkerType.SolidBlock, Color.Green, Color.White); SourceDoc.MarkerStrategy.AddMarker(marker); } DestTextArea.InsertString("\n"); DestDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.LightGray, false); cnt++; } break; case DiffResultSpanStatus.NoChange: for (i = 0; i < drs.Length; i++) { var bgColor = SourceDoc.HighlightingStrategy.GetColorFor("Default"); SourceTextArea.InsertString(((DiffTextLine)source.GetByIndex(drs.SourceIndex + i)).Line + "\n"); //SourceDoc.CustomLineManager.AddCustomLine(cnt - 1, bgColor != null ? bgColor.BackgroundColor : Color.White, false); bgColor = DestDoc.HighlightingStrategy.GetColorFor("Default"); DestTextArea.InsertString(((DiffTextLine)destination.GetByIndex(drs.DestIndex + i)).Line + "\n"); //DestDoc.CustomLineManager.AddCustomLine(cnt - 1, bgColor != null ? bgColor.BackgroundColor : Color.White, false); cnt++; } break; case DiffResultSpanStatus.AddDestination: for (i = 0; i < drs.Length; i++) { SourceTextArea.InsertString("\n"); SourceDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.LightGray, false); var line = ((DiffTextLine)destination.GetByIndex(drs.DestIndex + i)).Line + "\n"; DestTextArea.InsertString(line); var segment = DestDoc.GetLineSegment(cnt - 1); if (segment.Length > 0) { var marker = new TextMarker(segment.Offset, segment.Length, TextMarkerType.SolidBlock, Color.Red, Color.White); DestDoc.MarkerStrategy.AddMarker(marker); } //DestDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.LightGreen, false); cnt++; } break; case DiffResultSpanStatus.Replace: for (i = 0; i < drs.Length; i++) { var line = ((DiffTextLine)source.GetByIndex(drs.SourceIndex + i)).Line + "\n"; SourceTextArea.InsertString(line); //SourceDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.MistyRose, false); var segment = SourceDoc.GetLineSegment(cnt - 1); if (segment.Length > 0) { var marker = new TextMarker(segment.Offset, segment.Length, TextMarkerType.SolidBlock, Color.Gold, Color.Black); SourceDoc.MarkerStrategy.AddMarker(marker); } line = ((DiffTextLine)destination.GetByIndex(drs.DestIndex + i)).Line + "\n"; DestTextArea.InsertString(line); segment = DestDoc.GetLineSegment(cnt - 1); if (segment.Length > 0) { var marker = new TextMarker(segment.Offset, segment.Length, TextMarkerType.SolidBlock, Color.Gold, Color.Black); DestDoc.MarkerStrategy.AddMarker(marker); } //DestDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.LightGreen, false); cnt++; } break; } } } finally { SourceTextArea.EndUpdate(); DestTextArea.EndUpdate(); SourceTextArea.ScrollTo(0); DestTextArea.ScrollTo(0); _isDisplayingDiff = false; SourceDoc.ReadOnly = true; DestDoc.ReadOnly = true; } }
private void CheckNativeDb() { if (Config.SubscribedChannels.Count == 0) { return; } var headerFile = DownloadHeader(); if (!File.Exists("natives.h")) { File.WriteAllText("natives.h", headerFile); return; } var existingFileLines = new List <string>(File.ReadAllLines("natives.h")); File.WriteAllText("natives.h", headerFile); var headerFileLines = new List <string>(headerFile.Split('\n')); var diff = new TextDiff(HashType.Crc32, false, true); var changes = diff.Execute(existingFileLines, headerFileLines); int changeCount = 0; var outputText = "```diff\n"; var lastEditType = EditType.None; foreach (var change in changes) { if (change.EditType == EditType.Change) { if (existingFileLines[change.StartA].StartsWith("// Generated ")) { continue; } if (lastEditType != EditType.Change) { outputText += "*** Changed:\n"; lastEditType = EditType.Change; } changeCount += change.Length; for (int i = 0; i < change.Length; i++) { outputText += "- " + CleanLine(existingFileLines[change.StartA + i]) + "\n"; outputText += "+ " + CleanLine(headerFileLines[change.StartB + i]) + "\n\n"; } } if (change.EditType == EditType.Insert) { for (int i = 0; i < change.Length; i++) { var line = headerFileLines[change.StartA + i]; if (line == "") { continue; } if (lastEditType != EditType.Insert) { outputText += "\n*** Added:\n"; lastEditType = EditType.Insert; } changeCount++; outputText += "+ " + CleanLine(line) + "\n"; } } if (change.EditType == EditType.Delete) { for (int i = 0; i < change.Length; i++) { var line = existingFileLines[change.StartA + i]; if (line == "") { continue; } if (lastEditType != EditType.Delete) { outputText += "\n*** Removed:\n"; lastEditType = EditType.Delete; } changeCount++; outputText += "- " + CleanLine(line) + "\n"; } } } outputText += "```"; Logging.Info("NativeDb had {0} changes.", changeCount); if (changeCount > 0) { foreach (var id in Config.SubscribedChannels) { var channel = Discord.GetChannel(id); if (channel == null) { continue; } channel.SendMessage("`[" + DateTime.Now.ToString("HH:mm:ss") + "] [NATIVES]` " + changeCount + " change(s):\n" + outputText); } } }
private void btnDiff_Click(object sender, EventArgs e) { GeneratedCode gc = (GeneratedCode)tabControl1.SelectedTab.Tag; Form f = new Form(); f.WindowState = FormWindowState.Maximized; f.Text = "[Existing File] vs. [Generated Code]"; ComponentResourceManager resources = new ComponentResourceManager(this.GetType()); f.Icon = (Icon)(resources.GetObject("$this.Icon")); DiffControl diffControl = new DiffControl(); diffControl.Dock = DockStyle.Fill; f.Controls.Add(diffControl); bool chkIgnoreCase = false; bool chkIgnoreWhitespace = true; bool chkSupportChangeEditType = false; bool chkXML = false; string strA = gc.Path; try { //edtTextOne.Text = strA; //edtTextTwo.Text = strB; TextDiff diff = new TextDiff(HashType.CRC32, chkIgnoreCase, chkIgnoreWhitespace, 0, chkSupportChangeEditType); IList<string> code1, code2; if (chkXML) { code1 = Functions.GetXMLTextLines(strA, WhitespaceHandling.All); code2 = gc.Code.Replace("\r","").Split('\n');//Functions.GetXMLTextLines(strB, eWS); } else { code1 = Functions.GetFileTextLines(strA); code2 = gc.Code.Replace("\r","").Split('\n');//Functions.GetFileTextLines(strB); } EditScript script = diff.Execute(code1, code2); diffControl.SetData(code1, code2, script);//, strA, strB); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } f.Show(); }
public MyersDiffOutputList() { diffengine = new TextDiff(new MyersDiff(), new HTMLDiffOutputGenerator()); }
public void MatchTwoLineTests() { bool ignoreCase = true; bool ignoreWhiteSpace = true; int leadingCharactersToIgnore = 0; bool supportChangeEditType = false; var txtDiff = new TextDiff(HashType.HashCode, ignoreCase, ignoreWhiteSpace, leadingCharactersToIgnore, supportChangeEditType); var editScript = txtDiff.Execute(new List <string>(), new List <string>()); Assert.IsTrue(editScript.TotalEditLength == 0); Assert.IsTrue(editScript.Count == editScript.TotalEditLength); editScript = null; editScript = txtDiff.Execute(new List <string>(), new List <string> { "abc", "ccc" }); Assert.IsTrue(editScript.TotalEditLength == 2); Assert.IsTrue(editScript.Count != editScript.TotalEditLength); Assert.IsTrue(editScript.Count == 1); Assert.IsTrue(editScript[0].EditType == EditType.Insert); Assert.IsTrue(editScript[0].Length == 2); Assert.IsTrue(editScript[0].StartA == 0 && editScript[0].StartB == 0); editScript = null; editScript = txtDiff.Execute(new List <string> { "abc", "ccc" }, new List <string>() { }); Assert.IsTrue(editScript.TotalEditLength == 2); Assert.IsTrue(editScript.Count != editScript.TotalEditLength); Assert.IsTrue(editScript.Count == 1); Assert.IsTrue(editScript[0].EditType == EditType.Delete); Assert.IsTrue(editScript[0].Length == 2); Assert.IsTrue(editScript[0].StartA == 0 && editScript[0].StartB == 0); editScript = null; editScript = txtDiff.Execute(new List <string> { "abc" }, new List <string> { "abc", "ccc" }); Assert.IsTrue(editScript.TotalEditLength == 1); Assert.IsTrue(editScript.Count == editScript.TotalEditLength); Assert.IsTrue(editScript[0].EditType == EditType.Insert); Assert.IsTrue(editScript[0].Length == 1); Assert.IsTrue(editScript[0].StartA == 1 && editScript[0].StartB == 1); editScript = null; editScript = txtDiff.Execute(new List <string> { "abc", "ccc" }, new List <string> { "abc" }); Assert.IsTrue(editScript.TotalEditLength == 1); Assert.IsTrue(editScript.Count == editScript.TotalEditLength); Assert.IsTrue(editScript[0].EditType == EditType.Delete); Assert.IsTrue(editScript[0].Length == 1); Assert.IsTrue(editScript[0].StartA == 1 && editScript[0].StartB == 1); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX editScript = null; editScript = txtDiff.Execute(new List <string> { "abc", "ccc" }, new List <string> { "abc", "ccc" }); Assert.IsTrue(editScript.TotalEditLength == 0); Assert.IsTrue(editScript.Count == editScript.TotalEditLength); editScript = null; editScript = txtDiff.Execute(new List <string> { "abc", "ccc" }, new List <string> { "abc", "cxc" }); Assert.IsTrue(editScript.TotalEditLength == 2); Assert.IsTrue(editScript.Count == editScript.TotalEditLength); Assert.IsTrue(editScript[0].EditType == EditType.Delete); Assert.IsTrue(editScript[0].Length == 1); Assert.IsTrue(editScript[0].StartA == 1 && editScript[0].StartB == 1); Assert.IsTrue(editScript[1].EditType == EditType.Insert); Assert.IsTrue(editScript[1].Length == 1); Assert.IsTrue(editScript[1].StartA == 1 && editScript[1].StartB == 1); editScript = null; editScript = txtDiff.Execute(new List <string> { "abc", "ccc" }, new List <string> { "acc", "ccc" }); Assert.IsTrue(editScript.TotalEditLength == 2); Assert.IsTrue(editScript.Count == editScript.TotalEditLength); Assert.IsTrue(editScript[0].EditType == EditType.Delete); Assert.IsTrue(editScript[0].Length == 1); Assert.IsTrue(editScript[0].StartA == 0 && editScript[0].StartB == 0); Assert.IsTrue(editScript[1].EditType == EditType.Insert); Assert.IsTrue(editScript[1].Length == 1); Assert.IsTrue(editScript[1].StartA == 0 && editScript[1].StartB == 0); editScript = null; editScript = txtDiff.Execute(new List <string> { "abc", "ccc" }, new List <string> { "acc", "cxc" }); Assert.IsTrue(editScript.TotalEditLength == 4); Assert.IsTrue(editScript.Count != editScript.TotalEditLength); Assert.IsTrue(editScript.Count == 2); Assert.IsTrue(editScript[0].EditType == EditType.Delete); Assert.IsTrue(editScript[0].Length == 2); Assert.IsTrue(editScript[0].StartA == 0 && editScript[0].StartB == 0); Assert.IsTrue(editScript[1].EditType == EditType.Insert); Assert.IsTrue(editScript[1].Length == 2); Assert.IsTrue(editScript[1].StartA == 0 && editScript[1].StartB == 0); }
private void Comparer(XElement fromDS, XElement toDS, bool equal = false) { string from = fromDS.ToString(); string to = toDS.ToString(); XmlDiff diff = new XmlDiff(); diff.IgnoreChildOrder = true; diff.IgnoreComments = true; diff.IgnoreDtd = true; diff.IgnoreNamespaces = true; diff.IgnorePI = true; diff.IgnorePrefixes = true; diff.IgnoreWhitespace = true; diff.IgnoreXmlDecl = true; StringWriter diffgramString = new StringWriter(); XmlTextWriter diffgramXml = new XmlTextWriter(diffgramString); bool diffBool = diff.Compare(new XmlTextReader(new StringReader(from)), new XmlTextReader(new StringReader(to)), diffgramXml); IList <string> linesFrom = GetLines(from);; IList <string> linesTo = GetLines(to); TextDiff Diff = new TextDiff(HashType.Crc32, true, true); var es = Diff.Execute(linesFrom, linesTo); dc.SetData(linesFrom, linesTo, es, $"{(equal ? "Data Sent To:":"Returned From:")} {(cmbFrom.SelectedItem as Methods).Method}", $"{(equal ?"Data Returned From:":"Data Sent To:")}{(cmdTo.SelectedItem as Methods).Method}"); var dic = GenerateDiffCode(fromDS.Parent, XElement.Load(new StringReader(diffgramString.ToString()))); bool first = true; StringBuilder sbOrig = new StringBuilder(); sbOrig.AppendLine($"//Data Returned from Prior Method{Environment.NewLine}"); sbOrig.AppendLine("//Note data type of each field not known maye not be a string allow the compiler to assist"); StringBuilder sbChanged = new StringBuilder(); sbChanged.AppendLine($"//Data Changed and Sent to the Selected Method {Environment.NewLine}"); sbChanged.AppendLine("//Note data type of each field not known maye not be a string allow the compiler to assist"); if (!equal) { foreach (var x in dic) { string[] ds = x.Key.GetXPath().Split('/'); bool found = false; string dataSet = ""; string dataTable = ""; string field = ""; int dsIdx = -1; foreach (string s in ds) { dsIdx++; if (s.Contains("DataSet")) { found = true; break; } } if (found) { if (first) { dataSet = ds[dsIdx].Substring(0, ds[dsIdx].IndexOf("[")); sbOrig.AppendLine($"{dataSet} ds = new {dataSet}();"); sbChanged.AppendLine($"{dataSet} ds = new {dataSet}();"); first = false; } dataTable = ds[++dsIdx].Substring(0, ds[dsIdx].Length); //TODO: Josh fix this line to subtract 1 from index; sbOrig.Append($"ds.{dataTable}"); sbChanged.Append($"ds.{dataTable}"); field = ds[++dsIdx].Substring(0, ds[dsIdx].IndexOf("[")); sbOrig.Append($".{field} = "); sbChanged.Append($".{field} = "); sbOrig.AppendLine($"\"{x.Key.Value};\""); sbChanged.AppendLine($"\"{x.Value}\";"); } } } TextArea1.Text = sbOrig.ToString(); TextArea2.Text = sbChanged.ToString(); }
private void schemaView_OnSelectItem(string ObjectFullName) { txtNewObject.IsReadOnly = false; txtOldObject.IsReadOnly = false; txtNewObject.Text = string.Empty; txtOldObject.Text = string.Empty; Database database = (Database)schemaView.DatabaseSource; if (database.Find(ObjectFullName) != null) { if (database.Find(ObjectFullName).Status != Enums.ObjectStatusType.DropStatus) txtNewObject.Text = database.Find(ObjectFullName).ToSql(); } database = (Database)schemaView.DatabaseDestination; if (database.Find(ObjectFullName) != null) { if (database.Find(ObjectFullName).Status != Enums.ObjectStatusType.CreateStatus) txtOldObject.Text = database.Find(ObjectFullName).ToSql(); } txtNewObject.IsReadOnly = true; txtOldObject.IsReadOnly = true; //Make sure we have a new and an old object before we try and do a diff. if (!string.IsNullOrEmpty(txtNewObject.Text) && !string.IsNullOrEmpty(txtOldObject.Text)) { TextDiff textDiff = new TextDiff(HashType.HashCode, true, true); //Make 2 lists, containing every line from the old and the new sql queries List<string> oldLines, newLines; newLines = new List<string>(txtNewObject.Text.Split('\n')); oldLines = new List<string>(txtOldObject.Text.Split('\n')); EditScript editScript = textDiff.Execute(newLines, oldLines); diffControl.SetData(newLines, oldLines, editScript, "New", "Old"); } }
static void Main(string[] args) { //TextDiff diffobj = new TextDiff(new MyersDiff(), new HTMLDiffOutputGenerator("span", "style", "color:#003300;background-color:#ccff66;","color:#990000;background-color:#ffcc99;text-decoration:line-through;","")); //TextDiff diffobj = new TextDiff(new MyersDiff(), new HTMLDiffOutputGenerator("span", "class", "newText","deletedText","")); TextDiff diffobj = new TextDiff(new MyersDiff(), new MarkdownDiffOutputGenerator()); string oldText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r\nMaecenas luctus ipsum sit amet turpis pulvinar, et consequat magna tincidunt.\r\nUt tristique sem vitae justo elementum, et fermentum arcu elementum.\r\nDonec blandit facilisis vulputate. Maecenas eu elit ut tortor volutpat condimentum.\r\nPhasellus faucibus vehicula turpis eu pharetra. In imperdiet iaculis cursus."; string newText = "Lorem ipsum dolor sit amet, consectetur adiafeeing elit.\r\nMaecenas sit amet turpis pulvinar, et consequat magna tincidunt.\r\nUt tristique sem vitae justo elementum, et free arcu elementum.\r\nDwfvwc blandit facilisis vulputate. Maecenas eu elit ut tortor volutpat condimentum.\r\nPhasellus dotnet vehicula turpis eu pharetra. In imperdiet iaculis cursus chieown."; string output = diffobj.GenerateDiffOutput("oldText", "newText"); if (true) { oldText = "The quick brown fox"; output = ""; //Equal System.Console.WriteLine("#1 Equal test"); newText = "The quick brown fox"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The quick brown fox"); OutputPatternMatch(diffobj.InnerList, "E"); output += Environment.NewLine; //Add at start System.Console.WriteLine("#2 Add at start"); newText = "Once The quick brown fox"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "Once ", "The quick brown fox"); OutputPatternMatch(diffobj.InnerList, "AE"); output += Environment.NewLine; //Remove at start System.Console.WriteLine("#3 Remove at start"); newText = "quick brown fox"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The ", "quick brown fox"); OutputPatternMatch(diffobj.InnerList, "RE"); output += Environment.NewLine; //Add at middle System.Console.WriteLine("#4 Add at middle"); newText = "The quick agile brown fox"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The quick ", "agile ", "brown fox"); OutputPatternMatch(diffobj.InnerList, "EAE"); output += Environment.NewLine; //Remove at middle System.Console.WriteLine("#5 Remove at middle"); newText = "The quick fox"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The quick ", "brown ", "fox"); OutputPatternMatch(diffobj.InnerList, "ERE"); output += Environment.NewLine; //Add at end System.Console.WriteLine("#6 Add at end"); newText = "The quick brown fox jumped"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The quick brown fox", " jumped"); OutputPatternMatch(diffobj.InnerList, "EA"); output += Environment.NewLine; //Remove at end System.Console.WriteLine("#7 Remove at end"); newText = "The quick brown"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The quick brown", " fox"); OutputPatternMatch(diffobj.InnerList, "ER"); output += Environment.NewLine; //Update at start System.Console.WriteLine("#8 Update at start"); newText = "A quick brown fox"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The", "A", " quick brown fox"); OutputPatternMatch(diffobj.InnerList, "RAE"); output += Environment.NewLine; //Update at middle System.Console.WriteLine("#9 Update at middle"); newText = "The quick blue fox"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The quick b", "rown", "lue", " fox"); OutputPatternMatch(diffobj.InnerList, "ERAE"); output += Environment.NewLine; //Update at end System.Console.WriteLine("#10 Update at end"); newText = "The quick brown cat"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The quick brown ", "fox", "cat"); OutputPatternMatch(diffobj.InnerList, "ERA"); output += Environment.NewLine; //Multiple add System.Console.WriteLine("#11 Multiple add"); newText = "The quick agile brown fox jumped"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The quick ", "agile ", "brown fox", " jumped"); OutputPatternMatch(diffobj.InnerList, "EAEA"); output += Environment.NewLine; //Multiple remove System.Console.WriteLine("#12 Multiple remove"); newText = "quick fox"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The ", "quick", " brown", " fox"); OutputPatternMatch(diffobj.InnerList, "RERE"); output += Environment.NewLine; //Multiple updates System.Console.WriteLine("#13 Multiple updates"); newText = "The slow brown cat"; output += diffobj.GenerateDiffOutput(oldText, newText); PrintList(diffobj.InnerList, oldText, newText); OutputTextMatch(diffobj.InnerList, "The ", "quick", "slow", " brown ", "fox", "cat"); OutputPatternMatch(diffobj.InnerList, "ERAERA"); output += Environment.NewLine; } System.Console.WriteLine(output); Console.ReadLine(); }