Exemplo n.º 1
0
 private static State Apply(State state, Command.ChangeDiameter command)
 {
     return(new State(
                state.Circles,
                command.Circle,
                new[] { command }.Concat(state.UndoStack).ToArray(),
                Enumerable.Empty <ICommand>()
                ));
 }
Exemplo n.º 2
0
        private static State Redo(State state, Command.ChangeDiameter command)
        {
            var circle = state.Circles.Where(c => c.Equals(command.Circle)).First();

            circle.Diameter = command.Diameter;

            return(new State(
                       state.Circles,
                       command.Circle,
                       new[] { command }.Concat(state.UndoStack).ToArray(),
                       state.RedoStack.Except(new[] { command }).ToArray()
                       ));
        }
Exemplo n.º 3
0
        private static State Undo(State state, Command.ChangeDiameter command)
        {
            var previousDiameter = state.UndoStack
                                   .OfType <Command.ChangeDiameter>()
                                   .Where(c => !c.Equals(command) && c.Circle.Equals(command.Circle))
                                   .Select(c => (int?)c.Diameter)
                                   .FirstOrDefault() ?? Logic.InitialDiameter;

            var circle = state.Circles
                         .Where(c => c.Equals(command.Circle))
                         .First();

            circle.Diameter = previousDiameter;

            return(new State(
                       state.Circles,
                       command.Circle,
                       state.UndoStack.Except(new[] { command }).ToArray(),
                       new[] { command }.Concat(state.RedoStack).ToArray()
                       ));
        }