//добавить в очередь
 public void addToQueue(Client client)
 {
     numberClient++;
     client.setSequenceNumber(numberClient);
     clientList.Add(client);
     notify();
 }
 public void releaseClient(Client client)
 {
     client.setName(null);
     client.setNameOperation(null);
     client.setNumberOperation(0);
     client.setSequenceNumber(0);
     poolClient.Add(client);
 }
 private ObjectPoolClient()
 {
     for (int i = 0; i < 100; i++)
     {
         Client client = new Client();
         this.poolClient.Add(client);
     }
 }
Example #4
0
 public Client(Client client)
 {
     if (client != null)
     {
         this.name = client.name;
         this.nameOperation = client.nameOperation;
         this.numberOperation = client.numberOperation;
         this.sequenceNumber = client.sequenceNumber;
     }
 }
        public BankWindow(int number, BankWindowState state)
        {
            this.number = number;
            this.processOperation = new List<IOperation>();
            this.client = null;
            this.currentOperation = null;
            this.state = state;

            this.countCredits = 0;
            this.countDeposits = 0;
            this.countTransfers = 0;
            this.countCards = 0;
            this.countPayments = 0;
        }
        public BankWindow(int number)
        {
            this.number = number;
            this.processOperation = new List<IOperation>();
            this.isFree = true;
            this.client = null;
            this.currentOperation = null;

            this.countCredits = 0;
            this.countDeposits = 0;
            this.countTransfers = 0;
            this.countCards = 0;
            this.countPayments = 0;
            this.countCurrencyExchanges = 0;
        }
 public BankWindow(BankWindow bw)
 {
     this.number = bw.number;
     this.processOperation = new List<IOperation>();
     List<IOperation> oper = bw.getProcessOperation();
     for (int k = 0; k < oper.Count; k++)
     {
         this.addOperation(oper[k]);
     }
     if(bw.getClient() != null)
         this.client = new Client(bw.client);
     if (bw.getCurrentOperation() != null)
     {
         switch (bw.currentOperation.getNumberOperation())
         {
             case Credit.CREDIT: this.currentOperation = new Credit(); break;
             case Deposit.DEPOSIT: this.currentOperation = new Deposit(); break;
             case Card.CARD: this.currentOperation = new Card(); break;
             case Transfer.TRANSFER: this.currentOperation = new Transfer(); break;
             case Payment.PAYMENT: this.currentOperation = new Payment(); break;
         }
         this.currentOperation.setTimeOperation(bw.currentOperation.getTimeOperation());
     }
     this.manager = new OperationManager(bw.manager);
     if(bw.state.GetType() == typeof(BankWindowBusyState))
     {
         this.state = new BankWindowBusyState();
     }
     else
         if (bw.state.GetType() == typeof(BankWindowFreeState))
         {
             this.state = new BankWindowFreeState();
         }
         else
             if (bw.state.GetType() == typeof(BankWindowBreakState))
             {
                 this.state = new BankWindowBreakState();
             }
     this.isBreak = bw.isBreak;
     this.countAllOperations = bw.countAllOperations;
     this.countCredits = bw.countCredits;
     this.countDeposits = bw.countDeposits;
     this.countCards = bw.countCards;
     this.countTransfers = bw.countTransfers;
     this.countPayments = bw.countPayments;
 }
 //задать клиента
 public void setClient(Client client)
 {
     OperationFactory factory = new OperationFactory();
     this.client = client;
     if (this.client != null)
     {
         switch (client.getNumberOperation())
         {
             case Credit.CREDIT: currentOperation = factory.createOperation(Credit.CREDIT); break;
             case Deposit.DEPOSIT: currentOperation = factory.createOperation(Deposit.DEPOSIT); break;
             case Card.CARD: currentOperation = factory.createOperation(Card.CARD); break;
             case Transfer.TRANSFER: currentOperation = factory.createOperation(Transfer.TRANSFER); break;
             case Payment.PAYMENT: currentOperation = factory.createOperation(Payment.PAYMENT); break;
         }
         Random r = new Random();
         this.currentOperation.setTimeOperation(r.Next(this.currentOperation.getMinTimeOperation(), this.currentOperation.getMinTimeOperation()));
         this.state = new BankWindowBusyState();
     }
     notify();
 }
