public TransactionGenerator(UIHelper uiHelper, CancellationToken ct, BankQueue bq, CustomerList cl, decimal maxTransactionAmount, int timeoutThrottle)
        {
            try
            {
                this.uiHelper = uiHelper;
                this.cancelToken = ct;
                this.maxTransAmount = maxTransactionAmount;
                if (cl == null)
                {
                    uiHelper.GeneralMessage("DEBUG: The 'cl' (CustomerList) IS NULL!!!!");
                }
                this.customerList = cl;

                if (timeoutThrottle < 1) timeoutThrottle = 1;
                this.timeoutThrottle = timeoutThrottle;

                this.bankQueue = bq;

                this.task = Task.Factory.StartNew(TransactionGeneratorProc, cancelToken);
            }
            catch(Exception ex)
            {
                uiHelper.GeneralMessage("Exception in the Transaction Generator().  Message=" + ex.Message);
            }
        }
Пример #2
0
        public Teller(UIHelper uiHelper, CancellationToken ct, Bank b)
        {
            this.uiHelper = uiHelper;
            this.cancelToken = ct;
            this.bank = b;
            this.customerGoalAmount = uiHelper.GetCustomerGoalAmount();     // a bit of a hack

            task = Task.Factory.StartNew(TellerProc, cancelToken);
            uiHelper.AddTellerStartedMessage(task.Id);
        }
Пример #3
0
 public Bank(UIHelper uiHelper, CancellationToken ct, int numTellers, int numCustomers, decimal custInitialAmount, decimal initialBankVaultBalance)
 {
     BankQueue = new BankQueue(ct);
     Customers = new CustomerList(numCustomers, custInitialAmount, uiHelper);
     Vault = new BankVault(initialBankVaultBalance);
     tellerList = new List<Teller>();
     for (int i = 0; i < numTellers; i++)
     {
         tellerList.Add(new Teller(uiHelper, ct, this));
     }
 }
Пример #4
0
        public CustomerList(int numCustomers, decimal initialAmount, UIHelper uiHelper)
        {
            this.uiHelper = uiHelper;

            lock (customerListLock)
            {
                Customer tempCust;
                customerList = new List<Customer>();

                for (int i = 0; i < numCustomers; i++)
                {
                    tempCust = new Customer("cust" + i, initialAmount);

                    customerList.Add(tempCust);
                    //uiHelper.GeneralMessage("Added customer cust" + i+" to customerList="+customerList.ToString());
                }
            }
        }
        public BankSimulator(UIHelper uiHelper, int numTellers, int numCustomers, decimal custGoalAmount, decimal initialBankVaultBalance, 
                                decimal maxTransactionAmount, decimal custInitialAmount)
        {
            uiHelper.StartButton(true);

            this.uiHelper = uiHelper;
            this.cancelTokenSource = new CancellationTokenSource();
            CancellationToken ct = cancelTokenSource.Token;
            int timeoutThrottle = 10;

            this.bank = new Bank(uiHelper, ct, numTellers, numCustomers, custInitialAmount, initialBankVaultBalance);

            // Cannot start the transaction Generator until the CustomerList is ready (ie not null)
            while (bank.Customers==null) {
                //Thread.Sleep(100);
            }

            this.transactionGenerator = new TransactionGenerator(uiHelper, ct, bank.BankQueue, bank.Customers, maxTransactionAmount, timeoutThrottle);
        }
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (ValidateInputFields())
            {
                if (uiHelper == null)
                {
                    uiHelper = new UIHelper(this);
                }

                //if (bankSimulator == null)
                //{
                    //form.bankGroupBox1.Enabled = false;
                    //form.transactionsGroupBox2.Enabled = false;
                    //form.txbxCustGoalAmount.Enabled = false;

                    this.bankSimulator = new BankSimulator(uiHelper, numTellers, numCustomers, custGoalAmount, initialBankVaultBalance, maxTransAmount, custInitialAmount);
                //}
            }
        }