private void TextDiff(string sFile, string dFile) { this.Cursor = Cursors.WaitCursor; DiffList_TextFile sLF = null; DiffList_TextFile dLF = null; try { sLF = new DiffList_TextFile(sFile); dLF = new DiffList_TextFile(dFile); } catch (Exception ex) { this.Cursor = Cursors.Default; MessageBox.Show(ex.Message, "File Error"); return; } try { double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF, dLF, _level); ArrayList rep = de.DiffReport(); Results dlg = new Results(sLF, dLF, rep, time); dlg.ShowDialog(); dlg.Dispose(); } catch (Exception ex) { this.Cursor = Cursors.Default; string tmp = string.Format("{0}{1}{1}***STACK***{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace); MessageBox.Show(tmp, "Compare Error"); return; } this.Cursor = Cursors.Default; }
private void TextDiff(string sFile, string dFile) { this.Cursor = Cursors.Wait; DiffList_TextFile sLF = null; DiffList_TextFile dLF = null; try { sLF = new DiffList_TextFile(sFile); dLF = new DiffList_TextFile(dFile); } catch (Exception ex) { this.Cursor = Cursors.Arrow; MessageBox.Show(ex.Message, "File Error"); return; } try { double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF, dLF, DiffEngineLevel.SlowPerfect); ArrayList rep = de.DiffReport(); Results dlg = new Results(sLF, dLF, rep, time); try { this.Hide(); dlg.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Unexpected Error!", MessageBoxButton.OKCancel, MessageBoxImage.Error, MessageBoxResult.None); dlg.Close(); } finally { this.Show(); } } catch (Exception ex) { this.Cursor = Cursors.Arrow; string tmp = string.Format("{0}{1}{1}***STACK***{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace); MessageBox.Show(tmp, "Compare Error"); return; } this.Cursor = Cursors.Arrow; }
private static ArrayList GetFileChanges(string source, string destinationPath) { DiffList_TextFile sourceFile = new DiffList_TextFile(source.Split('\n')); DiffList_TextFile destinationFile = new DiffList_TextFile(destinationPath); DiffEngine diffEngine = new DiffEngine(); diffEngine.ProcessDiff(sourceFile, destinationFile, DiffEngineLevel.FastImperfect); ArrayList differenceList = diffEngine.DiffReport(); return(differenceList); }
private void TextDiff(string sFile, string dFile) { DiffList_TextFile sLF = null; DiffList_TextFile dLF = null; try { sLF = new DiffList_TextFile(sFile); dLF = new DiffList_TextFile(dFile); } catch (Exception ex) { MessageBox.Show(ex.Message, "File Error"); return; } try { double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF, dLF, DiffEngineLevel.FastImperfect); ArrayList rep = de.DiffReport(); string[] res = getResults(dLF, rep); if (res != null) { string[] filesplit = dFile.Split('\\'); string filename = filesplit.Last(); File.WriteAllLines(folderPath + "\\SetItUp_Registry\\" + filename, res); } } catch (Exception ex) { string tmp = string.Format("{0}{1}{1}***STACK***{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace); MessageBox.Show(tmp, "Compare Error"); return; } }
public static string CompareTextFiles(string sFile, string dFile) { DiffList_TextFile sLF = null; DiffList_TextFile dLF = null; bool IsEqual = true; string reportStr = null; try { sLF = new DiffList_TextFile(sFile); dLF = new DiffList_TextFile(dFile); } catch (Exception ex) { throw new Exception(ex.Message); } try { double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF, dLF, DiffEngineLevel.FastImperfect); ArrayList rep = de.DiffReport(); CompareReport theReports = Results(sLF, dLF, rep, time, out IsEqual); if (!IsEqual) { reportStr = CompareReports(sFile, dFile, theReports); } } catch (Exception ex) { throw new Exception(ex.Message); } return(reportStr); }
/// <summary> /// returns the number of differences /// </summary> /// <param name="sFile"></param> /// <param name="dFile"></param> /// <returns></returns> private int TextDiff(string sFile, string dFile) { this.Cursor = Cursors.WaitCursor; int nChanges = 0; DiffList_TextFile sLF = null; DiffList_TextFile dLF = null; try { sLF = new DiffList_TextFile(sFile); dLF = new DiffList_TextFile(dFile); } catch (Exception ex) { this.Cursor = Cursors.Default; CoreUtilities.NewMessage.Show(ex.Message, "File Error"); return -1; } try { double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF, dLF, _level); ArrayList rep = de.DiffReport(); nChanges = rep.Count; //Results dlg = new Results(sLF, dLF, rep, time); this.DoCompare(sLF, dLF, rep, time); //dlg.ShowDialog(); //dlg.Dispose(); } catch (Exception ex) { this.Cursor = Cursors.Default; string tmp = string.Format("{0}{1}{1}***STACK***{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace); CoreUtilities.NewMessage.Show(tmp, "Compare Error"); return -1; } this.Cursor = Cursors.Default; return nChanges; }
private void DoCompare(DiffList_TextFile source, DiffList_TextFile destination, ArrayList DiffLines, double seconds) { // label1.Text = string.Format("Results: {0} secs.", seconds.ToString("#0.00")); lvSource.Items.Clear(); lvDestination.Items.Clear(); int nChanges = 0; ListViewItem lviS; ListViewItem lviD; int cnt = 1; int i; foreach (DiffResultSpan drs in DiffLines) { 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(""); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; nChanges++; } 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); lvSource.Items.Add(lviS); 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(""); lviD.BackColor = Color.LightGreen; lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; nChanges++; } 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); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; nChanges++; } break; } } statusLabel.Text = String.Format("Changes {0}", nChanges.ToString()); labelWordsNew.Text = String.Format("Words: {0}", destination.words.ToString()); labelWordsOld.Text = String.Format("Words: {0}", source.words.ToString()); }
public Results(DiffList_TextFile source, DiffList_TextFile destination, ArrayList DiffLines, double seconds) { InitializeComponent(); this.Text = string.Format("Results: {0} secs.", seconds.ToString("#0.00")); System.Windows.Forms.ListViewItem lviS; System.Windows.Forms.ListViewItem lviD; int cnt = 1; int i; foreach (DiffResultSpan drs in DiffLines) { switch (drs.Status) { case DiffResultSpanStatus.DeleteSource: for (i = 0; i < drs.Length; i++) { lviS = new System.Windows.Forms.ListViewItem(cnt.ToString("00000")); lviD = new System.Windows.Forms.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(""); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; } break; case DiffResultSpanStatus.NoChange: for (i = 0; i < drs.Length; i++) { lviS = new System.Windows.Forms.ListViewItem(cnt.ToString("00000")); lviD = new System.Windows.Forms.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); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; } break; case DiffResultSpanStatus.AddDestination: for (i = 0; i < drs.Length; i++) { lviS = new System.Windows.Forms.ListViewItem(cnt.ToString("00000")); lviD = new System.Windows.Forms.ListViewItem(cnt.ToString("00000")); lviS.BackColor = Color.LightGray; lviS.SubItems.Add(""); lviD.BackColor = Color.LightGreen; lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; } break; case DiffResultSpanStatus.Replace: for (i = 0; i < drs.Length; i++) { lviS = new System.Windows.Forms.ListViewItem(cnt.ToString("00000")); lviD = new System.Windows.Forms.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); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; } break; } } }
private void CompareFiles(DiffList_TextFile source, DiffList_TextFile destination, ArrayList DiffLines, double seconds) { int cnt = 1; int i; DataGridViewRow oldrow; DataGridViewRow newrow; foreach (DiffResultSpan drs in DiffLines) { switch (drs.Status) { case DiffResultSpanStatus.DeleteSource: for (i = 0; i < drs.Length; i++) { oldrow = (DataGridViewRow)oldGridView.Rows[0].Clone(); oldrow.Cells[0].Value = cnt.ToString("00000"); oldrow.Cells[0].Style.BackColor = Color.LightSlateGray; oldrow.Cells[1].Value = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line; oldrow.Cells[1].Style.BackColor = Color.Red; newrow = (DataGridViewRow)newGridView.Rows[0].Clone(); newrow.Cells[0].Value = cnt.ToString("00000"); oldrow.Cells[0].Style.BackColor = Color.LightSlateGray; newrow.Cells[1].Value = ""; newrow.Cells[1].Style.BackColor = Color.LightGray; oldGridView.Rows.Add(oldrow); newGridView.Rows.Add(newrow); cnt++; } break; case DiffResultSpanStatus.NoChange: for (i = 0; i < drs.Length; i++) { oldrow = (DataGridViewRow)oldGridView.Rows[0].Clone(); oldrow.Cells[0].Value = cnt.ToString("00000"); oldrow.Cells[0].Style.BackColor = Color.LightSlateGray; oldrow.Cells[1].Value = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line; oldrow.Cells[1].Style.BackColor = Color.White; newrow = (DataGridViewRow)newGridView.Rows[0].Clone(); newrow.Cells[0].Value = cnt.ToString("00000"); oldrow.Cells[0].Style.BackColor = Color.LightSlateGray; newrow.Cells[1].Value = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line; newrow.Cells[1].Style.BackColor = Color.White; oldGridView.Rows.Add(oldrow); newGridView.Rows.Add(newrow); cnt++; } break; case DiffResultSpanStatus.AddDestination: for (i = 0; i < drs.Length; i++) { oldrow = (DataGridViewRow)oldGridView.Rows[0].Clone(); oldrow.Cells[0].Value = cnt.ToString("00000"); oldrow.Cells[0].Style.BackColor = Color.LightSlateGray; oldrow.Cells[1].Value = ""; oldrow.Cells[1].Style.BackColor = Color.LightGray; newrow = (DataGridViewRow)newGridView.Rows[0].Clone(); newrow.Cells[0].Value = cnt.ToString("00000"); oldrow.Cells[0].Style.BackColor = Color.LightSlateGray; newrow.Cells[1].Value = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line; newrow.Cells[1].Style.BackColor = Color.LightGreen; oldGridView.Rows.Add(oldrow); newGridView.Rows.Add(newrow); cnt++; } break; case DiffResultSpanStatus.Replace: for (i = 0; i < drs.Length; i++) { oldrow = (DataGridViewRow)oldGridView.Rows[0].Clone(); oldrow.Cells[0].Value = cnt.ToString("00000"); oldrow.Cells[0].Style.BackColor = Color.LightSlateGray; oldrow.Cells[1].Value = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line; oldrow.Cells[1].Style.BackColor = Color.Red; newrow = (DataGridViewRow)newGridView.Rows[0].Clone(); newrow.Cells[0].Value = cnt.ToString("00000"); oldrow.Cells[0].Style.BackColor = Color.LightSlateGray; newrow.Cells[1].Value = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line; newrow.Cells[1].Style.BackColor = Color.LightGreen; oldGridView.Rows.Add(oldrow); newGridView.Rows.Add(newrow); cnt++; } break; } } }
private string[] getResults(DiffList_TextFile destination, ArrayList DiffLines) { int i = 1; //string[] res = new string[5000]; List <string> res = new List <string>(); string lastKey = ""; string tmp; res.Add("Windows Registry Editor Version 5.00"); foreach (DiffResultSpan drs in DiffLines) { switch (drs.Status) { case DiffResultSpanStatus.AddDestination: for (i = 0; i < drs.Length; i++) { tmp = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line.ToString(); if (tmp != "") { if (tmp.StartsWith("[HKEY_")) { lastKey = tmp; } else if (tmp.StartsWith("\"") || tmp.StartsWith("@")) { res.Add(lastKey); res.Add(tmp); res.Add(""); /*j++; * res[j] = lastKey; * j++; * res[j] = tmp; * j++;*/ } else { res.Add(tmp); } } } break; case DiffResultSpanStatus.Replace: for (i = 0; i < drs.Length; i++) { tmp = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line.ToString(); if (tmp != "") { if (tmp.StartsWith("[HKEY_")) { lastKey = tmp; } else if (tmp.StartsWith("\"") || tmp.StartsWith("@")) { res.Add(lastKey); res.Add(tmp); res.Add(""); /*j++; * res[j] = lastKey; * j++; * res[j] = tmp; * j++;*/ } else { res.Add(tmp); } } } break; case DiffResultSpanStatus.NoChange: for (i = 0; i < drs.Length; i++) { tmp = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line.ToString(); if (tmp.StartsWith("[HKEY_")) { lastKey = tmp; } } break; } } if (res.Count == 1) { return(null); } return(res.ToArray()); }
public void Results(DiffList_TextFile source, DiffList_TextFile destination, ArrayList DiffLines, double seconds) { //this.Text = string.Format("Results: {0} secs.", seconds.ToString("#0.00")); ListViewItem lviS; ListViewItem lviD; int cnt = 1; int i; foreach (DiffResultSpan drs in DiffLines) { 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(""); lvSource.Items.Add(lviS); 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); lvSource.Items.Add(lviS); 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(""); lviD.BackColor = Color.LightGreen; lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line); lvSource.Items.Add(lviS); 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); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; } break; } } }
private void PrepareDiff(string[] left, string[] right, List <LineRecord> leftrecs, List <LineRecord> rightrecs) { DiffList_TextFile file1 = new DiffList_TextFile(left); DiffList_TextFile file2 = new DiffList_TextFile(right); DiffEngine engine = new DiffEngine(); engine.ProcessDiff(file1, file2, DiffEngineLevel.SlowPerfect); ArrayList report = engine.DiffReport(); foreach (DiffResultSpan dres in report) { switch (dres.Status) { case DiffResultSpanStatus.NoChange: for (int i = 0; i < dres.Length; i++) { LineRecord lrec = new LineRecord(i + dres.SourceIndex, left[i + dres.SourceIndex]); leftrecs.Add(lrec); LineRecord rrec = new LineRecord(i + dres.DestIndex, right[i + dres.DestIndex]); rightrecs.Add(rrec); } break; case DiffResultSpanStatus.Replace: for (int i = 0; i < dres.Length; i++) { LineRecord lrec = new LineRecord(i + dres.SourceIndex, left[i + dres.SourceIndex]); lrec.BackColor = Color.Khaki; leftrecs.Add(lrec); LineRecord rrec = new LineRecord(i + dres.DestIndex, right[i + dres.DestIndex]); rrec.BackColor = Color.Khaki; rightrecs.Add(rrec); ComputeLineDifferences(lrec, rrec); } break; case DiffResultSpanStatus.DeleteSource: for (int i = 0; i < dres.Length; i++) { LineRecord lrec = new LineRecord(i + dres.SourceIndex, left[i + dres.SourceIndex]); lrec.BackColor = Color.Khaki; leftrecs.Add(lrec); LineRecord rrec = new LineRecord(); rrec.BackColor = Color.LightGray; rightrecs.Add(rrec); } break; case DiffResultSpanStatus.AddDestination: for (int i = 0; i < dres.Length; i++) { LineRecord lrec = new LineRecord(); lrec.BackColor = Color.LightGray; leftrecs.Add(lrec); LineRecord rrec = new LineRecord(i + dres.DestIndex, right[i + dres.DestIndex]); rrec.BackColor = Color.Khaki; rightrecs.Add(rrec); } break; default: break; } // switch } // foreach }
private void lwDatabaseObjects_Click(object sender, EventArgs e) { //MessageBox.Show(lwDatabaseObjects.SelectedItems[0].SubItems[0].Text + "." + lwDatabaseObjects.SelectedItems[0].SubItems[2].Text); try { lvDestination.Items.Clear(); lvSource.Items.Clear(); DataView dwObjectDefinition = new DataView(this.dbOjects, "Type='" + lwDatabaseObjects.SelectedItems[0].SubItems[0].Text + "' AND " + "Name='" + lwDatabaseObjects.SelectedItems[0].SubItems[2].Text + "'", "Name", DataViewRowState.CurrentRows); foreach (DataRowView dr in dwObjectDefinition) { //ObjectDefinition1 string objDef1 = dr["ObjectDefinition1"].ToString(); string objDef2 = dr["ObjectDefinition2"].ToString(); DiffList_TextFile sLF = null; DiffList_TextFile dLF = null; sLF = new DiffList_TextFile(objDef1); dLF = new DiffList_TextFile(objDef2); double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF, dLF, DiffEngineLevel.SlowPerfect); ArrayList rep = de.DiffReport(); ListViewItem lviS; ListViewItem lviD; int cnt = 1; int i; foreach (DiffResultSpan drs in rep) { 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)sLF.GetByIndex(drs.SourceIndex + i)).Line); lviD.BackColor = Color.LightGray; lviD.SubItems.Add(""); lvSource.Items.Add(lviS); 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)sLF.GetByIndex(drs.SourceIndex + i)).Line); lviD.BackColor = Color.White; lviD.SubItems.Add(((TextLine)dLF.GetByIndex(drs.DestIndex + i)).Line); lvSource.Items.Add(lviS); 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(""); lviD.BackColor = Color.LightGreen; lviD.SubItems.Add(((TextLine)dLF.GetByIndex(drs.DestIndex + i)).Line); lvSource.Items.Add(lviS); 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)sLF.GetByIndex(drs.SourceIndex + i)).Line); lviD.BackColor = Color.LightGreen; lviD.SubItems.Add(((TextLine)dLF.GetByIndex(drs.DestIndex + i)).Line); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; } break; } } /* * lvSource.Items.Clear(); * using (StringReader sr = new StringReader(objDef1)) * { * string line; * while ((line = sr.ReadLine()) != null) * { * lvSource.Items.Add(line); * } * } * lvDestination.Items.Clear(); * using (StringReader sr = new StringReader(objDef2)) * { * string line; * while ((line = sr.ReadLine()) != null) * { * this.lvDestination.Items.Add(line); * } * }*/ } } catch (Exception err) { string error = err.Message; } }
private static CompareReport Results(DiffList_TextFile source, DiffList_TextFile destination, ArrayList DiffLines, double time, string failedFileName, out bool result) { int cnt = 1; int i; bool tmpResult = true; string addStr = "+ "; string deleteStr = "- "; CompareReport tmpReports = new CompareReport(); tmpReports.AddDestinationStrings = new ArrayList(); tmpReports.DeleteSourceStrings = new ArrayList(); tmpReports.ReplaceStrings = new ArrayList(); StreamWriter sw = new StreamWriter(failedFileName); sw.WriteLine(titleString); sw.WriteLine(reportSignals); foreach (DiffResultSpan drs in DiffLines) { switch (drs.Status) { case DiffResultSpanStatus.DeleteSource: tmpResult = false; tmpReports.DeleteSourceStrings.Add(deleteString + cnt.ToString() + reportSignals); for (i = 0; i < drs.Length; i++) { tmpReports.DeleteSourceStrings.Add(deleteStr + ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line + "\n"); cnt++; } foreach (object o in tmpReports.DeleteSourceStrings) { sw.WriteLine(o.ToString()); } break; case DiffResultSpanStatus.NoChange: for (i = 0; i < drs.Length; i++) { cnt++; } break; case DiffResultSpanStatus.AddDestination: tmpResult = false; tmpReports.AddDestinationStrings.Add(addString + cnt.ToString() + reportSignals); for (i = 0; i < drs.Length; i++) { tmpReports.AddDestinationStrings.Add(addStr + ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line + "\n"); cnt++; } foreach (object o in tmpReports.AddDestinationStrings) { sw.WriteLine(o.ToString()); } break; case DiffResultSpanStatus.Replace: tmpResult = false; tmpReports.ReplaceStrings.Add(replaceString + cnt.ToString() + reportSignals); for (i = 0; i < drs.Length; i++) { tmpReports.ReplaceStrings.Add(deleteStr + ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line + "\n"); tmpReports.ReplaceStrings.Add(addStr + ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line + "\n"); cnt++; } foreach (object o in tmpReports.ReplaceStrings) { sw.WriteLine(o.ToString()); } break; } } sw.Close(); sw.Dispose(); result = tmpResult; return(tmpReports); }
/// <summary> /// now we highlight any changes between the actual textboxes /// </summary> private void UpdateComparisonBox() { // now we highlight any changes between the actual textboxes DiffList_TextFile sLF = new DiffList_TextFile(textBoxSource.Text, true); DiffList_TextFile dLF = new DiffList_TextFile(textBoxDest.Text, true); double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF, dLF, _level); ArrayList rep = de.DiffReport(); int nChanges = rep.Count; //Results dlg = new Results(sLF, dLF, rep, time); // this.DoCompare(sLF, dLF, rep, time); // textBoxSource.Text = textBoxSource.Text + " >>>> " + nChanges.ToString(); // textBoxSource.Text = ""; // textBoxDest.Text = ""; int i = 0; foreach (DiffResultSpan drs in rep) { switch (drs.Status) { case DiffResultSpanStatus.DeleteSource: for (i = 0; i < drs.Length; i++) { string sSource = ((TextLine)sLF.GetByIndex(drs.SourceIndex + i)).Line; textBoxSource.Find(sSource); textBoxSource.SelectionBackColor = Color.Red; // lviD.BackColor = Color.LightGray; // cnt++; nChanges++; } 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); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); */ // cnt++; } break; case DiffResultSpanStatus.AddDestination: for (i = 0; i < drs.Length; i++) { string sDest = ((TextLine)dLF.GetByIndex(drs.DestIndex + i)).Line; textBoxDest.Find(sDest); textBoxDest.SelectionBackColor = Color.LightGreen; // cnt++; nChanges++; } break; case DiffResultSpanStatus.Replace: for (i = 0; i < drs.Length; i++) { string sSource = (((TextLine)sLF.GetByIndex(drs.SourceIndex + i)).Line); textBoxSource.Find(sSource); textBoxSource.SelectionBackColor = Color.LightGreen; string sDest = (((TextLine)dLF.GetByIndex(drs.DestIndex + i)).Line); textBoxDest.Find(sDest); textBoxDest.SelectionBackColor = Color.Red; // cnt++; nChanges++; } break; } } }
private void TextDiff(string sFile, string dFile) { _level = DiffEngineLevel.SlowPerfect; this.Cursor = Cursors.WaitCursor; DiffList_TextFile sLF = null; DiffList_TextFile dLF = null; try { sLF = new DiffList_TextFile(sFile); dLF = new DiffList_TextFile(dFile); } catch (Exception ex) { this.Cursor = Cursors.Default; MessageBox.Show(ex.Message, "File Error"); return; } try { double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF, dLF, _level); ArrayList rep = de.DiffReport(); Results dlg = new Results(sLF, dLF, rep, time); // dlg.MdiParent = this.MdiParent; dlg.Text = Path.GetFileName(sFile); dlg.ShowDialog(); dlg.Dispose(); } catch (Exception ex) { this.Cursor = Cursors.Default; string tmp = string.Format("{0}{1}{1}***STACK***{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace); MessageBox.Show(tmp, "Compare Error"); return; } this.Cursor = Cursors.Default; }
public Results(DiffList_TextFile source, DiffList_TextFile destination, ArrayList DiffLines, double seconds) { InitializeComponent(); this.Title = $"Results: {seconds:#0.00} secs."; var cnt = 1; foreach (DiffResultSpan diffResult in DiffLines) { switch (diffResult.Status) { case DiffResultSpanStatus.DeleteSource: for (var idx = 0; idx < diffResult.Length; idx++) { DgSource.Items.Add(new { Line = cnt, Text = ((TextLine)source.GetByIndex(diffResult.SourceIndex + idx)).Line, Type = "Red" }); DgTarget.Items.Add(new { Line = cnt, Text = "", Type = "Gray" }); cnt++; } break; case DiffResultSpanStatus.NoChange: for (var idx = 0; idx < diffResult.Length; idx++) { DgSource.Items.Add(new { Line = cnt, Text = ((TextLine)source.GetByIndex(diffResult.SourceIndex + idx)).Line, Type = "White" }); DgTarget.Items.Add(new { Line = cnt, Text = ((TextLine)destination.GetByIndex(diffResult.DestIndex + idx)).Line, Type = "White" }); cnt++; } break; case DiffResultSpanStatus.AddDestination: for (var idx = 0; idx < diffResult.Length; idx++) { DgSource.Items.Add(new { Line = cnt, Text = "", Type = "Gray" }); DgTarget.Items.Add(new { Line = cnt, Text = ((TextLine)destination.GetByIndex(diffResult.DestIndex + idx)).Line, Type = "Green" }); cnt++; } break; case DiffResultSpanStatus.Replace: for (var idx = 0; idx < diffResult.Length; idx++) { DgSource.Items.Add(new { Line = cnt, Text = ((TextLine)source.GetByIndex(diffResult.SourceIndex + idx)).Line, Type = "Red" }); DgTarget.Items.Add(new { Line = cnt, Text = ((TextLine)destination.GetByIndex(diffResult.DestIndex + idx)).Line, Type = "Green" }); cnt++; } break; } } }