Esempio n. 1
0
        public void TurnOn()
        {
            this.authorizers = GasStationAuthorizer.CreateAll();

            if (this.authorizers == null)
            {
                return;
            }

            foreach (GasStationAuthorizer authorizer in this.authorizers)
            {
                Task.Run(() => this.InitiateFlow(authorizer));
            }
        }
Esempio n. 2
0
        private void InitiateFlow(GasStationAuthorizer authorizer)
        {
            do
            {
                ITransactionEntry transaction = null;
                ICard             card        = null;

                Nullable <short> pump = 0;

                Task readPump = new Task(() =>
                {
                    do
                    {
                        try
                        {
                            pump = authorizer.Authorizer.PinpadFacade.Keyboard.DataPicker.GetNumericValue("Escolha a bomba", true, 1, 4);
                        }
                        catch (Exception) { break; }
                    } while (pump == null);
                });
                readPump.Start();
                readPump.Wait();

                // We know very little about the transaction:
                transaction = new TransactionEntry();
                transaction.CaptureTransaction = true;
                transaction.Type = AccountType.Undefined;

                // Get transaction amount:
                decimal amount = 0;
                amount = this.View.Dispatcher.Invoke <decimal>(() =>
                {
                    return(GetPumpuAmount(pump.Value));
                });

                if (amount == 0)
                {
                    continue;
                }

                transaction.Amount = amount;

                // Asks for a card to be inserted or swiped:
                Task readCard = new Task(() => authorizer.WaitForCard(transaction, out card));
                readCard.Start();
                readCard.Wait();

                string authorizationMessage;
                bool   status = authorizer.BuyGas(card, transaction, out authorizationMessage);

                // Verify response
                if (status == true)
                {
                    authorizer.ShowSomething("approved!", ":-D", DisplayPaddingType.Center, true);
                }
                else
                {
                    authorizer.ShowSomething("not approved", ":-(", DisplayPaddingType.Center, true);
                }
            }while (true);
        }