Example #1
0
        /// <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);
        }
        /// <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;
                        }

                    }
        }
        /// <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;
        }
Example #4
0
        /// <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;
                }
            }
        }