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;
 }
Beispiel #2
0
        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;
                }

            }
        }