Пример #1
0
        public void GetPatchOperations11()
        {
            DiffEngine <string> diffEngine =
                new DiffEngine <string>(
                    "The metrics for clarity are more-well understood. Do you have a game PLAN to become peerlessly synergetic across all platforms ? Think interactive".Split(' '),
                    //0    1       2    3     4      5      6           7  8   9   10 11   12  13   14      15        16         17   18   19       20 21     22
                    //0    1       2    3         4     5         6         7  8   9   10 11  12   13  14         15     16  17   18
                    "The metrics for obfuscation are more-well understood. Do you have a game plan to become cross-media ? Think interactive".Split(' '));

            PatchOperation[] expectedPatchOperations =
                new PatchOperation[] {
                PatchOperation.CreateCopy(0, 2),
                PatchOperation.CreateAddition(3, 3),
                PatchOperation.CreateDeletion(3, 3),
                PatchOperation.CreateCopy(4, 11),
                PatchOperation.CreateAddition(12, 12),
                PatchOperation.CreateDeletion(12, 12),
                PatchOperation.CreateCopy(13, 14),
                PatchOperation.CreateAddition(15, 15),
                PatchOperation.CreateDeletion(15, 19),
                PatchOperation.CreateCopy(20, 22)
            };

            AssertDifferences(diffEngine, expectedPatchOperations);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var textA = @"zero one two three four fyve six seven";
            var textB = @"zero one too treee four five six seven eight nine";

            var result = DiffEngine.Process(ref textA, ref textB);

            var html =
                $@"
                    <html>
                     <head>
                      <style>
                        ins{{background-color: #d5ffba;}}
                        del{{background-color: #ffc6d5;}}
                      </style>
                     </head>
                      <body>
                        {result}
                      </body>
                    </html>
                    ";

            File.WriteAllText(@"test.html", html);
            Process.Start("test.html");
        }
Пример #3
0
        private void ComputeLineDifferences(LineRecord lrec, LineRecord rrec)
        {
            DiffList_CharData left  = new DiffList_CharData(lrec.Text);
            DiffList_CharData right = new DiffList_CharData(rrec.Text);

            DiffEngine engine = new DiffEngine();

            engine.ProcessDiff(left, right, DiffEngineLevel.SlowPerfect);
            ArrayList report = engine.DiffReport();

            foreach (DiffResultSpan dres in report)
            {
                switch (dres.Status)
                {
                case DiffResultSpanStatus.NoChange:
                    break;

                case DiffResultSpanStatus.Replace:
                    lrec.AddRange(dres.SourceIndex, dres.SourceIndex + dres.Length, Color.LightSalmon, Color.Empty);
                    rrec.AddRange(dres.DestIndex, dres.DestIndex + dres.Length, Color.LightSalmon, Color.Empty);
                    break;

                case DiffResultSpanStatus.DeleteSource:
                    lrec.AddRange(dres.SourceIndex, dres.SourceIndex + dres.Length, Color.LightSalmon, Color.Empty);
                    break;

                case DiffResultSpanStatus.AddDestination:
                    rrec.AddRange(dres.DestIndex, dres.DestIndex + dres.Length, Color.LightSalmon, Color.Empty);
                    break;

                default:
                    break;
                } // switch
            }     // foreach
        }
Пример #4
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;
        }
Пример #5
0
        public void DiffDifferentTest()
        {
            const string f_alt = @"diff-b1.xml";
            const string f_neu = @"diff-b2.xml";

            Knoten alt = Knoten.createOf(createDOM(XmlReader.Create(f_alt)));
            Knoten neu = Knoten.createOf(createDOM(XmlReader.Create(f_neu)));

            DiffEngine diff = new DiffEngine();
            Knoten     res  = diff.Diff(alt, neu);

            Assert.IsNotNull(res);
            Assert.AreEqual(
                "<fucc>" +
                "<property name=\"launch\">" +
                "<!-- ADDED:   hinzugefuegt (aslkdfh) -->" +
                "</property>" +
                "<program name=\"\">" +
                "<argument startsWith=\"\">" +
                "<dir recursive=\"false\" type=\"files\">" +
                "<!-- REMOVED: match (.+\\.(cmd|exe|lnk|bat)) -->" +
                "<!-- ADDED:   match (sdf.+\\.(cmd|exe|lnk|bat)) -->" +
                "</dir>" +
                "<!-- REMOVED: pathenv () -->" +
                "<!-- ADDED:   pathenb () -->" +
                "</argument>" +
                "</program>" +
                "<!-- REMOVED: alias name=\"gt\" appendParams=\"true\" () -->" +
                "</fucc>",
                res.ToString());
        }
Пример #6
0
        public void Should_find_no_difference_between_original_Scrum_project_and_Agile_project_converted_to_Scrum()
        {
            PrepareTestEnvironment.ResetCollectionOnce();

            TfsConnection.ClientSettingsDirectory = Path.Combine(TestContext.TestRunResultsDirectory, "TfsClient");

            var factory = new ProcessTemplateFactory();

            var unconverted = factory.FromActiveTeamProject(TestCollectionUri, "Agile-6.1");
            var goal = factory.FromActiveTeamProject(TestCollectionUri, "Scrum-2.1");

            var agileToScrumDiffEngine = new DiffEngine(ProcessTemplateMaps.Agile61ToScrum21());

            var initialDifferences = agileToScrumDiffEngine.CompareProcessTemplates(unconverted, goal);

            var morphEngine = new MorphEngine();
            var actions = morphEngine.GenerateActions(initialDifferences);

            morphEngine.Apply(TestCollectionUri, "Agile-6.1", actions, TestContext.TestRunResultsDirectory);

            var emptyMapDiffEngine = new DiffEngine(ProcessTemplateMap.Empty());

            var converted = factory.FromActiveTeamProject(TestCollectionUri, "Agile-6.1");

            var finalDifferences = emptyMapDiffEngine.CompareProcessTemplates(converted, goal);

            var reportBuilder = new ReportBuilder();
            var report = reportBuilder.WriteDifferencesToXml(finalDifferences);
            report.Save(Path.Combine(TestContext.TestRunResultsDirectory, TestContext.TestName + ".xml"));

            Assert.AreEqual(0, finalDifferences.Count(), "Should be zero differences between new Scrum 2.1 project and the converted Agile 6.1 project.");
        }
Пример #7
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                System.Console.WriteLine("usage: {0} <collection uri> <project name to morph> <project name to use as template>",
                    Process.GetCurrentProcess().ProcessName);
                return;
            }

            var collectionUri = new Uri(args[0]);
            var projectName = args[1];
            var templateProjectName = args[2];

            var factory = new ProcessTemplateFactory();

            var currentTemplate = factory.FromActiveTeamProject(collectionUri, projectName);
            var goalTemplate = factory.FromActiveTeamProject(collectionUri, templateProjectName);

            // TODO test for project property showing process template used and update after conversion

            var diffEngine = new DiffEngine(ProcessTemplateMap.ConvertScrum2ToAgile6());
            var differences = diffEngine.CompareProcessTemplates(currentTemplate, goalTemplate);

            var engine = new MorphEngine();

            var actions = engine.GenerateActions(differences);
            foreach (var action in actions)
            {
                System.Console.WriteLine(action.ToString());
            }

            //var filteredActions = actions.Where(a => !(a is DestroyWitdMorphAction)); // TODO optionally skip deleting extra work item items

            engine.Apply(collectionUri, projectName, actions, Path.GetTempPath()); //TODO replace temp path with something useful
        }
Пример #8
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();
                }
            }
        }
