public ModelDelta Revert(IDataModel model)
        {
            var reverse = new ModelDelta {
                HasDataChange = HasDataChange
            };

            foreach (var kvp in oldData)
            {
                var(index, data)       = (kvp.Key, kvp.Value);
                reverse.oldData[index] = model[index];
                model[index]           = data;
            }

            foreach (var kvp in addedRuns)
            {
                reverse.removedRuns[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedRuns)
            {
                reverse.addedRuns[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in addedNames)
            {
                reverse.removedNames[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedNames)
            {
                reverse.addedNames[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in addedUnmappedPointers)
            {
                reverse.removedUnmappedPointers[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedUnmappedPointers)
            {
                reverse.addedUnmappedPointers[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in addedMatchedWords)
            {
                reverse.removedMatchedWords[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedMatchedWords)
            {
                reverse.addedMatchedWords[kvp.Key] = kvp.Value;
            }

            model.MassUpdateFromDelta(addedRuns, removedRuns, addedNames, removedNames, addedUnmappedPointers, removedUnmappedPointers, addedMatchedWords, removedMatchedWords);

            return(reverse);
        }
Example #2
0
        public ModelDelta Revert(IDataModel model)
        {
            var reverse = new ModelDelta {
                HasDataChange = HasDataChange
            };

            foreach (var kvp in oldData)
            {
                var(index, data)       = (kvp.Key, kvp.Value);
                reverse.oldData[index] = model.Count > index ? model[index] : (byte)0xFF;
                if (model.Count > index)
                {
                    model[index] = data;
                }
            }

            foreach (var kvp in addedRuns)
            {
                reverse.removedRuns[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedRuns)
            {
                reverse.addedRuns[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in addedNames)
            {
                reverse.removedNames[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedNames)
            {
                reverse.addedNames[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in addedLists)
            {
                reverse.removedLists[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedLists)
            {
                reverse.addedLists[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in addedMatchedWords)
            {
                reverse.removedMatchedWords[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedMatchedWords)
            {
                reverse.addedMatchedWords[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in addedOffsetPointers)
            {
                reverse.removedOffsetPointers[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedOffsetPointers)
            {
                reverse.addedOffsetPointers[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in addedUnmappedPointers)
            {
                reverse.removedUnmappedPointers[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedUnmappedPointers)
            {
                reverse.addedUnmappedPointers[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in addedUnmappedConstants)
            {
                reverse.removedUnmappedConstants[kvp.Key] = kvp.Value;
            }
            foreach (var kvp in removedUnmappedConstants)
            {
                reverse.addedUnmappedConstants[kvp.Key] = kvp.Value;
            }

            if (oldDataLength != -1 || newDataLength != -1)
            {
                model.ExpandData(reverse, oldDataLength - 1);
                model.ContractData(reverse, oldDataLength - 1);
            }

            model.MassUpdateFromDelta(addedRuns, removedRuns,
                                      addedNames, removedNames,
                                      addedUnmappedPointers, removedUnmappedPointers,
                                      addedMatchedWords, removedMatchedWords,
                                      addedOffsetPointers, removedOffsetPointers,
                                      addedUnmappedConstants, removedUnmappedConstants,
                                      addedLists, removedLists);

            return(reverse);
        }