Example #1
0
		public MainForm()
		{
			
			InitializeComponent();

			_level = DiffEngineLevel.FastImperfect; 
		}
Example #2
0
        private void Compare_Click(object sender, RoutedEventArgs e)
        {
            string sourceFile = txtSourceEditor.Text.Trim();
            string destFile   = txtDestEditor.Text.Trim();

            ValidateFile(sourceFile, txtSourceEditor);
            ValidateFile(destFile, txtDestEditor);

            var diffLevelRadioBtns = new List <RadioButton> {
                RbFast, RbMedium, RbSlow
            };

            RadioButton checkedDiffLevel = diffLevelRadioBtns.FirstOrDefault((RadioButton rb) => rb.IsChecked == true);

            if (checkedDiffLevel.Tag.Equals("Fast"))
            {
                diffEngineLevel = DiffEngineLevel.Fast;
            }
            if (checkedDiffLevel.Tag.Equals("Medium"))
            {
                diffEngineLevel = DiffEngineLevel.Medium;
            }
            if (checkedDiffLevel.Tag.Equals("Slow"))
            {
                diffEngineLevel = DiffEngineLevel.Slow;
            }

            DisplayTextDiff(sourceFile, destFile);
        }
Example #3
0
        private void compareBtn_Click(object sender, EventArgs e)
        {
            if (checkBoxEdit.Checked || checkBoxEdit.Checked)
            {
                MessageBox.Show(this, "Cannot Compare Documents in Edit Mode: Please Uncheck Edit Mode and try again");
                return;
            }

            if (radioButtonfast.Checked)
            {
                _level = DiffEngineLevel.FastImperfect;
            }
            else
            {
                if (radioButtonMedium.Checked)
                {
                    _level = DiffEngineLevel.Medium;
                }
                else
                {
                    _level = DiffEngineLevel.SlowPerfect;
                }
            }

            ResetView(oldGridView);
            ResetView(newGridView);

            #region todelete

            #endregion

            TextDiff(_oldText, _newText);
        }
Example #4
0
        private void btnCompare_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            if (btn != null)
            {
                if (btn.Equals(this.btnCompare))
                {
                    this.lbxChangedLine.Items.Clear();

                    this.tsLblSource.Text = this.tsLblDest.Text = "";

                    string pText1 = this.ucCompareSelectSource.GetString();
                    string pText2 = this.ucCompareSelectDestination.GetString();

                    if (string.IsNullOrEmpty(pText1))
                    {
                        this.gbxSource.Visible      = this.gbxDest.Visible = true;
                        this.pnlCompareInfo.Visible = !this.gbxSource.Visible;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(pText2))
                        {
                            this.gbxSource.Visible      = this.gbxDest.Visible = true;
                            this.pnlCompareInfo.Visible = !this.gbxSource.Visible;
                        }
                        else
                        {
                            this.tsLblSource.Text = this.ucCompareSelectSource.GetTitle();
                            this.tsLblDest.Text   = this.ucCompareSelectDestination.GetTitle();

                            this._sorurceText = new DiffListText(pText1);
                            this._destText    = new DiffListText(pText2);

                            this.lvSource.Items.Clear();
                            this.lvDestination.Items.Clear();

                            DiffEngine      diffEngine = new DiffEngine();
                            DiffEngineLevel level      = !this.rbtnFast.Checked ? (!this.rbtnMedium.Checked ? DiffEngineLevel.SlowPerfect : DiffEngineLevel.Medium) : DiffEngineLevel.FastImperfect;

                            diffEngine.ProcessDiff((IDiffList)this._sorurceText, (IDiffList)this._destText, level);
                            this.ShowDiff(this._sorurceText, this._destText, diffEngine.DiffReport());
                            this.gbxSource.Visible      = this.gbxDest.Visible = false;
                            this.pnlCompareInfo.Visible = !this.gbxSource.Visible;
                        }
                    }
                }
                else if (btn.Equals(this.btnVisible))
                {
                    this.gbxSource.Visible      = this.gbxDest.Visible = !this.gbxSource.Visible;
                    this.pnlCompareInfo.Visible = !this.gbxSource.Visible;
                }
                else if (btn.Equals(this.btnClose))
                {
                    this.Close();
                }
            }
        }
Example #5
0
 public DiffEngine()
 {
     this._source    = null;
     this._dest      = null;
     this._matchList = null;
     this._stateList = null;
     this._level     = DiffEngineLevel.FastImperfect;
 }
