public void Calculate(string operation)
        {
            PlaySoundService.PlaySound(AppSoundsEnum.DigitalButton);
            var addNew = !_operands.Any() || (_operands.Count - _operators.Count) == 0;

            switch (operation)
            {
            case "0":
            case "1":
            case "2":
            case "3":
            case "4":
            case "5":
            case "6":
            case "7":
            case "8":
            case "9":
                if (addNew)
                {
                    _operands.Push(operation);
                }
                else
                {
                    var lastOperand = _operands.Pop();
                    _operands.Push(lastOperand + operation);
                }
                break;

            case "-":
                _operators.Push(CalculatorOperatorsEnum.Minus);
                break;

            case "+":
                _operators.Push(CalculatorOperatorsEnum.Plus);
                break;

            case "=":
                _operators.Push(CalculatorOperatorsEnum.Equal);
                break;

            case "C":
                _operators.Clear();
                _operands.Clear();
                break;
            }

            OutputResult = CalculatorService.Calculate(_operands.ToList(), _operators.ToList());
        }
Esempio n. 2
0
        protected async Task NavigateToUri(string uri)
        {
            if (string.IsNullOrWhiteSpace(uri))
            {
                throw new ArgumentException("Value cannot be null or white space.", nameof(uri));
            }

            try
            {
                DeviceService.BeginInvokeOnMainThread(async() =>
                {
                    PlaySoundService.PlaySound(AppSoundsEnum.DigitalButton);
                    await NavigationService.NavigateAsync(uri, useModalNavigation: false);
                });
            }
            catch (Exception ex)
            {
                await HandleException(ex);
            }
        }