Пример #9
0
        public string GetDifferences(string first, string second)
        {
            DiffEngine   engine      = new DiffEngine();
            DiffListHtml source      = new DiffListHtml(StringUtil.RemoveTags(first));
            DiffListHtml destination = new DiffListHtml(StringUtil.RemoveTags(second));

            engine.ProcessDiff(source, destination, DiffEngineLevel.SlowPerfect);
            StringBuilder builder = new StringBuilder();

            foreach (DiffResultSpan span in engine.DiffReport())
            {
                if (span != null)
                {
                    switch (span.Status)
                    {
                    case DiffResultSpanStatus.NoChange:
                        this.Append(builder, first, span.SourceIndex, span.Length);
                        break;

                    case DiffResultSpanStatus.Replace:
                        this.Append(
                            builder,
                            first,
                            span.SourceIndex,
                            span.Length,
                            "green");
                        this.Append(
                            builder,
                            second,
                            span.DestIndex,
                            span.Length,
                            "red;text-decoration:line-through;font-weight:bold");
                        break;

                    case DiffResultSpanStatus.DeleteSource:
                        this.Append(
                            builder,
                            first,
                            span.SourceIndex,
                            span.Length,
                            "green;font-weight:bold");
                        break;

                    case DiffResultSpanStatus.AddDestination:
                        this.Append(
                            builder,
                            second,
                            span.DestIndex,
                            span.Length,
                            "red;text-decoration:line-through;font-weight:bold");
                        break;
                    }
                }
            }

            return(builder.ToString());
        }
Пример #10
0
        public DiffTokensCsvColumn(DiffConfiguration diffConfiguration)
            : base(diffConfiguration)
        {
            var stringWriter    = new StringWriter();
            var writer          = new TextSyntaxWriter(stringWriter);
            var mappingSettings = DiffEngine.GetMappingSettings(diffConfiguration);

            _diffWriter = new DiffCSharpWriter(writer, mappingSettings);
        }
