Пример #1
0
        /// <summary>
        /// Runs the diff process for the specified files.
        /// </summary>
        public void CompareDifference(Object sender, DoWorkEventArgs e)
        {
            this.sourceListView.Items.Clear();
            this.destinationListView.Items.Clear();
            this.sourceListView.BeginUpdate();
            this.destinationListView.BeginUpdate();
            try
            {
                String source = ((String[])e.Argument)[0];
                String destination = ((String[])e.Argument)[1];
                Int32 count = 1; ListViewItem lviS, lviD;
                TextFile file1 = new TextFile(source);
                TextFile file2 = new TextFile(destination);
                DiffEngine de = new DiffEngine();
                de.ProcessDiff(file1, file2, DiffEngineLevel.Medium);
                ArrayList lines = de.DiffReport();
                Int32 counter = 0, total = lines.Count;
                foreach (DiffResultSpan drs in lines)
                {
                    switch (drs.Status)
                    {
                        case DiffResultSpanStatus.DeleteSource:
                            for (Int32 i = 0; i < drs.Length; i++)
                            {
                                lviS = new ListViewItem(count.ToString("00000"));
                                lviD = new ListViewItem(count.ToString("00000"));
                                lviS.Font = lviD.Font = new Font("Courier New", 8.25F);
                                lviS.BackColor = Color.Red;
                                lviS.SubItems.Add(((TextLine)file1.GetByIndex(drs.SourceIndex + i)).Line);
                                lviD.BackColor = Color.LightGray;
                                lviD.SubItems.Add("");
                                this.sourceListView.Items.Add(lviS);
                                this.destinationListView.Items.Add(lviD);
                                count++;
                            }
                            break;

                        case DiffResultSpanStatus.NoChange:
                            for (Int32 i = 0; i < drs.Length; i++)
                            {
                                lviS = new ListViewItem(count.ToString("00000"));
                                lviD = new ListViewItem(count.ToString("00000"));
                                lviS.Font = lviD.Font = new Font("Courier New", 8.25F);
                                lviS.BackColor = Color.White;
                                lviS.SubItems.Add(((TextLine)file1.GetByIndex(drs.SourceIndex + i)).Line);
                                lviD.BackColor = Color.White;
                                lviD.SubItems.Add(((TextLine)file2.GetByIndex(drs.DestIndex + i)).Line);
                                this.sourceListView.Items.Add(lviS);
                                this.destinationListView.Items.Add(lviD);
                                count++;
                            }
                            break;

                        case DiffResultSpanStatus.AddDestination:
                            for (Int32 i = 0; i < drs.Length; i++)
                            {
                                lviS = new ListViewItem(count.ToString("00000"));
                                lviD = new ListViewItem(count.ToString("00000"));
                                lviS.Font = lviD.Font = new Font("Courier New", 8.25F);
                                lviS.BackColor = Color.LightGray;
                                lviS.SubItems.Add("");
                                lviD.BackColor = Color.LightGreen;
                                lviD.SubItems.Add(((TextLine)file2.GetByIndex(drs.DestIndex + i)).Line);
                                this.sourceListView.Items.Add(lviS);
                                this.destinationListView.Items.Add(lviD);
                                count++;
                            }
                            break;

                        case DiffResultSpanStatus.Replace:
                            for (Int32 i = 0; i < drs.Length; i++)
                            {
                                lviS = new ListViewItem(count.ToString("00000"));
                                lviD = new ListViewItem(count.ToString("00000"));
                                lviS.Font = lviD.Font = new Font("Courier New", 8.25F);
                                lviS.BackColor = Color.Red;
                                lviS.SubItems.Add(((TextLine)file1.GetByIndex(drs.SourceIndex + i)).Line);
                                lviD.BackColor = Color.LightGreen;
                                lviD.SubItems.Add(((TextLine)file2.GetByIndex(drs.DestIndex + i)).Line);
                                this.sourceListView.Items.Add(lviS);
                                this.destinationListView.Items.Add(lviD);
                                count++;
                            }
                            break;
                    }
                    counter++;
                    Int32 percent = (100 * counter) / total;
                    this.backgroundWorker.ReportProgress(percent);
                }
                e.Result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                e.Result = false;
            }
            this.destinationListView.EndUpdate();
            this.sourceListView.EndUpdate();
        }
