Exemplo n.º 1
0
        public IOperation GetOperation()
        {
            decimal firstNumber  = default(decimal);
            decimal secondNumber = default(decimal);
            string  operatorValue;

            ConsoleManager.GetParameter <decimal>(out firstNumber, ConsoleMessages.InsertFirstNumber);
            ConsoleManager.GetParameter <decimal>(out secondNumber, ConsoleMessages.InsertSecondNumber);
            ConsoleManager.GetParameter <string>(
                out operatorValue,
                string.Format(ConsoleMessages.InsertOperator, OperatorSymbols.GetOperators()),
                new OperatorValidator());

            return(OperationCreator.Create(firstNumber, secondNumber, operatorValue));
        }
Exemplo n.º 2
0
        public IOperation GetOperation()
        {
            string readAllText = FileWrapper.ReadAllText(this.Path);

            if (readAllText == null)
            {
                throw new InvalidOperationException("readAllText");
            }

            string[] parameters = readAllText.Split(new char[] { '\r', '\n' },
                                                    StringSplitOptions.RemoveEmptyEntries);

            if (parameters.Length != 3)
            {
                throw new InvalidOperationException(
                          ConsoleMessages.InvalidFile);
            }
            decimal firstNumber   = this.GetParameter <decimal>(parameters[0]);
            decimal secondNumber  = this.GetParameter <decimal>(parameters[1]);
            string  operatorValue = this.GetParameter <string>(parameters[2], new OperatorValidator());

            return(OperationCreator.Create(firstNumber, secondNumber, operatorValue));
        }