コード例 #1
0
        private void TextDiff(string sText, string dText)
        {
            this.Cursor = Cursors.WaitCursor;

            DiffList_Text sLF = null;
            DiffList_Text dLF = null;

            try
            {
                sLF = new DiffList_Text(sText);
                dLF = new DiffList_Text(dText);
            }
            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(sLF, dLF, rep, time);
            }
            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;
        }
コード例 #2
0
        public void Results(DiffList_Text source, DiffList_Text 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;
                }
            }
        }