Пример #2
0
        private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.lvSource.Items.Clear();
            this.lvDestination.Items.Clear();

            ChangeInfo info = (ChangeInfo)this.treeView.SelectedNode.Tag;

            DiffList_TextString source = new DiffList_TextString(info.Original != null ? info.Original.Documentation : String.Empty);
            DiffList_TextString destination = new DiffList_TextString(info.Change != null ? info.Change.Documentation : String.Empty);
            DiffEngine de = new DiffEngine();
            de.ProcessDiff(source, destination, DiffEngineLevel.SlowPerfect);
            ArrayList DiffLines = de.DiffReport();

            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;
                }

            }


            this.radioButtonOriginal.Checked = !this.treeView.SelectedNode.Checked;
            this.radioButtonChange.Checked = this.treeView.SelectedNode.Checked;
        }
Пример #3
0
        /// <summary>
        /// Use DifferenceEngine to calculate Differences
        /// </summary>
        /// <param name="sFile"></param>
        /// <param name="dFile"></param>
        private ArrayList TextDiff(DiffList_TextFile sLF, DiffList_TextFile dLF)
        {

            double time = 0;
            DiffEngine de = new DiffEngine();
            time = de.ProcessDiff(sLF, dLF, DifferenceEngine.DiffEngineLevel.SlowPerfect);

            ArrayList rep = de.DiffReport();
            return rep;

        }
        /// <summary>
        /// The get source diff from strings.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <param name="level">
        /// The level.
        /// </param>
        /// <returns>
        /// The <see cref="ArrayList"/>.
        /// </returns>
        public static ArrayList GetSourceDiffFromStrings(string source, string destination, DiffEngineLevel level = DiffEngineLevel.SlowPerfect)
        {
            var sourceseparator = "\n";
            if (source.Contains("\r\n"))
            {
                sourceseparator = "\r\n";
            }

            var destinationsepartor = "\n";
            if (destination.Contains("\r\n"))
            {
                destinationsepartor = "\r\n";
            }

            var sLf = new DiffListTextFile(source, sourceseparator);
            var dLf = new DiffListTextFile(destination, destinationsepartor);
            var de = new DiffEngine();
            de.ProcessDiff(sLf, dLf, level);
            return de.DiffReport();
        }
        /// <summary>
        /// The get difference report.
        /// </summary>
        /// <param name="filePath">
        /// The file Path.
        /// </param>
        /// <param name="sourceInServer">
        /// The in server source.
        /// </param>
        /// <param name="displayWindow">
        /// The display Window.
        /// </param>
        /// <returns>
        /// The <see cref="ArrayList"/>.
        /// </returns>
        public static ArrayList GetDifferenceReport(string filePath, string sourceInServer, bool displayWindow)
        {
            var sLf = new DiffListTextFile(filePath);
            var dLf = new DiffListTextFile(sourceInServer, "\r\n");

            var de = new DiffEngine();
            de.ProcessDiff(dLf, sLf, DiffEngineLevel.SlowPerfect);

            if (!displayWindow)
            {
                return de.DiffReport();
            }

            using (var win = new Results(sLf, dLf, de.DiffReport(), 0))
            {
                win.ShowDialog();
            }

            return de.DiffReport();
        }
Пример #6
0
		private void BinaryDiff(string sFile, string dFile)
		{
			this.Cursor = Cursors.WaitCursor;

			DiffList_BinaryFile sLF = null;
			DiffList_BinaryFile dLF = null;
			try
			{
				sLF = new DiffList_BinaryFile(sFile);
				dLF = new DiffList_BinaryFile(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();
				
				BinaryResults dlg = new BinaryResults(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;
		}
Пример #7
0
 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;
 }
Пример #8
0
        private void CompareFrom_Click(object sender, EventArgs e)
        {
            int typeIndex = this.FileTypeComBox.SelectedIndex;
            if (typeIndex != 3 && typeIndex != 4)
            {
                MessageBox.Show("请选择要对比文件类型", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string parentFileName = PathManager.GetParentFolderName(typeIndex);
            string compareFileName = PathManager.GetCompareFileName(typeIndex);
            string sFile = this.OldServiceWsdCmb.Text.Trim();
            string dFile = this.NewServiceWsdCmb.Text.Trim();
            if (sFile.Contains("{0}"))
            {
                sFile = string.Format(this.OldServiceWsdCmb.Text, this.ChangeSetTextBox.Text, this.CompanyComBox.Text, parentFileName, compareFileName);
            }
            if (dFile.Contains("{0}"))
            {
                dFile = string.Format(this.NewServiceWsdCmb.Text, parentFileName, parentFileName, compareFileName);
            }
            if (!PathManager.ValidFileExist(sFile) || !PathManager.ValidFileExist(dFile)) return;

            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, DiffEngineLevel.FastImperfect);

                ArrayList rep = de.DiffReport();
                Results dlg = new Results(sLF, dLF, rep);
                dlg.ShowDialog();
                dlg.Dispose();
                //this.BindData(sLF, dLF, rep);
            }
            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;
        }