Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        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);
        }
        public TransactionGenerator(UIHelper uiHelper, CancellationToken cancelToken, BankQueue bankQueue, CustomerList customerList, int maxTransAmount, int timeOutThrottle,
                                    /*List<Teller> tellers,*/ BlockingCollection <Teller> tellers, Bank bank)
        {
            this.cancelToken     = cancelToken;
            this.customerList    = customerList;
            this.maxTransAmount  = maxTransAmount;
            this.uiHelper        = uiHelper;
            this.timeOutThrottle = timeOutThrottle;
            this.bankQueue       = bankQueue;
            this.bank            = bank;

            currentTranAmount = 0;
            rand               = new Random();
            this.tellers       = tellers;
            availTellerQueue   = new BlockingCollection <Teller>();
            unAvailTellerQueue = new BlockingCollection <Teller>();

            foreach (Teller tel in tellers)
            {
                availTellerQueue.Add(tel);
            }


            task = new Task(Generate);
            task.Start();
        }