Exemplo n.º 1
0
        /// <summary>
        /// Новый метод Execute, принимает на вход операцию, а не ее имя
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public object Execute(IOperation operation, object[] args)
        {
            if (operation == null)
            {
                return("Error: no such operation defined");
            }
            double x, y;

            double.TryParse(args[0].ToString(), out x);
            double.TryParse(args[1].ToString(), out y);
            double result = 0;

            var operArgs = operation as IOperationArgs;

            if (operArgs != null)
            {
                result = operArgs.Calc(args);
            }
            else
            {
                result = operation.Calc(x, y);
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Выполнить операцию
        /// </summary>
        /// <param name="operation">Название операции</param>
        /// <param name="args">Аргументы операции</param>
        /// <returns></returns>
        public object Execute(IOperation operation, object[] args)
        {
            if (operation == null)
            {
                return(null);
            }

            double result   = 0;
            var    operArgs = operation as IOperationArgs;

            if (operArgs != null)
            {
                result = operArgs.Calc(args.Select(it => double.Parse(it.ToString())));
            }
            else
            {
                double x;
                double.TryParse(args[0].ToString(), out x);

                double y;
                double.TryParse(args[1].ToString(), out y);

                result = operation.Calc(x, y);
            }

            //result = oper.Calc(x, y);

            return(result);
        }
Exemplo n.º 3
0
        public void ApplyOperation(decimal?value, IOperation operation)
        {
            if (value.HasValue)
            {
                bool isValid = true;
                if (nextOperation == null)
                {
                    this.accumulator = value.Value;

                    OnCalculatorValueChanged(new CalculatorChangedEventArgs(this.accumulator, !isValid, OperationType.Accumulation));
                }
                else
                {
                    try
                    {
                        if (!nextOperation.GetType().Name.ToLower().StartsWith("memory"))
                        {
                            this.accumulator = nextOperation.Calc(accumulator, value.Value);
                        }
                        else
                        {
                            this.memory = nextOperation.Calc(this.memory, value.Value);
                        }
                    }
                    catch (Exception ex)
                    {
                        isValid = false;
                    }
                    lastOperation = nextOperation;
                    lastValue     = value.Value;
                    OnCalculatorValueChanged(new CalculatorChangedEventArgs(this.accumulator, !isValid, OperationType.Calculation));
                }
            }

            nextOperation = operation;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Выполнить операцию
        /// </summary>
        /// <param name="operation">Название операции</param>
        /// <param name="args">Аргументы операции</param>
        /// <returns></returns>
        ///
        public object Execute(IOperation operation, object[] args)
        {
            double result, z, y;

            double.TryParse(args[0].ToString(), out z);
            double.TryParse(args[1].ToString(), out y);

            var operArgs = operation as IOperationArgs;

            if (operArgs != null)
            {
                result = operArgs.Calc(args.Select(x => double.Parse(x.ToString())));
            }
            else
            {
                result = operation.Calc(z, y);
            }
            return(result);
        }
Exemplo n.º 5
0
 public decimal ExecuteOperation(int num1, int num2)
 {
     return(operation.Calc(num1, num2));
 }