Exemple #1
0
        private PatchSets LockedUpdate(VersionedWikiPage page, int revisionToPatch, List<Patch> patches)
        {
            var patchingCurrentRevision = revisionToPatch == page.RevisionNumber;

            var previousRevision = page.Revision;
            var newText = (string)this.patcher.patch_apply(patches, previousRevision.Text)[0];
            if (newText != previousRevision.Text)
                page.Revision = new WikiPageRevision(page.RevisionNumber + 1, newText);

            if (patchingCurrentRevision) {
                Debug.WriteLine(string.Format("Accepted {0}=>{1}.", revisionToPatch, page.RevisionNumber));
                return new PatchSets(
                    patchesForAuthor: new Patch[0],
                    patchesForOthers: patches
                );
            }
            else {
                Debug.WriteLine(string.Format(
                    "Upgraded {0}=>{1} to {2}=>{3}.",
                    revisionToPatch, revisionToPatch + 1, previousRevision.Number, page.RevisionNumber
                ));
                return new PatchSets(
                    patchesForAuthor: this.patcher.patch_make(page.AllRevisions[revisionToPatch].Text, page.Text),
                    patchesForOthers: this.patcher.patch_make(previousRevision.Text, page.Text)
                );
            }
        }
        public void TestConflictResolution(string original, string changeOne, string changeTwo, string expected)
        {
            var patcher = new diff_match_patch();
            var patchOne = patcher.patch_toText(patcher.patch_make(original, changeOne));
            var patchTwo = patcher.patch_toText(patcher.patch_make(original, changeTwo));

            var page = new VersionedWikiPage("test", original);
            var updater = new WikiPageUpdater(patcher);

            updater.ApplyUpdate(page, 0, patchOne);
            updater.ApplyUpdate(page, 0, patchTwo);

            Assert.AreEqual(expected, page.Text);
        }