Esempio n. 1
0
        public static string Unpatch(this TableOperations <MeterConfiguration> meterConfigurationTable, MeterConfiguration meterConfiguration)
        {
            DiffMatchPatch patchProvider = new DiffMatchPatch();

            string ToSheetText(MeterConfiguration config)
            {
                if (config.DiffID == null)
                {
                    return(config.ConfigText);
                }

                MeterConfiguration configToPatch = meterConfigurationTable.QueryRecordWhere("ID = {0}", config.DiffID);
                List <Patch>       patches       = patchProvider.PatchFromText(config.ConfigText);
                string             sheetToPatch  = ToSheetText(configToPatch);

                return((string)patchProvider.PatchApply(patches, sheetToPatch)[0]);
            }

            return(ToSheetText(meterConfiguration));
        }
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);
            }
        }
Esempio n. 3
0
        public static void PatchLatestConfiguration(this TableOperations <MeterConfiguration> meterConfigurationTable, Meter meter, string configKey, string newConfigText)
        {
            RecordRestriction latestConfigurationQueryRestriction =
                new RecordRestriction("MeterID = {0}", meter.ID) &
                new RecordRestriction("ConfigKey = {0}", configKey) &
                new RecordRestriction("DiffID IS NULL");

            MeterConfiguration latestConfiguration = meterConfigurationTable.QueryRecord("RevisionMajor DESC, RevisionMinor DESC", latestConfigurationQueryRestriction);

            if (latestConfiguration == null)
            {
                MeterConfiguration newConfiguration = new MeterConfiguration();
                newConfiguration.MeterID       = meter.ID;
                newConfiguration.ConfigKey     = configKey;
                newConfiguration.ConfigText    = newConfigText;
                newConfiguration.RevisionMajor = 0;
                newConfiguration.RevisionMinor = 0;
                meterConfigurationTable.AddNewRecord(newConfiguration);
                return;
            }

            meterConfigurationTable.Patch(latestConfiguration, newConfigText);
        }