Example #6
0
 public Engine()
 {
     _source        = null;
     _destination   = null;
     _matchList     = null;
     _diffStateList = null;
     _level         = DiffEngineLevel.Fast;
 }
Example #7
0
 public DiffEngine()
 {
     source    = null;
     dest      = null;
     matchList = null;
     stateList = null;
     level     = DiffEngineLevel.FastImperfect;
 }
Example #8
0
 public DiffEngine()
 {
     _source    = null;
     _dest      = null;
     _matchList = null;
     _stateList = null;
     _level     = DiffEngineLevel.FastImperfect;
 }
Example #9
0
 public DiffEngine()
 {
     source = null;
     dest = null;
     matchList = null;
     stateList = null;
     level = DiffEngineLevel.FastImperfect;
 }
Example #10
0
 public DiffEngine()
 {
     this._source    = (IDiffList)null;
     this._dest      = (IDiffList)null;
     this._matchList = (ArrayList)null;
     this._stateList = (DiffStateList)null;
     this._level     = DiffEngineLevel.FastImperfect;
 }
 public DiffEngine()
 {
     _source = null;
     _dest = null;
     _matchList = null;
     _stateList = null;
     _level = DiffEngineLevel.FastImperfect;
 }
 public DiffEngine()
 {
     this._source = null;
     this._dest = null;
     this._matchList = null;
     this._stateList = null;
     this._level = DiffEngineLevel.FastImperfect;
 }
Example #13
0
        public Main()
        {
            InitializeComponent();
            _oldText = textBoxOld.Text;
            _newText = textBoxNew.Text;

            _level = DiffEngineLevel.FastImperfect;
            CreateColumns();
        }
 public static List<DiffResultSpan> CompareTextFiles(string source, string destination, DiffEngineLevel level)
 {
     var inst = new DiffEngine();
     inst._level = level;
     var src = new DiffList_TextFile(source);
     var dst = new DiffList_TextFile(destination);
     inst.ProcessDiff(src, dst);
     return inst.DiffReport();
 }
Example #15
0
 private void ClickDiffButtonEvent(object sender, EventArgs e, string target, string correct)
 {
     if (rbFast.Checked)
     {
         _level = DiffEngineLevel.FastImperfect;
     }
     else if (rbMedium.Checked)
     {
         _level = DiffEngineLevel.Medium;
     }
     else
     {
         _level = DiffEngineLevel.SlowPerfect;
     }
     TextDiff(target, correct);
 }
Example #16
0
        private void cmdCompare_Click(object sender, System.EventArgs e)
        {
            string sFile = txtSource.Text.Trim();
            string dFile = txtDestination.Text.Trim();

            if (!ValidFile(sFile))
            {
                MessageBox.Show("Source file name is invalid.", "Invalid File");
                txtSource.Focus();
                return;
            }

            if (!ValidFile(dFile))
            {
                MessageBox.Show("Destination file name is invalid.", "Invalid File");
                txtDestination.Focus();
                return;
            }

            if (rbFast.Checked)
            {
                _level = DiffEngineLevel.FastImperfect;
            }
            else
            {
                if (rbMedium.Checked)
                {
                    _level = DiffEngineLevel.Medium;
                }
                else
                {
                    _level = DiffEngineLevel.SlowPerfect;
                }
            }

            if (chkBinary.Checked)
            {
                BinaryDiff(sFile, dFile);
            }
            else
            {
                TextDiff(sFile, dFile);
            }
        }
