Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            // canonical
            var rec     = new Receiver();
            var command = new ConcreteCommand(rec);
            var invoker = new Invoker();

            invoker.SetCommand(command);
            invoker.ExecuteCommand();
            Console.WriteLine();

            // live
            var user = new User();

            user.Compute('+', 100);
            user.Compute('-', 30);
            user.Compute('*', -1);

            user.Undo(3);
            user.Undo(3);

            user.Redo(2);
            user.Redo(2);
            user.Redo(2);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            user = new User();

            /*
             * user.Compute('+', 100);
             * user.Compute('-', 50);
             * user.Compute('*', 10);
             * user.Compute('/', 2);
             *
             * user.Undo(4);
             *
             * user.Compute('+', 100);
             * user.Compute('+', 100);
             * user.Compute('+', 100);
             * user.Undo(3);
             */

            user.Compute('+', 100);
            user.Undo(1);
            user.Compute('+', 50);
            user.Undo(1);


            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            // Crea un usuario y deja que compute

            User user = new User();

            // El usuario presiona botones de calculadora

            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // Deshace 4 comandos

            user.Undo(4);

            // Vuelve a hacer 3 comandos

            user.Redo(3);

            // Espera al usuarioo

            Console.ReadKey();
        }
        public static void Run()
        {
            Console.WriteLine("This real-world code demonstrates the Command pattern used in a simple calculator with unlimited number of undo's and redo's. Note that in C#  the word 'operator' is a keyword. Prefixing it with '@' allows using it as an identifier.");
            User user = new User();

            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            user.Undo(4);
            user.Redo(3);

            /*
             * Current value = 100 (following + 100)
             * Current value =  50 (following - 50)
             * Current value = 500 (following * 10)
             * Current value = 250 (following / 2)
             *
             * ---- Undo 4 levels
             * Current value = 500 (following * 2)
             * Current value =  50 (following / 10)
             * Current value = 100 (following + 50)
             * Current value =   0 (following - 100)
             *
             * ---- Redo 3 levels
             * Current value = 100 (following + 100)
             * Current value =  50 (following - 50)
             * Current value = 500 (following * 10)
             */
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            /////////
            //Receiver receiver = new Receiver();
            //ConcreteCommand command = new ConcreteCommand(receiver);
            //Invoker invoker = new Invoker();

            //invoker.SetCommand(command);
            //invoker.ExecuteCommand();
            //Console.ReadKey();

            ////////
            /// // Create user and let her compute
            User user = new User();

            // User presses calculator buttons
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // Undo 4 commands
            user.Undo(4);

            // Redo 3 commands
            user.Redo(3);

            // Wait for user
            Console.ReadKey();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            // Create user and let her compute

            User user = new User();

            // User presses calculator buttons

            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // Undo 4 commands

            user.Undo(4);

            // Redo 3 commands

            user.Redo(3);

            // Wait for user

            Console.ReadKey();
        }
Exemplo n.º 7
0
        private static void CalculatorExample()
        {
            var user = new User();

            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);
            user.Undo(4);
            user.Redo(3);
        }
Exemplo n.º 8
0
        public static void Run()
        {
            Console.WriteLine("\nCommand Real World Practice");
            User user = new User();

            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            user.Undo(4);
            user.Redo(3);
        }
Exemplo n.º 9
0
        internal static void Main()
        {
            var user = new User();

            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            user.Undo(4);

            user.Redo(3);
        }
        static void Main(string[] args)
        {
            User user = new User();

            user.Compute(100, '+');
            user.Compute(50, '-');
            user.Compute(10, '*');
            user.Compute(2, '/');

            user.Undo(4);
            user.Redo(3);

            Console.Read();
        }
Exemplo n.º 11
0
        static void Main()
        {
            User user = new User();

            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            user.Undo(4);

            user.Redo(3);

            Console.Read();
        }
Exemplo n.º 12
0
        internal static void Main()
        {
            var user = new User();

            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            user.Undo(4);

            user.Redo(3);

            // Wait for user
            Console.ReadKey();
        }
Exemplo n.º 13
0
        public static void Main()
        {
            // Create user and let her compute
            User user = new User();

            // User presses calculator buttons
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // Undo 4 commands
            user.Undo(4);

            // Redo 3 commands
            user.Redo(3);
        }
        static void Main(string[] args)
        {
            User user = new User();

            // Use press calculator buttons
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // Undo 4 commands
            user.Undo(4);

            // Redo 3 commands
            user.Redo(3);

            Console.ReadKey();
        }
Exemplo n.º 15
0
        private static void Main()
        {
            // Creating the user
            var user = new User();

            // Let the user do something
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // Undo 4 last commands
            user.Undo(4);

            // Redo 3 cancelled commands
            user.Redo(3);

            Console.ReadKey();
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            Console.WriteLine("Calculator undo/redo operations.");

            // Create user to compute
            User user = new User();

            // User presses calculator buttons
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            user.Undo(4);

            user.Redo(3);

            Console.ReadKey();
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            // Create user and let them compute
            User user = new User();

            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // Undo 4 commands
            user.Undo(4);

            // Redo 3 commands
            user.Redo(3);


            Console.ReadLine();
        }
Exemplo n.º 18
0
        static void Main()
        {
            // Создаем пользователя.
            User user = new User();

            // Пусть он что-нибудь сделает.
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // Отменяем 4 команды
            user.Undo(4);

            // Вернём 3 отменённые команды.
            user.Redo(3);

            // Ждем ввода пользователя и завершаемся.
            Console.Read();
        }
Exemplo n.º 19
0
    static void Main()
    {
      // Создаем пользователя.
      User user = new User();

      // Пусть он что-нибудь сделает.
      user.Compute('+', 100);
      user.Compute('-', 50);
      user.Compute('*', 10);
      user.Compute('/', 2);

      // Отменяем 4 команды
      user.Undo(4);

      // Вернём 3 отменённые команды.
      user.Redo(3);

      // Ждем ввода пользователя и завершаемся.
      Console.Read();
    }
Exemplo n.º 20
0
        static void Main()
        {
            // Create user & let them compute
            User user = new User();

            // Use press calculator buttons
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // Undo 4 commands
            user.Undo(4);

            // Redo 3 commands
            user.Redo(3);

            // Wait for user
            Console.ReadKey();
        }
Exemplo n.º 21
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Create user and let her compute
            User user = new User();

            // User presses calculator buttons
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // Undo 4 commands
            user.Undo(4);

            // Redo 3 commands
            user.Redo(3);

            // Wait for user
            Console.ReadKey();
        }
Exemplo n.º 22
0
        public static void Main()
        {
            // create a new object for calculations
            var user = new User();

            // executing several calculation actions
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            // cancel 4 last commands
            WriteLine("Undo 4 commands");
            user.Undo(4);

            // repeat 3 of them again
            WriteLine("Redo 3 commands");
            user.Redo(3);

            ReadLine();
        }
        public void ApplyCommandPlu100Minus50MutiplyBy10DividedBy2_Equal250()
        {
            User user = new User();

            // User presses calculator buttons
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            Assert.Equal(250, user.GetResult());

            // Undo 4 commands
            user.Undo(4);

            Assert.Equal(0, user.GetResult());

            // Redo 3 commands
            user.Redo(3);

            Assert.Equal(500, user.GetResult());
        }
Exemplo n.º 24
0
 private void bBack_Click(object sender, EventArgs e)
 {
     user.Undo(2);
 }