Пример #1
0
        static void Main(string[] args)
        {
            //3 hotel suppliers
            HotelSupplier[] h = new HotelSupplier[2];

            //1 travel agency
            TravelAgency travelAgency = new TravelAgency();
            //array of thread agency names
            string[] agenciesName= { "TA1", "TA2", "TA3", "TA4", "TA5" };

            for (int i = 0; i < 3; i++)
            {
                buffer[i] = new MultiCellBuffer();
            }

            //hotel threads started
            for (int i = 0; i < 2; i++)
            {
                h[i] = new HotelSupplier("HS" + (i + 1));
                h[i].priceCut += new priceCutDelegate(travelAgency.getHotelPrice);
                Thread hs = new Thread(new ThreadStart(h[i].run));
                hs.Start();
            }

            //agency threads started
            for (int i = 0; i < 5; i++)
            {
                Thread t = new Thread(new ThreadStart(travelAgency.run));
                t.Name = agenciesName[i];
                t.Start();
            }
        }
 public OrderProcessing(HotelSupplier hotel, OrderClass order, string supplierName)
 {
     this.hotel = hotel;
     this.order = order;
     this.supplierName = supplierName;
 }
        public void run()
        {
            while (counter < 3)
            {

                HotelSupplier hotel = new HotelSupplier();

                if (waitHandler > 0)
                {
                    autoReset.WaitOne();
                }
                waitHandler++;
                hotelPricingModel();

                String orderString;
                int count = 0;
                hotel.NoOfRoom = 30;
                hotel.NoOfAvailableRooms = 30;

                //Processing Order
              while (count < 5)
               {
                    for (int i = 0; i < 3; i++)
                    {
                        orderString = Program.buffer[i].getBuffer(hotelName);
                        if (orderString != null)
                        {
                            //decoding the buffere object
                            order = new Decoder().decode(orderString);
                           count++;
                            OrderProcessing orderProcessing = new OrderProcessing(hotel, order, hotelName);
                            Thread orderProcessingThread = new Thread(new ThreadStart(orderProcessing.processOrder));
                            orderProcessingThread.Start();
                            orderProcessingThread.Join();
                        }
                        else
                        {
                            Thread.Sleep(1000);
                        }
                    }
                    Thread.Sleep(500);

              }
                autoReset.Set();
                Console.WriteLine("");
                Thread.Sleep(500);

            }
        }