/// <summary>
 /// Does/Redoes the command</summary>
 public override void Do()
 {
     for (int i = 0; i < m_commands.Count; ++i)
     {
         Command command = m_commands[i];
         // if a command can't be completed successfully, back up to consistent state
         bool success = false;
         try
         {
             command.Do();
             success = true;
         }
         finally
         {
             if (!success)
             {
                 for (--i; i >= 0; --i)
                 {
                     Command done = m_commands[i];
                     done.Undo();
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Redo the last "undone" command</summary>
        /// <returns>Last Command undone</returns>
        public Command Redo()
        {
            if (!CanRedo)
            {
                throw new InvalidOperationException("Can't redo");
            }

            Command command = m_commands[m_commandCount.Current];

            m_commandCount.Increment();

            command.Do();

            OnCommandDone();

            return(command);
        }