Exemple #1
0
        static void Main(string[] args)
        {
            var invoker    = new Invoker();
            var calculator = new Calculator();

            var command1 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Add, 10);
            var command2 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Multiply, 5);
            var command3 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Subtract, 5);
            var command4 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Divide, 5);

            invoker.Command = command1;
            invoker.Invoke();

            invoker.Command = command2;
            invoker.Invoke();

            invoker.Command = command3;
            invoker.Invoke();
            invoker.Undo();

            invoker.Command = command4;
            invoker.Invoke();

            Console.WriteLine($"Result is : {calculator.Value}");
        }
Exemple #2
0
        public void Compute(char @operator, int operand)
        {
            Command command = new CalculatorCommand(this.calculator, @operator, operand);
            command.Execute();

            this.commands.Add(command);
            this.current++;
        }
Exemple #3
0
        public void Compute(char @operator, int operand)
        {
            var command = new CalculatorCommand(_calculator, @operator, operand);

            command.Execute();
            _commands.Add(command);
            _current++;
        }
Exemple #4
0
        public void Compute(char @operator, int operand)
        {
            // Create command operation and execute it
            Command command = new CalculatorCommand(_calculator, @operator, operand);

            command.Execute();
            _commands.Add(command);
            _commandsCount++;
        }
Exemple #5
0
        public void Compute(char @operator, int operand)
        {
            Command command = new CalculatorCommand(this.calculator, @operator, operand);

            command.Execute();

            this.commands.Add(command);
            this.current++;
        }
Exemple #6
0
        public void Compute(char @operator, int operand)
        {
            // create the command and execute it
            var command = new CalculatorCommand(@operator, operand, _calculator);

            command.Execute();

            // Add operation to the cancel list
            _commandHistory.Add(command);
            _current++;
        }
Exemple #7
0
        public void Compute(char @operator, int operand)
        {
            // Create command opearation and execue it
            Command command = new CalculatorCommand(_calculator, @operator, operand);

            command.Execute();

            //Add command to undo list
            _commands.Add(command);
            _current++;
        }
Exemple #8
0
        public void Compute(char @operator, int operand)
        {
            // Create command operation and execute it
            Command command = new CalculatorCommand(
              _calculator, @operator, operand);
            command.Execute();

            // Add command to undo list
            _commands.Add(command);
            _current++;
        }
Exemple #9
0
        /// <summary>
        /// The compute.
        /// </summary>
        /// <param name="operator">
        /// The operator.
        /// </param>
        /// <param name="operand">
        /// The operand.
        /// </param>
        public void Compute(char @operator, int operand)
        {
            // Create command operation and execute it
            AnAbstractCommand command = new CalculatorCommand(
                this.Calculator, @operator, operand);

            command.Execute();

            // Add command to undo list
            this.Commands.Add(command);
            this.Current++;
        }
Exemple #10
0
        public void Compute(char @operator, int operand)
        {
            Command command = new CalculatorCommand(
                _calculator, @operator, operand);

            command.Execute();

            if (_current < _commands.Count)
            {
                _commands.RemoveRange(_current, _commands.Count - _current);
            }

            _commands.Add(command);
            _current++;
        }
Exemple #11
0
        public void Compute(char @operator, int operand)
        {
            // Create command operation and execute it

            Command command = new CalculatorCommand(
                _calculator, @operator, operand);

            command.Execute();

            //fix the redo list bug
            if (_commands.Count > _current)
            {
                _commands.RemoveRange(_current, _commands.Count - _current);
            }

            // Add command to undo list
            _commands.Add(command);
            _current++;
        }
Exemple #12
0
        public void Compute(char @operator, int operand)
        {
            // Создаем команду операции и выполняем её
            Command command = new CalculatorCommand(
                _calculator, @operator, operand);

            command.Execute();

            if (_current < _commands.Count)
            {
                // если "внутри undo" мы запускаем новую операцию,
                // надо обрубать список команд, следующих после текущей,
                // иначе undo/redo будут некорректны
                _commands.RemoveRange(_current, _commands.Count - _current);
            }

            // Добавляем операцию к списку отмены
            _commands.Add(command);
            _current++;
        }
Exemple #13
0
    public void Compute(char @operator, int operand)
    {

      // Создаем команду операции и выполняем её
      Command command = new CalculatorCommand(
        _calculator, @operator, operand);
      command.Execute();

	if (_current < _commands.Count)
	{
	    // если "внутри undo" мы запускаем новую операцию, 
	    // надо обрубать список команд, следующих после текущей, 
	    // иначе undo/redo будут некорректны
		_commands.RemoveRange(_current, _commands.Count - _current);
	}

      // Добавляем операцию к списку отмены
      _commands.Add(command);
      _current++;
    }