Пример #1
0
        /// <summary>
        /// Communicate with keypad.
        /// </summary>
        private void ReadKeypadInstructions()
        {
            try
            {
                do
                {
                    // verify stock
                    if (IsAnyStock())
                    {
                        DisplayProducts();
                    }
                    else
                    {
                        // Signal nothing to sell
                        OrderAction?.Invoke(OrderCmdEvent.OutOfStock, null);
                        IsStateOn = false;
                        continue;
                    }

                    DisplayMessageByCode(MessageCode.SelectOrder);

                    char code = _readKeypadInput.ReadInput(_cancellationToken);

                    // check the product code
                    if (_productRepository.ProductList.Any((p) => p.Code == code))
                    {
                        // valid code
                        var product = _productRepository.ProductList.First((p) => p.Code == code);
                        DisplayMessageByCode(MessageCode.Ok);
                        // select it
                        OrderAction?.Invoke(OrderCmdEvent.Select, product);
                    }
                    else
                    {
                        // inform - invalid code
                        DisplayMessageByCode(MessageCode.InvalidInput);
                    }
                }while (IsStateOn);
            }
            catch (Exception e)
            {
                FailtException?.Invoke(e);
            }
        }
Пример #2
0
        /// <summary>
        /// Communicate with payment keypad simulator.
        /// </summary>
        private void ReadPaymentInstructions()
        {
            try
            {
                do
                {
                    string template = _vendingMessageRepository.GetMessage(MessageCode.MakeYourPayment);
                    if (!string.IsNullOrWhiteSpace(template))
                    {
                        string msg = string.Format(template, msgAccepted);
                        _displayPanel.DisplayMessage(msg);
                    }
                    // get the key code
                    char code = _readKeypadInput.ReadInput(_cancellationToken);

                    if (code == '#')
                    {
                        // cancel simulation key
                        DisplayMessageByCode(MessageCode.Ok);
                        CoinAction?.Invoke(PaymentCmdEvent.Cancel, null);
                    }
                    else if (MapToCoins.ContainsKey(code))
                    {
                        // valid coin code
                        var coin = MapToCoins[code];
                        DisplayMessageByCode(MessageCode.Ok);
                        // signal about payment
                        CoinAction?.Invoke(PaymentCmdEvent.Payment, coin);
                    }
                    else
                    {
                        // invalid keypad simulation key
                        DisplayMessageByCode(MessageCode.InvalidInput);
                    }
                }while (IsStateOn);
            }
            catch (Exception e)
            {
                FailtException?.Invoke(e);
            }
        }