Пример #1
0
        public void ProcessTransaction(Transaction transaction)
        {
            Customer aCustomer = transaction.Customer();

            if (transaction.Type() == TransactionGenerator.TransactionType.Deposit)
            {
                aCustomer.Balance += transaction.Amount();

                bankBalance = bank.BankVault().Deposit(transaction.Amount());
                OutPutTran(transaction);
                if (aCustomer.Balance >= bank.CustomerGoal)
                {
                    uiHelper.AddGoalReachedCustomerTransaction(transaction, this);
                }
            }
            else if (transaction.Type() == TransactionGenerator.TransactionType.Withdrawal)
            {
                decimal diff;
                bool    bankEmpty;
                //Checks customer balance first
                if (aCustomer.Balance >= transaction.Amount())
                {
                    if (bank.BankVault().Withdraw(transaction.Amount(), out diff, out bankEmpty))
                    {
                        //Normal Transaction
                        if (!bankEmpty)
                        {
                            aCustomer.Balance -= transaction.Amount();
                            OutPutTran(transaction);
                        }
                        //Get the remainder of bank funds if withdrawal amount >bank balance
                        if (bankEmpty && diff > 0)
                        {
                            aCustomer.Balance -= (transaction.Amount() - diff);
                            uiHelper.AddBankOutOfFundsCustomerTransaction(transaction, this);
                        }
                    }
                    else
                    {
                        OutPutTran(transaction);
                        uiHelper.AddBankOutOfFundsCustomerTransaction(transaction, this);
                    }
                    //Customer doesnt have the funds
                }
                else
                {
                    uiHelper.AddCustomerOutOfFundsCustomerTransaction(transaction, this);
                }
            }

            bank.Customers().MakeCustomerAvailable(aCustomer, cancelToken);
        }
Пример #2
0
        private void Simulate()
        {
            bank = new Bank(uiHelper, cancelTokenSource.Token, numberTellers, numberCustomers, bankVaultAmount, maxTransactionAmount, customersGoal, initCustomersAmount);

            uiHelper.AddListBoxItem("BankSimulator.Simulate Started...");

            transactionGenerator = new TransactionGenerator(uiHelper, cancelTokenSource.Token, bank.BankQueue(), bank.Customers(), maxTransactionAmount, timeOutThrottle, bank.Tellers(), bank);
        }