Пример #11
0
    private void CompareLines(string line1, string line2, StringBuilder res1, StringBuilder res2, ref int changed, ref int added, ref int deleted)
    {
        DiffList_CharData s1 = new DiffList_CharData(line1);
        DiffList_CharData s2 = new DiffList_CharData(line2);
        DiffEngine        de = new DiffEngine();
        ArrayList         rep;
        int i = 0;

        de.ProcessDiff(s1, s2, DiffEngineLevel.SlowPerfect);
        rep = de.DiffReport();
        foreach (DiffResultSpan drs in rep)
        {
            switch (drs.Status)
            {
            case DiffResultSpanStatus.DeleteSource:
                res1.Append("<span style=\"background-color: #FBB2A7\">");
                for (i = 0; i < drs.Length; i++)
                {
                    res1.Append(s1.GetByIndex(drs.SourceIndex + i));
                    deleted++;
                }
                res1.Append("</span>");
                break;

            case DiffResultSpanStatus.AddDestination:
                res2.Append("<span style=\"background-color: #85D685\">");
                for (i = 0; i < drs.Length; i++)
                {
                    res2.Append(s2.GetByIndex(drs.DestIndex + i));
                    added++;
                }
                res2.Append("</span>");
                break;

            case DiffResultSpanStatus.NoChange:
                for (i = 0; i < drs.Length; i++)
                {
                    res1.Append(s1.GetByIndex(drs.SourceIndex + i));
                    res2.Append(s2.GetByIndex(drs.DestIndex + i));
                }
                break;

            case DiffResultSpanStatus.Replace:
                res1.Append("<span style=\"background-color: #75C5FF\">");
                res2.Append("<span style=\"background-color: #75C5FF\">");
                for (i = 0; i < drs.Length; i++)
                {
                    res1.Append(s1.GetByIndex(drs.SourceIndex + i));
                    res2.Append(s2.GetByIndex(drs.DestIndex + i));
                    changed++;
                }
                res1.Append("</span>");
                res2.Append("</span>");
                break;
            }
        }
    }
Пример #12
0
        //public static double StringSimilar(string sourceString, string checkString)
        public static DiffResult matchString(string sourceString, string checkString)
        {
            DiffEngine        diffEngine = new DiffEngine();
            DiffList_CharData source     = new DiffList_CharData(sourceString);
            DiffList_CharData dest       = new DiffList_CharData(checkString);
            var time   = diffEngine.ProcessDiff(source, dest);
            var report = diffEngine.DiffReport();

            string result       = "";
            int    addCount     = 0;
            int    deleteCount  = 0;
            int    replaceCount = 0;
            int    sameCount    = 0;

            foreach (DiffResultSpan diffResultSpan in report)
            {
                switch (diffResultSpan.Status)
                {
                case DiffResultSpanStatus.AddDestination:
                {
                    addCount += diffResultSpan.Length;
                    break;
                }

                case DiffResultSpanStatus.DeleteSource:
                {
                    deleteCount += diffResultSpan.Length;
                    break;
                }

                case DiffResultSpanStatus.Replace:
                {
                    for (int i = 0; i < diffResultSpan.Length; i++)
                    {
                        result += dest.GetByIndex(diffResultSpan.DestIndex + i);
                    }

                    replaceCount += diffResultSpan.Length;
                    break;
                }

                case DiffResultSpanStatus.NoChange:
                {
                    for (int i = 0; i < diffResultSpan.Length; i++)
                    {
                        result += dest.GetByIndex(diffResultSpan.DestIndex + i);
                    }

                    sameCount += diffResultSpan.Length;
                    break;
                }
                }
            }
            return(new DiffResult(addCount, deleteCount, replaceCount, sameCount));//(deleteCount) + "|" + result;
        }
