Ejemplo n.º 1
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();
 }
Ejemplo n.º 2
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());
        }
        private void cmdCompare2_Click(object sender, RoutedEventArgs e)
        {
            txtResult.TextArea.TextView.LineTransformers.Clear();


            var cp1 = new DiffList_String(textEditorA.Text);
            var cp2 = new DiffList_String(textEditorB.Text);
            var df = new DiffEngine();
            df.ProcessDiff(cp1, cp2, DiffEngineLevel.SlowPerfect);
            var result = df.DiffReport();

            var txt = "";
            //diff_match_patch comparer=new diff_match_patch();
            //var result = comparer.diff_main(textEditorA.Text, textEditorB.Text);
            
            txtResult.Document.Text = "";
            foreach (var diff in result)
            {
                if (diff.Status == DiffResultSpanStatus.AddDestination)
                {
                    var st = txt.Length;
                    for (int i = diff.DestIndex; i < diff.DestIndex + diff.Length; i++)
                    {
                        txt += ((TextLine)cp2.GetByIndex(i)).Line + Environment.NewLine; ;
                    }
                    var stp = txt.Length;

                    txtResult.TextArea.TextView.LineTransformers.Add(new TextColorizer(st, stp, Brushes.Green));
                }
                else if (diff.Status == DiffResultSpanStatus.DeleteSource)
                {
                    var st = txt.Length;
                    for (int i = diff.SourceIndex; i < diff.SourceIndex + diff.Length; i++)
                    {
                        txt += ((TextLine)cp1.GetByIndex(i)).Line + Environment.NewLine; ;
                    }
                    var stp = txt.Length;
                    txtResult.TextArea.TextView.LineTransformers.Add(new TextColorizer(st, stp, Brushes.Red));
                }
                else if (diff.Status == DiffResultSpanStatus.Replace)
                {
                    var st = txt.Length;
                    for (int i = diff.DestIndex; i < diff.DestIndex + diff.Length; i++)
                    {
                        txt += ((TextLine)cp2.GetByIndex(i)).Line + Environment.NewLine;
                    }
                    var stp = txt.Length;
                    txtResult.TextArea.TextView.LineTransformers.Add(new TextColorizer(st, stp, Brushes.Orange));
                }
                else
                {
                    for (int i = diff.SourceIndex; i < diff.Length; i++)
                    {
                        txt += ((TextLine)cp1.GetByIndex(i)).Line + Environment.NewLine; ;
                    }  
                }
                
            }
            txtResult.Document.Text = txt;

        }