Exemple #1
0
        public void ApplyEquality()
        {
            try
            {
                if (_isLastActionAnEquation && _lastBinaryOperation == null)
                {
                    var newValue = _displayNumber.ToDouble();
                    DisplayValue = newValue.ToString(_cultureInfo);

                    _lastOperand1 = newValue;
                    return;
                }

                var binaryOperationInfo = GetBinaryOperationInfo();
                if (binaryOperationInfo == null)
                {
                    return;
                }

                var value1          = binaryOperationInfo.Value1;
                var value2          = binaryOperationInfo.Value2;
                var binaryOperation = binaryOperationInfo.BinaryOperation;

                var executableInfo = binaryOperation.GetExecutableInfo(value1, value2);
                if (executableInfo.CanBeExecuted)
                {
                    var result = binaryOperation.Execute(value1, value2);

                    var displayValue = result.ToString(_cultureInfo);
                    _displayNumber = DisplayNumberFactory.Create(displayValue);
                    DisplayValue   = displayValue;

                    _lastOperand1        = value1;
                    _lastOperand2        = value2;
                    _lastBinaryOperation = binaryOperation;
                }
                else
                {
                    DisplayValue = executableInfo.Message;
                }

                _selectedBinaryOperation = null;
            }
            catch
            {
                DisplayValue = ErrorMessages.OperationFailed;
            }
            finally
            {
                _lastActionType = ActionType.Equality;
                _isLastActionAnBinaryOperation = false;
                _isLastActionAnEquation        = true;
            }
        }
Exemple #2
0
        private void ExecuteOperation(Func <ExecutableInfo> getExecutableInfo, Func <double> getResult)
        {
            var executableInfo = getExecutableInfo();

            if (!executableInfo.CanBeExecuted)
            {
                DisplayValue = executableInfo.Message;
                return;
            }

            var result       = getResult();
            var displayValue = result.ToString(_cultureInfo);

            _displayNumber = DisplayNumberFactory.Create(displayValue);
            DisplayValue   = displayValue;
        }