Пример #13
0
        private void TextDiff(string sFile, string dFile)
        {
            this.Cursor = Cursors.Wait;

            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.Arrow;
                MessageBox.Show(ex.Message, "File Error");
                return;
            }

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

                ArrayList rep = de.DiffReport();
                Results   dlg = new Results(sLF, dLF, rep, time);
                try
                {
                    this.Hide();
                    dlg.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Unexpected Error!", MessageBoxButton.OKCancel, MessageBoxImage.Error,
                                    MessageBoxResult.None);
                    dlg.Close();
                }
                finally
                {
                    this.Show();
                }
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Arrow;
                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.Arrow;
        }
        public void Setup()
        {
            var source      = Path.Combine(this.sampleDataPath, "SonarSource.txt");
            var destination = Path.Combine(this.sampleDataPath, "LocalSource.txt");

            this.sLf = new DiffListTextFile(source);
            this.dLf = new DiffListTextFile(destination);
            this.de  = new DiffEngine();
            this.de.ProcessDiff(this.sLf, this.dLf, DiffEngineLevel.SlowPerfect);
            this.rep = this.de.DiffReport();
        }
        // Sitecore.Text.Diff.View.TwoCoumnsDiffView
        protected static void Compare(ref string value1, ref string value2)
        {
            DiffEngine diffEngine = new DiffEngine();
            string     value3     = value1;
            string     value4     = value2;

            value1 = StringUtil.RemoveTags(value1);
            value2 = StringUtil.RemoveTags(value2);
            DiffListHtml source      = new DiffListHtml(value1);
            DiffListHtml destination = new DiffListHtml(value2);

            diffEngine.ProcessDiff(source, destination, DiffEngineLevel.SlowPerfect);
            System.Collections.ArrayList arrayList      = diffEngine.DiffReport();
            System.Text.StringBuilder    stringBuilder  = new System.Text.StringBuilder();
            System.Text.StringBuilder    stringBuilder2 = new System.Text.StringBuilder();
            for (int i = 0; i < arrayList.Count; i++)
            {
                DiffResultSpan diffResultSpan = arrayList[i] as DiffResultSpan;
                if (diffResultSpan != null)
                {
                    switch (diffResultSpan.Status)
                    {
                    case DiffResultSpanStatus.NoChange:
                        Append(stringBuilder, value1, diffResultSpan.SourceIndex, diffResultSpan.Length);
                        Append(stringBuilder2, value2, diffResultSpan.DestIndex, diffResultSpan.Length);
                        break;

                    case DiffResultSpanStatus.Replace:
                        Append(stringBuilder, value1, diffResultSpan.SourceIndex, diffResultSpan.Length, "blue;font-weight:bold");
                        Append(stringBuilder2, value2, diffResultSpan.DestIndex, diffResultSpan.Length, "blue;font-weight:bold");
                        break;

                    case DiffResultSpanStatus.DeleteSource:
                        Append(stringBuilder, value1, diffResultSpan.SourceIndex, diffResultSpan.Length, "blue;font-weight:bold");
                        Append(stringBuilder2, value2, diffResultSpan.DestIndex, diffResultSpan.Length, "blue;font-weight:bold");
                        break;

                    case DiffResultSpanStatus.AddDestination:
                        Append(stringBuilder, value1, diffResultSpan.SourceIndex, diffResultSpan.Length, "blue;font-weight:bold");
                        Append(stringBuilder2, value2, diffResultSpan.DestIndex, diffResultSpan.Length, "blue;font-weight:bold");
                        break;
                    }
                }
            }

            if (arrayList.Count == 0 && (value3.Contains("<image") || value4.Contains("<image") || value3.Contains("<link") || value4.Contains("<link")))
            {
                stringBuilder.Append("<span>" + value3.Replace("<image", "< image").Replace("<link", "< link") + "</span>");
                stringBuilder2.Append("<span>" + value4.Replace("<image", "< image").Replace("<link", "< link") + "</span>");
            }

            value1 = stringBuilder.ToString();
            value2 = stringBuilder2.ToString();
        }
Пример #16
0
        public void DiffEqualShortTest()
        {
            const string xml = "<xml><hallo/></xml>";

            Knoten alt = Knoten.createOf(createDOM(XmlReader.Create(xml.ToStream())));
            Knoten neu = Knoten.createOf(createDOM(XmlReader.Create(xml.ToStream())));

            DiffEngine diff = new DiffEngine();
            Knoten     res  = diff.Diff(alt, neu);

            Assert.IsNull(res);
        }
Пример #17
0
        public void DiffEqualTest()
        {
            const string f_alt = @"diff-b1.xml";

            Knoten alt = Knoten.createOf(createDOM(XmlReader.Create(f_alt)));
            Knoten neu = Knoten.createOf(createDOM(XmlReader.Create(f_alt)));

            DiffEngine diff = new DiffEngine();
            Knoten     res  = diff.Diff(alt, neu);

            Assert.IsNull(res);
        }
Пример #18
0
        public void Compare()
        {
            TextDiff sourceDiffList = new TextDiff(_originalSourceText);
            TextDiff destDiffList   = new TextDiff(_originalDestText);

            DiffEngine de = new DiffEngine();

            de.ProcessDiff(sourceDiffList, destDiffList, DiffEngineLevel.Medium);
            ArrayList rep = de.DiffReport();

            DisplayDiff(sourceDiffList, destDiffList, rep);
        }
