コード例 #1
0
        public void Execute(RedoCommand command)
        {
            IsUndoRedo = true;
            Repository = Container.Resolve <IRepository>();
            var redoGroup = Repository.All <RedoItem>().GroupBy(p => p.Group).LastOrDefault();

            if (redoGroup == null)
            {
                return;
            }
            foreach (var redoItem in redoGroup)
            {
                // Create redo item
                var undoItem = InvertJsonExtensions.DeserializeObject(typeof(UndoItem), JSON.Parse(redoItem.UndoData)) as UndoItem;


                if (redoItem.Type == UndoType.Inserted)
                {
                    var record = Repository.GetById <IDataRecord>(redoItem.DataRecordId);

                    Repository.Remove(record);
                }
                else if (redoItem.Type == UndoType.Removed)
                {
                    var obj = InvertJsonExtensions.DeserializeObject(Type.GetType(redoItem.RecordType), JSON.Parse(redoItem.Data).AsObject) as IDataRecord;
                    Repository.Add(obj);
                }
                else
                {
                    var record = Repository.GetById <IDataRecord>(redoItem.DataRecordId);
                    // We don't want to signal any events on deserialization
                    record.Repository = null;
                    InvertJsonExtensions.DeserializeExistingObject(record, JSON.Parse(redoItem.Data).AsObject);
                    record.Changed    = true;
                    record.Repository = Repository;
                }
                Repository.Remove(redoItem);
                Repository.Add(undoItem);
            }
            IsUndoRedo = false;
            Repository.Commit();
        }
コード例 #2
0
        public void Execute(UndoCommand command)
        {
            Repository = Container.Resolve <IRepository>();
            var undoGroup = Repository.All <UndoItem>().GroupBy(p => p.Group).LastOrDefault();

            if (undoGroup == null)
            {
                return;
            }
            IsUndoRedo = true;
            try
            {
                foreach (var undoItem in undoGroup)
                {
                    // Create redo item
                    var redoItem = new RedoItem();
                    redoItem.Data         = undoItem.Data;
                    redoItem.Group        = undoItem.Group;
                    redoItem.DataRecordId = undoItem.DataRecordId;
                    redoItem.Name         = undoItem.Name;
                    redoItem.Time         = undoItem.Time;
                    redoItem.Type         = undoItem.Type;
                    redoItem.RecordType   = undoItem.RecordType;
                    redoItem.UndoData     = InvertJsonExtensions.SerializeObject(undoItem).ToString();

                    if (undoItem.Type == UndoType.Inserted)
                    {
                        var record = Repository.GetById <IDataRecord>(undoItem.DataRecordId);
                        redoItem.Data = InvertJsonExtensions.SerializeObject(record).ToString();
                        Repository.Remove(record);
                        redoItem.Type = UndoType.Removed;
                    }
                    else if (undoItem.Type == UndoType.Removed)
                    {
                        var obj =
                            InvertJsonExtensions.DeserializeObject(Type.GetType(undoItem.RecordType),
                                                                   JSON.Parse(undoItem.Data).AsObject) as IDataRecord;
                        Repository.Add(obj);
                        redoItem.Type = UndoType.Inserted;
                        redoItem.Data = InvertJsonExtensions.SerializeObject(obj).ToString();
                    }
                    else
                    {
                        var record = Repository.GetById <IDataRecord>(undoItem.DataRecordId);
                        // We don't want to signal any events on deserialization
                        record.Repository = null;
                        redoItem.Data     = InvertJsonExtensions.SerializeObject(record).ToString();
                        InvertJsonExtensions.DeserializeExistingObject(record, JSON.Parse(undoItem.Data).AsObject);
                        record.Changed    = true;
                        record.Repository = Repository;
                    }
                    Repository.Remove(undoItem);
                    Repository.Add(redoItem);
                }
            }
            catch (Exception ex)
            {
                // If we don't catch the exception IsUndoRedo won't be set back to fals causing cascading issues
            }
            IsUndoRedo = false;
            Repository.Commit();
        }