Inheritance: IDiffList
Ejemplo n.º 1
0
        public void TextDiff(string source, bool sourceIsFile, string destination, bool destinationIsFile)
        {
            using (new DisposableState(this, null))
            {
                DiffListText sLf = null;
                DiffListText dLf = null;
                try
                {
                    sLf = new DiffListText(source, sourceIsFile);
                    dLf = new DiffListText(destination, destinationIsFile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "File Error");
                    return;
                }

                try
                {
                    double time = 0;
                    var    de   = new DiffEngine();
                    time = de.ProcessDiff(sLf, dLf, DiffEngineLevel.SlowPerfect);

                    var rep = de.DiffReport();
                    ShowDiff(sLf, dLf, rep, time);
                }
                catch (Exception ex)
                {
                    var tmp = string.Format("{0}{1}{1}***STACK***{1}{2}",
                                            ex.Message,
                                            Environment.NewLine,
                                            ex.StackTrace);
                    MessageBox.Show(tmp, "Compare Error");
                }
            }
        }
Ejemplo n.º 2
0
        private void ShowDiff(DiffListText source, DiffListText destination, List<DiffResultSpan> diffLines, double seconds)
        {
            _currentIndex = 0;
            _cmdDifferenceNext.Enabled = true;
            _cmdDifferencePrevious.Enabled = true;
            _differences = new List<int>();
            _rtbSourceScript.BeginUpdate();
            _rtbDestinationScript.BeginUpdate();
            var sourceLines = new List<KeyValuePair<string, Color>>();
            var destinationLines = new List<KeyValuePair<string, Color>>();
            int i;

            foreach (var drs in diffLines)
            {
                switch (drs.Status)
                {
                    case DiffResultSpanStatus.DeleteSource:
                        _differences.Add(sourceLines.Count);
                        for (i = 0; i < drs.Length; i++)
                        {
                            sourceLines.Add(new KeyValuePair<string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Red));
                            destinationLines.Add(new KeyValuePair<string, Color>(new string(' ', ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line.Length), Color.Blue));
                        }
                        break;
                    case DiffResultSpanStatus.NoChange:
                        for (i = 0; i < drs.Length; i++)
                        {
                            sourceLines.Add(new KeyValuePair<string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Empty));
                            destinationLines.Add(new KeyValuePair<string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Empty));
                        }
                        break;
                    case DiffResultSpanStatus.AddDestination:
                        _differences.Add(sourceLines.Count);
                        for (i = 0; i < drs.Length; i++)
                        {
                            sourceLines.Add(new KeyValuePair<string, Color>(new string(' ', ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line.Length), Color.Blue));
                            destinationLines.Add(new KeyValuePair<string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Blue));
                        }
                        break;
                    case DiffResultSpanStatus.Replace:
                        _differences.Add(sourceLines.Count);
                        for (i = 0; i < drs.Length; i++)
                        {
                            sourceLines.Add(new KeyValuePair<string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Red));
                            destinationLines.Add(new KeyValuePair<string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Green));
                        }
                        break;
                }
            }

            FillScript(sourceLines, _rtbSourceScript);
            FillScript(destinationLines, _rtbDestinationScript);

            _rtbSourceScript.EndUpdate();
            _rtbDestinationScript.EndUpdate();

            this.Text = _differences.Count + " differences.";
        }
Ejemplo n.º 3
0
        private void ShowDiff(DiffListText source, DiffListText destination, List <DiffResultSpan> diffLines, double seconds)
        {
            _currentIndex = 0;
            _cmdDifferenceNext.Enabled     = true;
            _cmdDifferencePrevious.Enabled = true;
            _differences = new List <int>();
            _rtbSourceScript.BeginUpdate();
            _rtbDestinationScript.BeginUpdate();
            var sourceLines      = new List <KeyValuePair <string, Color> >();
            var destinationLines = new List <KeyValuePair <string, Color> >();
            int i;

            foreach (var drs in diffLines)
            {
                switch (drs.Status)
                {
                case DiffResultSpanStatus.DeleteSource:
                    _differences.Add(sourceLines.Count);
                    for (i = 0; i < drs.Length; i++)
                    {
                        sourceLines.Add(new KeyValuePair <string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Red));
                        destinationLines.Add(new KeyValuePair <string, Color>(new string(' ', ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line.Length), Color.Blue));
                    }
                    break;

                case DiffResultSpanStatus.NoChange:
                    for (i = 0; i < drs.Length; i++)
                    {
                        sourceLines.Add(new KeyValuePair <string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Empty));
                        destinationLines.Add(new KeyValuePair <string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Empty));
                    }
                    break;

                case DiffResultSpanStatus.AddDestination:
                    _differences.Add(sourceLines.Count);
                    for (i = 0; i < drs.Length; i++)
                    {
                        sourceLines.Add(new KeyValuePair <string, Color>(new string(' ', ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line.Length), Color.Blue));
                        destinationLines.Add(new KeyValuePair <string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Blue));
                    }
                    break;

                case DiffResultSpanStatus.Replace:
                    _differences.Add(sourceLines.Count);
                    for (i = 0; i < drs.Length; i++)
                    {
                        sourceLines.Add(new KeyValuePair <string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Red));
                        destinationLines.Add(new KeyValuePair <string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Green));
                    }
                    break;
                }
            }

            FillScript(sourceLines, _rtbSourceScript);
            FillScript(destinationLines, _rtbDestinationScript);

            _rtbSourceScript.EndUpdate();
            _rtbDestinationScript.EndUpdate();

            this.Text = _differences.Count + " differences.";
        }
Ejemplo n.º 4
0
        public void TextDiff(string source, bool sourceIsFile, string destination, bool destinationIsFile)
        {
            using (new DisposableState(this, null))
            {
                DiffListText sLf = null;
                DiffListText dLf = null;
                try
                {
                    sLf = new DiffListText(source, sourceIsFile);
                    dLf = new DiffListText(destination, destinationIsFile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "File Error");
                    return;
                }

                try
                {
                    double time = 0;
                    var de = new DiffEngine();
                    time = de.ProcessDiff(sLf, dLf, DiffEngineLevel.SlowPerfect);

                    var rep = de.DiffReport();
                    ShowDiff(sLf, dLf, rep, time);
                }
                catch (Exception ex)
                {
                    var tmp = string.Format("{0}{1}{1}***STACK***{1}{2}",
                        ex.Message,
                        Environment.NewLine,
                        ex.StackTrace);
                    MessageBox.Show(tmp, "Compare Error");
                }
            }
        }