Пример #19
0
        private static ArrayList GetFileChanges(string source, string destinationPath)
        {
            DiffList_TextFile sourceFile      = new DiffList_TextFile(source.Split('\n'));
            DiffList_TextFile destinationFile = new DiffList_TextFile(destinationPath);
            DiffEngine        diffEngine      = new DiffEngine();

            diffEngine.ProcessDiff(sourceFile, destinationFile, DiffEngineLevel.FastImperfect);

            ArrayList differenceList = diffEngine.DiffReport();

            return(differenceList);
        }
Пример #20
0
        public void GetPatchOperations5()
        {
            DiffEngine <long> diffEngine = new DiffEngine <long>(
                new long[] { 1, 2, 3 }, new long[] { 2, 3 });

            PatchOperation[] expectedPatchOperations =
                new PatchOperation[] {
                PatchOperation.CreateDeletion(0, 0),
                PatchOperation.CreateCopy(1, 2)
            };

            AssertDifferences(diffEngine, expectedPatchOperations);
        }
Пример #21
0
        private static void AssertDifferences <T>(DiffEngine <T> diffEngine,
                                                  PatchOperation[] expectedPatchOperations)
        {
            PatchOperationCollection patchOperations = diffEngine.GetPatchOperations();

            Assert.AreEqual(expectedPatchOperations.GetLength(0), patchOperations.Count);

            for (int index = 0; index < patchOperations.Count; ++index)
            {
                Assert.AreEqual(expectedPatchOperations[index], patchOperations[index],
                                string.Format("Collections differ at index {0}", index));
            }
        }
Пример #22
0
        private void btnDiff_Click(object sender, EventArgs e)
        {
            TextFileDiffList sLF        = null;
            TextFileDiffList dLF        = null;
            string           sourceFile = null;
            string           targetFile = null;

            try
            {
                _edSvc.SyncSessionCopy();
                var set = XmlCompareUtil.PrepareForComparison(_edSvc.CurrentConnection.ResourceService,
                                                              _edSvc.ResourceID,
                                                              _edSvc.EditedResourceID);
                sLF = set.Source;
                dLF = set.Target;
            }
            catch (Exception ex)
            {
                ErrorDialog.Show(ex);
                return;
            }
            finally
            {
                try { File.Delete(sourceFile); }
                catch { }
                try { File.Delete(targetFile); }
                catch { }
            }

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

                var          rep = de.DiffReport();
                TextDiffView dlg = new TextDiffView(sLF, dLF, rep, time);
                dlg.SetLabels(_edSvc.ResourceID, Strings.EditedResource);
                dlg.ShowDialog();
                dlg.Dispose();
            }
            catch (Exception ex)
            {
                string nl  = Environment.NewLine;
                string tmp = $"{ex.Message}{nl}{nl}***STACK***{nl}{ex.StackTrace}";
                MessageBox.Show(tmp, Strings.CompareError);
                return;
            }
        }
Пример #23
0
        public void GetPatchOperations2()
        {
            DiffEngine <string> diffEngine =
                new DiffEngine <string>(
                    new string[] { "a", "b", "c", "d" },
                    new string[] { "c", "d" });

            PatchOperation[] expectedPatchOperations =
                new PatchOperation[] {
                PatchOperation.CreateDeletion(0, 1),
                PatchOperation.CreateCopy(2, 3)
            };

            AssertDifferences(diffEngine, expectedPatchOperations);
        }
Пример #24
0
        public void Should_find_no_differences_between_Scrum_project_and_template()
        {
            Assert.Inconclusive("Templates naturally have differences from the projects they create");

            var factory = new ProcessTemplateFactory();

            var collectionTemplate = factory.FromCollectionTemplates(TestCollectionUri, "Microsoft Visual Studio Scrum 2.1");
            var activeProject = factory.FromActiveTeamProject(TestCollectionUri, "Scrum-2.1");

            var diffEngine = new DiffEngine(ProcessTemplateMap.Empty());

            var differences = diffEngine.CompareProcessTemplates(activeProject, collectionTemplate);

            Assert.AreEqual(0, differences.Count(), "Should be zero differences between new Scrum 2.1 project and the template it was created from.");
        }
Пример #25
0
        public void GetPatchOperations9()
        {
            DiffEngine <string> diffEngine =
                new DiffEngine <string>(
                    new string[] { "same", "same", "same", "", "same", "del", "", "del" },
                    new string[] { "ins", "", "same", "same", "same", "", "same" });

            PatchOperation[] expectedPatchOperations =
                new PatchOperation[] {
                PatchOperation.CreateAddition(0, 1),
                PatchOperation.CreateCopy(0, 4),
                PatchOperation.CreateDeletion(5, 7)
            };

            AssertDifferences(diffEngine, expectedPatchOperations);
        }