Example #9
0
        //выполняем работу по таймеру
        private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
        {
            OperationFactory factory = new OperationFactory();
            Random r = new Random();
            int numberOfClients = r.Next(this.numberOfNewClients + 1);
            for (int i = 0; i < numberOfClients; i++)
            {
                Client client = new Client();
                int numberName = r.Next(this.nameClients.Count);
                switch (r.Next(1,NUMBER_OF_OPERATION+1))
                {
                    case 1: client.setName(this.nameClients[numberName]);
                        client.setNumberOperation(Credit.CREDIT);
                        client.setNameOperation(factory.createOperation(Credit.CREDIT).getNameOperation());
                        break;
                    case 2: client.setName(this.nameClients[numberName]);
                        client.setNumberOperation(Deposit.DEPOSIT);
                        client.setNameOperation(factory.createOperation(Deposit.DEPOSIT).getNameOperation());
                        break;
                    case 3: client.setName(this.nameClients[numberName]);
                        client.setNumberOperation(Card.CARD);
                        client.setNameOperation(factory.createOperation(Card.CARD).getNameOperation());
                        break;
                    case 4: client.setName(this.nameClients[numberName]);
                        client.setNumberOperation(Transfer.TRANSFER);
                        client.setNameOperation(factory.createOperation(Transfer.TRANSFER).getNameOperation());
                        break;
                    case 5: client.setName(this.nameClients[numberName]);
                        client.setNumberOperation(Payment.PAYMENT);
                        client.setNameOperation(factory.createOperation(Payment.PAYMENT).getNameOperation());
                        break;
                }
                this.clientQueue.addToQueue(client);
            }

            for (int i = 0; i < this.listBankWindows.Count; i++)
            {
                //если окно свободно и в очереди есть клиенты, то выбираем клиента из очереди и отправлям к окну
                if ((this.listBankWindows[i].getState().GetType() == typeof(BankWindowFreeState))  && this.clientQueue.getClientCount() != 0)
                {
                    List<IOperation> processOperation = this.listBankWindows[i].getProcessOperation();
                    for (int j = 0; j < this.clientQueue.getClientCount(); j++)
                    {
                        Client client = this.clientQueue.takeFromQueue(j);
                        for (int k = 0; k < processOperation.Count; k++)
                        {
                            if (client.getNumberOperation() == processOperation[k].getNumberOperation())
                            {
                                this.listBankWindows[i].setClient(client);
                                this.clientQueue.removeFromQueue(j);
                                break;
                            }
                        }
                        if (this.listBankWindows[i].getState().GetType() == typeof(BankWindowBusyState))
                        {
                            break;
                        }
                    }
                }
                this.listBankWindows[i].performOperation();
            }
        }
Example #10
0
 //задать клиента
 public override void setClient(Client client)
 {
     this.client = client;
     switch (client.getNumberOperation())
     {
         case Credit.CREDIT: currentOperation = new Credit(); break;
         case Deposit.DEPOSIT: currentOperation = new Deposit(); break;
         case Card.CARD: currentOperation = new Card(); break;
         case Transfer.TRANSFER: currentOperation = new Transfer(); break;
         case Payment.PAYMENT: currentOperation = new Payment(); break;
         case CurrencyExchangeAdapter.CURRENCYEXCHANGE: currentOperation = new CurrencyExchangeAdapter(new CurrencyExchange()); break;
     }
     Random r = new Random();
     this.currentOperation.setTimeOperation(r.Next(this.currentOperation.getMinTimeOperation(), this.currentOperation.getMinTimeOperation()));
     this.isFree = false;
 }
Example #11
0
 //выполнять операцию
 public override bool performOperation()
 {
     if (this.currentOperation.getTimeOperation() != 0)
     {
         this.currentOperation.doOperation();
         return false;
     }
     else
     {
         switch (this.client.getNumberOperation())
         {
             case Credit.CREDIT: countCredits++; break;
             case Deposit.DEPOSIT: countDeposits++; break;
             case Card.CARD: countCards++; break;
             case Transfer.TRANSFER: countTransfers++; break;
             case Payment.PAYMENT: countPayments++; break;
             case CurrencyExchangeAdapter.CURRENCYEXCHANGE: countCurrencyExchanges++; break;
         }
         this.countAllOperations++;
         this.isFree = true;
         this.client = null;
         this.currentOperation = null;
         return true;
     }
 }
Example #12
0
 //задать клиента
 public void setClient(Client client)
 {
     this.client = client;
     switch (client.getNumberOperation())
     {
         case Credit.CREDIT: currentOperation = this.manager.getOperation(Credit.CREDIT); break;
         case Deposit.DEPOSIT: currentOperation = this.manager.getOperation(Deposit.DEPOSIT); break;
         case Card.CARD: currentOperation = this.manager.getOperation(Card.CARD); break;
         case Transfer.TRANSFER: currentOperation = this.manager.getOperation(Transfer.TRANSFER); break;
         case Payment.PAYMENT: currentOperation = this.manager.getOperation(Payment.PAYMENT); break;
     }
     Random r = new Random();
     this.currentOperation.setTimeOperation(r.Next(this.currentOperation.getMinTimeOperation(), this.currentOperation.getMinTimeOperation()));
     this.isFree = false;
 }
Example #13
0
 //выполнять операцию
 public bool performOperation()
 {
     if (this.currentOperation.getTimeOperation() != 0)
     {
         this.currentOperation.doOperation();
         return false;
     }
     else
     {
         switch (this.client.getNumberOperation())
         {
             case Credit.CREDIT: countCredits++; break;
             case Deposit.DEPOSIT: countDeposits++; break;
             case Card.CARD: countCards++; break;
             case Transfer.TRANSFER: countTransfers++; break;
             case Payment.PAYMENT: countPayments++; break;
         }
         this.countAllOperations++;
         this.isFree = true;
         ObjectPoolClient pool = ObjectPoolClient.getInstance();
         pool.releaseClient(this.client);
         this.client = null;
         this.manager.pushOperation(this.currentOperation);
         this.currentOperation = null;
         return true;
     }
 }
Example #14
0
 //выполнять операцию
 public bool performOperation()
 {
     if (this.currentOperation.getTimeOperation() != 0)
     {
         this.currentOperation.doOperation();
         return false;
     }
     else
     {
         switch (this.client.getNameOperation())
         {
             case Credit.CREDIT: countCredits++; break;
             case Deposit.DEPOSIT: countDeposits++; break;
             case Card.CARD: countCards++; break;
             case Transfer.TRANSFER: countTransfers++; break;
             case Payment.PAYMENT: countPayments++; break;
         }
         this.countAllOperations++;
         this.isFree = true;
         this.client = null;
         this.currentOperation = null;
         return true;
     }
 }
 public virtual void setClient(Client client)
 {
     throw new NotImplementedException();
 }