Example #17
0
        private void ListResults_Load(object sender, EventArgs e)
        {
            _level = DiffEngineLevel.Medium;
            Regex reg = new Regex(@"\d+.\w+");

            foreach (Test test in FailedTests)
            {
                Button buttonInput = new Button();
                buttonInput.Text      = reg.Match(test.InputPath).Value;
                buttonInput.BackColor = Color.DarkRed;
                buttonInput.ForeColor = Color.White;
                buttonInput.Click    += (s, args) => ClickInputButtonEvent(s, args, test.InputPath);
                flowLayoutPanel.Controls.Add(buttonInput);

                Button buttonDiff = new Button();
                buttonDiff.Text   = "Diff.";
                buttonDiff.Click += (s, args) => ClickDiffButtonEvent(s, args, test.TargetOutputPath, test.CorrectOutputPath);
                flowLayoutPanel.Controls.Add(buttonDiff);
            }
            foreach (Test test in PassedTests)
            {
                Button buttonInput = new Button();
                buttonInput.Text      = reg.Match(test.InputPath).Value;
                buttonInput.BackColor = Color.Green;
                buttonInput.ForeColor = Color.White;
                buttonInput.Click    += (s, args) => ClickInputButtonEvent(s, args, test.InputPath);
                flowLayoutPanel.Controls.Add(buttonInput);

                Button buttonDiff = new Button();
                buttonDiff.Text   = "Diff.";
                buttonDiff.Click += (s, args) => ClickDiffButtonEvent(s, args, test.TargetOutputPath, test.CorrectOutputPath);
                flowLayoutPanel.Controls.Add(buttonDiff);
            }
            foreach (string errorPath in ErrorInputPaths)
            {
                Button buttonErrorInput = new Button();
                buttonErrorInput.Text      = reg.Match(errorPath).Value;
                buttonErrorInput.BackColor = Color.Gold;
                buttonErrorInput.ForeColor = Color.Black;
                buttonErrorInput.Click    += (s, args) => ClickInputButtonEvent(s, args, errorPath);
                flowLayoutPanel.Controls.Add(buttonErrorInput);
            }
        }
        /// <summary>
        /// マージ処理を行います。
        /// </summary>
        /// <param name="mergedPath">マージ結果を保存するファイルのパス</param>
        /// <param name="level">比較レベル</param>
        public void Merge(string mergedPath, DiffEngineLevel level = DiffEngineLevel.SlowPerfect)
        {
            StringBuilder sb = new StringBuilder();
            int i = 0;
            DiffReport report = Report(level);
            foreach (DiffResultSpan drs in report)
            {
                switch (drs.Status)
                {
                    case DiffResultSpanStatus.DeleteSource:
                        // No Operation.
                        break;
                    case DiffResultSpanStatus.NoChange:
                        for (i = 0; i < drs.Length; i++)
                            sb.AppendLine(report.Source.GetByIndex(drs.SourceIndex + i).ToString());
                        break;
                    case DiffResultSpanStatus.AddDestination:
                        for (i = 0; i < drs.Length; i++)
                            sb.AppendLine(report.Destination.GetByIndex(drs.DestIndex + i).ToString());
                        break;
                    case DiffResultSpanStatus.Replace:
                        for (i = 0; i < drs.Length; i++)
                            sb.AppendLine(report.Destination.GetByIndex(drs.DestIndex + i).ToString());
                        break;
                }
            }

            // 終端の改行コードはロジック上で付加した物なので削除する
            string ret = sb.ToString();
            if (ret.EndsWith(Environment.NewLine))
                ret = ret.Remove(ret.LastIndexOf(Environment.NewLine), Environment.NewLine.Length);

            File.WriteAllText(mergedPath, ret, Encoding);
        }
Example #19
0
        private void cmdCompare_Click(object sender, System.EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;

            string sFile="";
            string dFile="";

            if (chkbxChanhecompare.Checked)
            {
                sFile = txtDestination.Text.Trim();
                dFile =  txtSource.Text.Trim();

            }
            if (!chkbxChanhecompare.Checked)
            {
                 sFile = txtSource.Text.Trim();
                 dFile = txtDestination.Text.Trim();
            }     

            if (!ValidFile(sFile))
            {
                MessageBox.Show("Source file name is invalid.", "Invalid File");
                txtSource.Focus();
                return;
            }

            if (!ValidFile(dFile))
            {
                MessageBox.Show("Destination file name is invalid.", "Invalid File");
                txtDestination.Focus();
                return;
            }

            if (rbFast.Checked)
			{
				_level = DiffEngineLevel.FastImperfect; 
			}
			else
			{
				if (rbMedium.Checked)
				{
					_level = DiffEngineLevel.Medium;
				}
				else
				{
					_level = DiffEngineLevel.SlowPerfect; 
				}
			}

			if (chkBinary.Checked)
			{
				BinaryDiff(sFile,dFile);
			}
			else
			{
				TextDiff(sFile,dFile);
			}
			
		}
        /// <summary>
        /// 比較結果を取得します。
        /// </summary>
        /// <param name="source">比較元文字列</param>
        /// <param name="destination">比較先文字列</param>
        /// <param name="level">比較レベル</param>
        /// <returns>比較結果</returns>
        public static DiffReport Report(string source, string destination, DiffEngineLevel level = DiffEngineLevel.SlowPerfect)
        {
            var d1 = new StringLineCollection(source);
            var d2 = new StringLineCollection(destination);
            DiffEngine de = new DiffEngine();
            de.ProcessDiff(d1, d2, level);

            return de.DiffReport();
        }
 /// <summary>
 /// The process diff.
 /// </summary>
 /// <param name="sourceIn">
 /// The source in.
 /// </param>
 /// <param name="destination">
 /// The destination.
 /// </param>
 /// <param name="levelIn">
 /// The level in.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public double ProcessDiff(IDiffList sourceIn, IDiffList destination, DiffEngineLevel levelIn)
 {
     this.level = levelIn;
     return this.ProcessDiff(sourceIn, destination);
 }