Пример #26
0
        public void GetPatchOperations4()
        {
            DiffEngine <string> diffEngine =
                new DiffEngine <string>(
                    new string[] { "a", "b", "c", "d", "e" },
                    new string[] { "a", "x", "y", "b", "c", "j", "e", });

            PatchOperation[] expectedPatchOperations =
                new PatchOperation[] {
                PatchOperation.CreateCopy(0, 0),
                PatchOperation.CreateAddition(1, 2),
                PatchOperation.CreateCopy(1, 2),
                PatchOperation.CreateAddition(5, 5),
                PatchOperation.CreateDeletion(3, 3),
                PatchOperation.CreateCopy(4, 4)
            };

            AssertDifferences(diffEngine, expectedPatchOperations);
        }
Пример #27
0
        private void btnCompare_Click(object sender, EventArgs e)
        {
            bool bValid = true;

            if (string.IsNullOrEmpty(txtSource.Text))
            {
                errorProvider.SetError(txtSource, Strings.Required);
                bValid = false;
            }
            else
            {
                errorProvider.SetError(txtSource, null);
            }
            if (string.IsNullOrEmpty(txtTarget.Text))
            {
                errorProvider.SetError(txtTarget, Strings.Required);
                bValid = false;
            }
            else
            {
                errorProvider.SetError(txtTarget, null);
            }

            if (bValid)
            {
                var set = XmlCompareUtil.PrepareForComparison(_conn.ResourceService,
                                                              this.Source,
                                                              this.Target);

                double     time = 0;
                DiffEngine de   = new DiffEngine();
                time = de.ProcessDiff(set.Source, set.Target, DiffEngineLevel.SlowPerfect);

                var rep = de.DiffReport();
                using (TextDiffView dlg = new TextDiffView(set.Source, set.Target, rep, time))
                {
                    dlg.SetLabels(this.Source, this.Target);
                    dlg.ShowDialog();
                    this.Close();
                }
            }
        }
Пример #28
0
    private int GetOutOfOrderElements(string[] source, string[] dest)
    {
        DiffEngine differ = new DiffEngine();

        differ.ProcessDiff(new DiffList_TextFile(source), new DiffList_TextFile(dest));
        ArrayList diffs = differ.DiffReport();

        diffs.TrimToSize();
        Debug.Log("Diffs found: " + diffs.Count);
        int errors = 0;

        foreach (DiffResultSpan diff in diffs)
        {
            if (!diff.Status.Equals("NoChange"))
            {
                errors += diff.Length;
            }
            Debug.Log("diff: " + diff);
        }
        return(diffs.Count / 2);
    }
Пример #29
0
        private void TextDiff(string oldText, string newText)
        {
            this.Cursor = Cursors.WaitCursor;

            DiffList_TextFile sLF = null;
            DiffList_TextFile dLF = null;

            try
            {
                sLF = new DiffList_TextFile(oldText);
                dLF = new DiffList_TextFile(newText);
            }
            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();
                CompareFiles(sLF, dLF, rep, time);
            }
            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;
        }
        protected static string Compare(string value1, string value2)
        {
            DiffEngine diffEngine = new DiffEngine();

            value1 = StringUtil.RemoveTags(value1);
            value2 = StringUtil.RemoveTags(value2);
            DiffListHtml source      = new DiffListHtml(value1);
            DiffListHtml destination = new DiffListHtml(value2);

            diffEngine.ProcessDiff(source, destination, DiffEngineLevel.SlowPerfect);
            System.Collections.ArrayList arrayList     = diffEngine.DiffReport();
            System.Text.StringBuilder    stringBuilder = new System.Text.StringBuilder();
            for (int i = 0; i < arrayList.Count; i++)
            {
                DiffResultSpan diffResultSpan = arrayList[i] as DiffResultSpan;
                if (diffResultSpan != null)
                {
                    switch (diffResultSpan.Status)
                    {
                    case DiffResultSpanStatus.NoChange:
                        Append(stringBuilder, value1, diffResultSpan.SourceIndex, diffResultSpan.Length);
                        break;

                    case DiffResultSpanStatus.Replace:
                        Append(stringBuilder, value1, diffResultSpan.SourceIndex, diffResultSpan.Length, "green");
                        Append(stringBuilder, value2, diffResultSpan.DestIndex, diffResultSpan.Length, "red; text-decoration:line-through;font-weight:bold");
                        break;

                    case DiffResultSpanStatus.DeleteSource:
                        Append(stringBuilder, value1, diffResultSpan.SourceIndex, diffResultSpan.Length, "green;font-weight:bold");
                        break;

                    case DiffResultSpanStatus.AddDestination:
                        Append(stringBuilder, value2, diffResultSpan.DestIndex, diffResultSpan.Length, "red; text-decoration:line-through;font-weight:bold");
                        break;
                    }
                }
            }
            return(stringBuilder.ToString());
        }
