Exemple #1
0
 public void On()
 {
     try
     {
         IsStateOn = true;
         // verify stock
         if (IsAnyStock())
         {
             // Activate key pad reader
             _cancellationTokenSource = new CancellationTokenSource();
             _cancellationToken       = _cancellationTokenSource.Token;
             _readKeypadTask          = Task.Run((Action)ReadKeypadInstructions, _cancellationToken);
         }
         else
         {
             // signal nothing to sell
             OrderAction?.Invoke(OrderCmdEvent.OutOfStock, null);
             IsStateOn = false;
         }
     }
     catch (Exception e)
     {
         FailtException?.Invoke(e);
     }
 }
Exemple #2
0
 public void On()
 {
     try
     {
         IsStateOn = true;
         _cancellationTokenSource = new CancellationTokenSource();
         _cancellationToken       = _cancellationTokenSource.Token;
         _readKeypadTask          = Task.Run((Action)ReadPaymentInstructions, _cancellationToken);
     }
     catch (Exception e)
     {
         FailtException?.Invoke(e);
     }
 }
Exemple #3
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);
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
0
 public void InvokeFailtException(Exception ex)
 {
     FailtException?.Invoke(ex);
 }