Esempio n. 1
0
        public void DemoDiffOfAdditionToLargeText()
        {
            var text1 = @"I am the very model of a modern Major-General,
I've information vegetable, animal, and mineral,
I know the kings of England, and I quote the fights historical,
From Marathon to Waterloo, in order categorical.

I am the very model of a cartoon individual,
My animation's comical, unusual, and whimsical,
I'm quite adept at funny gags, comedic theory I have read,
From wicked puns and stupid jokes to anvils that drop on your head.";

            var text2 = @"I am the very model of a modern Major-General,
I've information vegetable, animal, and mineral,
I know the kings of England, and I quote the fights historical,
From Marathon to Waterloo, in order categorical.

I am the very model of a cartoon individual,
My animation's comical, unusual, and whimsical,
I'm quite adept at funny gags, comedic theory I have read,
From wicked puns and stupid jokes to anvils that drop on your head.

And that is all I have to say about that.";

            var sut = new DiffMatchPatch();

            sut.DiffTimeout = 0;
            var diffs = sut.DiffMain(text1, text2);

            sut.DiffCleanupEfficiency(diffs);
            var patches = sut.PatchMake(diffs);
            var patch   = sut.PatchToText(patches);

            Approvals.Verify(patch);
        }
Esempio n. 2
0
        public static void Patch(this TableOperations <MeterConfiguration> meterConfigurationTable, MeterConfiguration meterConfiguration, string newConfigText)
        {
            string unpatchedText = Unpatch(meterConfigurationTable, meterConfiguration);

            DiffMatchPatch patchProvider = new DiffMatchPatch();
            List <Patch>   patches       = patchProvider.PatchMake(newConfigText, unpatchedText);

            if (patches.Count > 0)
            {
                MeterConfiguration newConfiguration = new MeterConfiguration();
                newConfiguration.MeterID       = meterConfiguration.MeterID;
                newConfiguration.ConfigKey     = meterConfiguration.ConfigKey;
                newConfiguration.ConfigText    = newConfigText;
                newConfiguration.RevisionMajor = newConfiguration.RevisionMajor + 1;
                newConfiguration.RevisionMinor = 0;
                meterConfigurationTable.AddNewRecord(newConfiguration);

                meterConfiguration.DiffID     = meterConfigurationTable.Connection.ExecuteScalar <int>("SELECT @@IDENTITY");
                meterConfiguration.ConfigText = patchProvider.PatchToText(patches);
                meterConfigurationTable.UpdateRecord(meterConfiguration);
            }
        }