Пример #31
0
        private void TextDiff(string sFile, string dFile)
        {
            DiffList_TextFile sLF = null;
            DiffList_TextFile dLF = null;

            try
            {
                sLF = new DiffList_TextFile(sFile);
                dLF = new DiffList_TextFile(dFile);
            }
            catch (Exception ex)
            {
                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();
                string[]  res = getResults(dLF, rep);
                if (res != null)
                {
                    string[] filesplit = dFile.Split('\\');
                    string   filename  = filesplit.Last();
                    File.WriteAllLines(folderPath + "\\SetItUp_Registry\\" + filename, res);
                }
            }
            catch (Exception ex)
            {
                string tmp = string.Format("{0}{1}{1}***STACK***{1}{2}",
                                           ex.Message,
                                           Environment.NewLine,
                                           ex.StackTrace);
                MessageBox.Show(tmp, "Compare Error");
                return;
            }
        }
Пример #32
0
        public void GetPatchOperations6()
        {
            DiffEngine <string> diffEngine =
                new DiffEngine <string>(
                    new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" },
                    new string[] {
                "a", "b", "p", "q", "r", "s", "t", "c", "d", "e", "f", "g", "h",
                "i", "j", "u", "l"
            });

            PatchOperation[] expectedPatchOperations =
                new PatchOperation[] {
                PatchOperation.CreateCopy(0, 1),
                PatchOperation.CreateAddition(2, 6),
                PatchOperation.CreateCopy(2, 9),
                PatchOperation.CreateAddition(15, 15),
                PatchOperation.CreateDeletion(10, 10),
                PatchOperation.CreateCopy(11, 11)
            };

            AssertDifferences(diffEngine, expectedPatchOperations);
        }
Пример #33
0
        public void GetPatchOperations7()
        {
            DiffEngine <string> diffEngine =
                new DiffEngine <string>(
                    new string[] {
                "a", "a", "a", "a", "b", "b", "b", "a", "a", "a", "a", "b", "b", "b", "a", "a",
                "a", "a", "b", "b", "b", "a", "a", "a", "a", "b", "b", "b"
            },
                    new string[] {
                "a", "a", "a", "a", "b", "b", "b", "a", "b", "b", "b", "a", "a", "a", "a"
            });

            PatchOperation[] expectedPatchOperations =
                new PatchOperation[] {
                PatchOperation.CreateCopy(0, 7),
                PatchOperation.CreateDeletion(8, 10),
                PatchOperation.CreateCopy(11, 17),
                PatchOperation.CreateDeletion(18, 27)
            };

            AssertDifferences(diffEngine, expectedPatchOperations);
        }
        protected static List<MorphAction> GenerateActionsViaDiffEngine()
        {
            if (_actionsViaDiffEngine != null) return _actionsViaDiffEngine;

            using (var agileTemplate = EmbeddedProcessTemplate.Agile6())
            using (var scrumTemplate = EmbeddedProcessTemplate.Scrum2())
            {
                var agileReader = new ProcessTemplateReader(agileTemplate.TemplatePath);
                var scrumReader = new ProcessTemplateReader(scrumTemplate.TemplatePath);

                var processTemplateMap = ProcessTemplateMap.ConvertScrum2ToAgile6();

                var currentProcessTemplate = new ProcessTemplate {WorkItemTypeDefinitions = new ReadOnlyCollection<WorkItemTypeDefinition>(scrumReader.WorkItemTypeDefinitions.ToArray())};
                var goalProcessTemplate = new ProcessTemplate {WorkItemTypeDefinitions = new ReadOnlyCollection<WorkItemTypeDefinition>(agileReader.WorkItemTypeDefinitions.ToArray())};

                var diffEngine = new DiffEngine(processTemplateMap);
                var differences = diffEngine.CompareProcessTemplates(currentProcessTemplate, goalProcessTemplate);

                var morphEngine = new MorphEngine();
                _actionsViaDiffEngine = morphEngine.GenerateActions(differences).ToList();
            }

            return _actionsViaDiffEngine;
        }
Пример #35
0
        /// <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();
        }
