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(); }
/// <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(); }
/// <summary> /// Initializes a new instance of the <see cref="Results"/> class. /// </summary> /// <param name="source"> /// The source. /// </param> /// <param name="destination"> /// The destination. /// </param> /// <param name="diffLines"> /// The diff lines. /// </param> /// <param name="seconds"> /// The seconds. /// </param> public Results(DiffListTextFile source, DiffListTextFile destination, ArrayList diffLines, double seconds) { this.InitializeComponent(); this.Text = string.Format("Results: {0} secs.", seconds.ToString("#0.00")); var cnt = 1; try { foreach (DiffResultSpan drs in diffLines) { ListViewItem lviS; ListViewItem lviD; int i; switch (drs.Status) { case DiffResultSpanStatus.DeleteSource: for (i = 0; i < drs.Length; i++) { lviS = new ListViewItem(cnt.ToString("00000")); lviD = new ListViewItem(cnt.ToString("00000")); lviS.BackColor = Color.Red; lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line); lviD.BackColor = Color.LightGray; lviD.SubItems.Add(string.Empty); this.lvsource.Items.Add(lviS); this.lvdestination.Items.Add(lviD); cnt++; } break; case DiffResultSpanStatus.NoChange: for (i = 0; i < drs.Length; i++) { lviS = new ListViewItem(cnt.ToString("00000")); lviD = new ListViewItem(cnt.ToString("00000")); lviS.BackColor = Color.White; lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line); lviD.BackColor = Color.White; lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line); this.lvsource.Items.Add(lviS); this.lvdestination.Items.Add(lviD); cnt++; } break; case DiffResultSpanStatus.AddDestination: for (i = 0; i < drs.Length; i++) { lviS = new ListViewItem(cnt.ToString("00000")); lviD = new ListViewItem(cnt.ToString("00000")); lviS.BackColor = Color.LightGray; lviS.SubItems.Add(string.Empty); lviD.BackColor = Color.LightGreen; lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line); this.lvsource.Items.Add(lviS); this.lvdestination.Items.Add(lviD); cnt++; } break; case DiffResultSpanStatus.Replace: for (i = 0; i < drs.Length; i++) { lviS = new ListViewItem(cnt.ToString("00000")); lviD = new ListViewItem(cnt.ToString("00000")); lviS.BackColor = Color.Red; lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line); lviD.BackColor = Color.LightGreen; lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line); this.lvsource.Items.Add(lviS); this.lvdestination.Items.Add(lviD); cnt++; } break; } } } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); } }
/// <summary> /// The get difference report. /// </summary> /// <param name="filePath"> /// The file Path. /// </param> /// <param name="sourceInServer"> /// The in server source. /// </param> /// <param name="displayWindow"> /// The display Window. /// </param> /// <returns> /// The <see cref="ArrayList"/>. /// </returns> public static ArrayList GetDifferenceReport(string filePath, string sourceInServer, bool displayWindow) { var sLf = new DiffListTextFile(filePath); var dLf = new DiffListTextFile(sourceInServer, "\r\n"); var de = new DiffEngine(); de.ProcessDiff(dLf, sLf, DiffEngineLevel.SlowPerfect); if (!displayWindow) { return de.DiffReport(); } using (var win = new Results(sLf, dLf, de.DiffReport(), 0)) { win.ShowDialog(); } return de.DiffReport(); }