Example #22
0
 public MainForm()
 {
     InitializeComponent();
     _level = DiffEngineLevel.FastImperfect;
 }
Example #23
0
        public ArrayList ProcessDiff(DiffEngineLevel level)
        {
            ArrayList result = new ArrayList();

            if (_source == null || _dest == null)
                return result;

            _level = level;
            _matchList = new ArrayList();

            int dcount = _dest  .Count();
            int scount = _source.Count();

            if ((dcount > 0) && (scount > 0)) {
                _stateList = new DiffStateList(dcount);
                ProcessRange(0, dcount - 1, 0, scount - 1);
            }

            //Deal with the special case of empty files
            if (dcount == 0) {
                if (scount > 0) {
                    result.Add(DiffResultSpan.CreateDeleteSource(0, scount));
                }
                return result;
            } else {
                if (scount == 0) {
                    result.Add(DiffResultSpan.CreateAddDestination(0, dcount));
                    return result;
                }
            }

            _matchList.Sort();
            int curDest   = 0;
            int curSource = 0;
            DiffResultSpan last = null;

            //Process each match record
            foreach (DiffResultSpan drs in _matchList) {
                if ((!AddChanges(result, curDest, drs.DestIndex, curSource, drs.SourceIndex)) &&
                    (last != null)) {
                    last.AddLength(drs.Length);
                } else {
                    result.Add(drs);
                }
                curDest   = drs.DestIndex   + drs.Length;
                curSource = drs.SourceIndex + drs.Length;
                last = drs;
            }

            //Process any tail end data
            AddChanges(result, curDest, dcount, curSource, scount);

            return result;
        }
Example #24
0
 public double ProcessDiff(IDiffList sourceList, IDiffList destination, DiffEngineLevel engineLevel)
 {
     level = engineLevel;
     return ProcessDiff(sourceList, destination);
 }
		public double ProcessDiff(IDiffList source, IDiffList destination,DiffEngineLevel level)
		{
			_level = level;
			return ProcessDiff(source,destination);
		}
Example #26
0
        public static List <DiffResultSpan> CompareTextFiles(string source, string destination, DiffEngineLevel level)
        {
            var inst = new DiffEngine();

            inst._level = level;
            var src = new DiffList_TextFile(source);
            var dst = new DiffList_TextFile(destination);

            inst.ProcessDiff(src, dst);
            return(inst.DiffReport());
        }
Example #27
0
 public double ProcessDiff(IDiffList source, IDiffList destination, DiffEngineLevel level)
 {
     this.level = level;
     return(ProcessDiff(source, destination));
 }
        /// <summary>
        /// 比較結果を取得します。
        /// </summary>
        /// <param name="level">比較レベル</param>
        /// <returns>比較結果</returns>
        public DiffReport Report(DiffEngineLevel level = DiffEngineLevel.SlowPerfect)
        {
            CheckFileExist(SourcePath);
            CheckFileExist(DestinationPath);

            var d1 = new TextLineCollection(SourcePath);
            var d2 = new TextLineCollection(DestinationPath);
            DiffEngine de = new DiffEngine();
            de.ProcessDiff(d1, d2, level);

            return de.DiffReport();
        }
Example #29
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;
 }
        /// <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 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();
        }
Example #32
0
 public TextDifference()
 {
     InitializeComponent();
     _level = DiffEngineLevel.FastImperfect;
 }
Example #33
0
 /// <summary>
 /// The process diff.
 /// </summary>
 /// <param name="sourceIn">
 /// The source in.
 /// </param>
 /// <param name="destination">
 /// The destination.
 /// </param>
 /// <param name="levelIn">
 /// The level in.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public double ProcessDiff(IDiffList sourceIn, IDiffList destination, DiffEngineLevel levelIn)
 {
     this.level = levelIn;
     return(this.ProcessDiff(sourceIn, destination));
 }