public void Setup() { var source = Path.Combine(this.sampleDataPath, "SonarSource.txt"); var destination = Path.Combine(this.sampleDataPath, "LocalSource.txt"); this.sLf = new DiffListTextFile(source); this.dLf = new DiffListTextFile(destination); this.de = new DiffEngine(); this.de.ProcessDiff(this.sLf, this.dLf, DiffEngineLevel.SlowPerfect); this.rep = this.de.DiffReport(); }
private void DisplayTextDiff(string sourceFile, string destFile) { try { DiffListTextFile sLF = new DiffListTextFile(sourceFile); DiffListTextFile dLF = new DiffListTextFile(destFile); Engine diffEngine = new Engine(); double time = diffEngine.ProcessDiff(sLF, dLF); ArrayList report = diffEngine.DiffReport(); ResultsWindow resultsWindow = new ResultsWindow(sLF, dLF, report, time); resultsWindow.Show(); } catch (Exception ex) { string temp = string.Format("{0}{1}{1}===STACKTRACE==={1}{2}", ex.Message, Environment.NewLine, ex.StackTrace); MessageBox.Show(temp, "Compare Error"); throw; } }
/// <summary> /// The get source diff from strings. /// </summary> /// <param name="source"> /// The source. /// </param> /// <param name="destination"> /// The destination. /// </param> /// <param name="level"> /// The level. /// </param> /// <returns> /// The <see cref="ArrayList"/>. /// </returns> public static ArrayList GetSourceDiffFromStrings(string source, string destination, DiffEngineLevel level = DiffEngineLevel.SlowPerfect) { var sourceseparator = "\n"; if (source.Contains("\r\n")) { sourceseparator = "\r\n"; } var destinationsepartor = "\n"; if (destination.Contains("\r\n")) { destinationsepartor = "\r\n"; } var sLf = new DiffListTextFile(source, sourceseparator); var dLf = new DiffListTextFile(destination, destinationsepartor); var de = new DiffEngine(); de.ProcessDiff(sLf, dLf, level); return(de.DiffReport()); }
public ResultsWindow(DiffListTextFile source, DiffListTextFile destination, ArrayList diffLines, double seconds) { InitializeComponent(); Results_Header.Content = string.Format("File Diffs Calculated in {0} seconds.", TimeSpan.FromSeconds(seconds)); int count = 1; int i; foreach (DiffResultSpan drs in diffLines) { switch (drs.Status) { case DiffResultSpanStatus.DeleteSource: for (i = 0; i < drs.Length; i++) { SourceListView.Items.Add(new LineItem { Line = count, Text = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Status = "Remove" }); DestinationListView.Items.Add(new LineItem { Line = count, Text = " ", Status = "Ignore" }); count++; } break; case DiffResultSpanStatus.NoChange: for (i = 0; i < drs.Length; i++) { SourceListView.Items.Add(new LineItem { Line = count, Text = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Status = "NoChange" }); DestinationListView.Items.Add(new LineItem { Line = count, Text = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Status = "NoChange" }); count++; } break; case DiffResultSpanStatus.AddDestination: for (i = 0; i < drs.Length; i++) { SourceListView.Items.Add(new LineItem { Line = count, Text = " ", Status = "Ignore" }); DestinationListView.Items.Add(new LineItem { Line = count, Text = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Status = "Include" }); count++; } break; case DiffResultSpanStatus.Replace: for (i = 0; i < drs.Length; i++) { SourceListView.Items.Add(new LineItem { Line = count, Text = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Status = "Remove" }); DestinationListView.Items.Add(new LineItem { Line = count, Text = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Status = "Include" }); count++; } break; } } }