Пример #36
0
	private void CompareLines(string line1, string line2, StringBuilder res1, StringBuilder res2, ref int changed, ref int added, ref int deleted)
	{
		DiffList_CharData s1 = new DiffList_CharData(line1);
		DiffList_CharData s2 = new DiffList_CharData(line2);
		DiffEngine de = new DiffEngine();
		ArrayList rep;
		int i = 0;

		de.ProcessDiff(s1, s2, DiffEngineLevel.SlowPerfect);
		rep = de.DiffReport();
		foreach (DiffResultSpan drs in rep)
		{
			switch (drs.Status)
			{
				case DiffResultSpanStatus.DeleteSource:
					res1.Append("<span style=\"background-color: #FBB2A7\">");
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append(s1.GetByIndex(drs.SourceIndex + i));
						deleted++;
					}
					res1.Append("</span>");
					break;
				case DiffResultSpanStatus.AddDestination:
					res2.Append("<span style=\"background-color: #85D685\">");
					for (i = 0; i < drs.Length; i++)
					{
						res2.Append(s2.GetByIndex(drs.DestIndex + i));
						added++;
					}
					res2.Append("</span>");
					break;
				case DiffResultSpanStatus.NoChange:
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append(s1.GetByIndex(drs.SourceIndex + i));
						res2.Append(s2.GetByIndex(drs.DestIndex + i));
					}
					break;
				case DiffResultSpanStatus.Replace:
					res1.Append("<span style=\"background-color: #75C5FF\">");
					res2.Append("<span style=\"background-color: #75C5FF\">");
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append(s1.GetByIndex(drs.SourceIndex + i));
						res2.Append(s2.GetByIndex(drs.DestIndex + i));
						changed++;
					}
					res1.Append("</span>");
					res2.Append("</span>");
					break;
			}
		}
	}
Пример #37
0
	private void CompareArticles(string ver1, string ver2, ref string leftRes, ref string rightRes)
	{
		System.Text.StringBuilder res1 = new System.Text.StringBuilder();
		System.Text.StringBuilder res2 = new System.Text.StringBuilder();
		DiffList_StringData s1 = new DiffList_StringData(ver1);
		DiffList_StringData s2 = new DiffList_StringData(ver2);
		DiffEngine de = new DiffEngine();
		ArrayList rep;
		int i = 0, count1 = 1, count2 = 1;
		int linesupdated = 0, linesadded = 0, linesdeleted = 0;
		int symbolschanged = 0, symbolsadded = 0, symbolsdeleted = 0;

		de.ProcessDiff(s1, s2, DiffEngineLevel.SlowPerfect);
		rep = de.DiffReport();

		foreach (DiffResultSpan drs in rep)
		{
			switch (drs.Status)
			{
				case DiffResultSpanStatus.DeleteSource:
					res1.Append("<a name=\"left_" + count1.ToString("0000") + "\">" + "</a>\r\n");
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append(count1.ToString("0000") + "&nbsp;&nbsp;");
						res1.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #FF7863\">");
						res1.Append(((TextLine)s1.GetByIndex(drs.SourceIndex + i)).Line + "<br />");
						res1.Append("</span>");
						res2.Append("<br />");
						count1++;
						linesdeleted++;
					}
					break;
				case DiffResultSpanStatus.NoChange: 
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append(count1.ToString("0000") + "&nbsp;&nbsp;");
						res2.Append(count2.ToString("0000") + "&nbsp;&nbsp;");
						res1.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
						res2.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
						res1.Append(((TextLine)s1.GetByIndex(drs.SourceIndex + i)).Line + "<br />");
						res2.Append(((TextLine)s2.GetByIndex(drs.DestIndex + i)).Line + "<br />");
						count1++; count2++;
					}
					break;
				case DiffResultSpanStatus.AddDestination:
					res1.Append("<a name=\"right_" + count2.ToString("0000") + "\">" + "</a>\r\n");
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append("<br />");
						res2.Append(count2.ToString("0000") + "&nbsp;&nbsp;");
						res2.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #54C954\">");
						res2.Append(((TextLine)s2.GetByIndex(drs.DestIndex + i)).Line + "<br />");
						res2.Append("</span>");
						count2++;
						linesadded++;
					}
					break;
				case DiffResultSpanStatus.Replace:
					res1.Append("<a name=\"left_" + count1.ToString("0000") + "\">" + "</a>\r\n");
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append(count1.ToString("0000") + "&nbsp;&nbsp;");
						res2.Append(count2.ToString("0000") + "&nbsp;&nbsp;");
						res1.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #C1E5FF\">");
						res2.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #C1E5FF\">");
						CompareLines(((TextLine)s1.GetByIndex(drs.SourceIndex + i)).Line, ((TextLine)s2.GetByIndex(drs.DestIndex + i)).Line, res1, res2, ref symbolschanged, ref symbolsadded, ref symbolsdeleted);
						res1.Append("</span>");
						res2.Append("</span>");
						res1.Append("<br />");
						res2.Append("<br />");
						count1++; count2++;
						linesupdated++;
					}
					break;
			}
		}
		CollectLinesStats(linesupdated, linesadded, linesdeleted);
		CollectSymbolsStats(symbolschanged, symbolsadded, symbolsdeleted);
		leftRes = res1.ToString();
		rightRes = res2.ToString();
	}
Пример #38
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;
 }
Пример #39
0
        /// <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();
        }