示例#1
0
        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());
        }
示例#2
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;
                        }

                    }
        }
示例#3
0
        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;
                }
            }
        }
示例#4
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;
                }

            }
        }
示例#5
0
        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());
        }
示例#6
0
        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;
                }
            }
        }
示例#7
0
        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;
            }
        }
示例#8
0
        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);
        }
示例#9
0
        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;
                }
            }
        }