private IEvent _Undo(bool countNonActionable = true) // TODO
        {
            IEvent e = allEvents.Pop();                      // Make method for this

            if (e is IActionableEvent)
            {
                IBaseCommand undoCommand = (e as IActionableEvent).NewUndoCommand();
                if (undoCommand is IEntityModifier)
                {
                    IEntityModifier m = (undoCommand as IEntityModifier);
                    Assert.IsTrue(m is IEventProducing);
                    (m as IEventProducing).DontRecordEvent = true;
                    EM.ApplyMod(m);
                }
                else if (undoCommand is IIndependentModifier)
                {
                    IIndependentModifier m = (undoCommand as IIndependentModifier);
                    Assert.IsTrue(m is IEventProducing);
                    (m as IEventProducing).DontRecordEvent = true;
                    EM.ApplyMod(m);
                }
                else if (undoCommand is Command)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    throw new Exception("Cannot apply undo command: " + undoCommand.GetType().Name);
                }
            }

            return(e);
        }
示例#2
0
文件: Commands.cs 项目: zOrder/ugui
        void OnFinish(IBaseCommand command)
        {
            Type type = command.GetType();
            Queue <IBaseCommand> cached;

            if (!_cache.TryGetValue(type, out cached))
            {
                _cache[type] = cached = new Queue <IBaseCommand>();
            }

            cached.Enqueue(command);
            _retained.Remove(command);
        }
示例#3
0
        public IDictionary <string, object> Serialize(IBaseCommand command)
        {
            var properties = command.GetType().GetRuntimeProperties().Where(p => p.CanRead && p.CanWrite);

            return(properties.ToDictionary(p => p.Name, p => p.GetValue(command)));
        }