Example #1
0
        static void Main(string[] args)
        {
            /*
             * Start Hotel Supplier Threads
             * Create buffer classes
             * Instantiate objects
             * Create Threads
             * Start Threads
             */

            MultiCellBuffer buffer = new MultiCellBuffer();

            //Get number of travel agencies from the user
            Console.WriteLine("Program started.");
            Console.WriteLine("Please enter the number of threads you would like to test:");
            int N = 0;

            while (N <= 0)
            {
                try
                {
                    N = Convert.ToInt32(Console.ReadLine());
                }
                catch (FormatException a)
                {
                    Console.WriteLine("Try entering a different number. Needs to be an integer.");
                }
            }
            //Instantiate our hotel supplier
            HotelSupplier hotel = new HotelSupplier(buffer, N);

            //Build our travel agencies
            const int idNum = 100;

            TravelAgency[] obitz    = new TravelAgency[N];
            Thread[]       agencies = new Thread[N];

            //Instantiate our travel agencies, attach the event handlers and start the threads
            for (int i = 0; i < N; ++i)
            {
                obitz[i] = new TravelAgency();
                obitz[i].setId(idNum + i);
                HotelSupplier.priceCut         += new HotelSupplier.priceCutEvent(obitz[i].priceCutEvent);
                HotelSupplier.printAgencyTimes += new HotelSupplier.printTimesEvent(obitz[i].printTimes);
                HotelSupplier.printOrders      += new HotelSupplier.printOrdersEvent(obitz[i].printOrders);
                agencies[i] = new Thread(new ThreadStart(obitz[i].agencyFunc));
                OrderProcessing.orderConfirmation += new OrderProcessing.orderConfirmationEvent(obitz[i].orderConfirmationEvent);
                agencies[i].Name = (i + 1).ToString();
                agencies[i].Start();
            }

            //Begin the Hotel Supplier thread which will control our main program flow
            Thread hotelThread = new Thread(new ThreadStart(hotel.hotelStarter));

            hotelThread.Start();
        }
Example #2
0
        static void Main(string[] args)
        {
            /*
             * Start Hotel Supplier Threads
             * Create buffer classes
             * Instantiate objects
             * Create Threads
             * Start Threads
             */

            MultiCellBuffer buffer = new MultiCellBuffer();

            //Get number of travel agencies from the user
            Console.WriteLine("Program started.");
            Console.WriteLine("Please enter the number of threads you would like to test:");
            int N = 0;
            while (N <= 0)
            {
                try
                {
                    N = Convert.ToInt32(Console.ReadLine());
                }
                catch (FormatException a)
                {
                    Console.WriteLine("Try entering a different number. Needs to be an integer.");
                }
            }
            //Instantiate our hotel supplier
            HotelSupplier hotel = new HotelSupplier(buffer, N);

            //Build our travel agencies
            const int idNum = 100;
            TravelAgency[] obitz = new TravelAgency[N];
            Thread[] agencies = new Thread[N];

            //Instantiate our travel agencies, attach the event handlers and start the threads
            for(int i = 0; i < N; ++i)
            {
                obitz[i] = new TravelAgency();
                obitz[i].setId(idNum + i);
                HotelSupplier.priceCut += new HotelSupplier.priceCutEvent(obitz[i].priceCutEvent);
                HotelSupplier.printAgencyTimes += new HotelSupplier.printTimesEvent(obitz[i].printTimes);
                HotelSupplier.printOrders += new HotelSupplier.printOrdersEvent(obitz[i].printOrders);
                agencies[i] = new Thread(new ThreadStart(obitz[i].agencyFunc));
                OrderProcessing.orderConfirmation += new OrderProcessing.orderConfirmationEvent(obitz[i].orderConfirmationEvent);
                agencies[i].Name = (i + 1).ToString();
                agencies[i].Start();
            }

            //Begin the Hotel Supplier thread which will control our main program flow
            Thread hotelThread = new Thread(new ThreadStart(hotel.hotelStarter));
            hotelThread.Start();
        }
Example #3
0
 public TravelAgency()
 {
     //instantiating necessary objects
     randDemand      = new Random();
     queuedOrders    = new List <OrderClass>();
     sentOrders      = new List <OrderClass>();
     confirmedOrders = new List <OrderClass>();
     currentOrder    = new OrderClass();
     orderEncoder    = new Encoder();
     orderStart      = new DateTime[10];
     orderFinish     = new DateTime[10];
     orderNumber     = 0;
     startNumber     = 0;
     roomDemand      = randDemand.Next(50, 100);
     mcb             = new MultiCellBuffer();
 }
 public TravelAgency()
 {
     //instantiating necessary objects
     randDemand = new Random();
     queuedOrders = new List<OrderClass>();
     sentOrders = new List<OrderClass>();
     confirmedOrders = new List<OrderClass>();
     currentOrder = new OrderClass();
     orderEncoder = new Encoder();
     orderStart = new DateTime[10];
     orderFinish = new DateTime[10];
     orderNumber = 0;
     startNumber = 0;
     roomDemand = randDemand.Next(50, 100);
     mcb = new MultiCellBuffer();
 }
 public HotelSupplier(MultiCellBuffer buffer, int numOfAgencies)
 {
     this.buffer = buffer;
     price_model = new PricingModel();
     numRooms = new int[7];
     numPriceCuts = new int[7];
     // get start time
     now = DateTime.Now;
     Console.WriteLine(now);
     totalAgencies = numOfAgencies;
     for (int i = 0; i < 7; ++i)
     {
         numRooms[i] = 50;
         numPriceCuts[i] = 0;
     }
     waitHandle = new EventWaitHandle[1];
     waitHandle[0] = new EventWaitHandle(false, EventResetMode.AutoReset);
     MultiCellBuffer mcp = new MultiCellBuffer();
 }
 public HotelSupplier(MultiCellBuffer buffer, int numOfAgencies)
 {
     this.buffer  = buffer;
     price_model  = new PricingModel();
     numRooms     = new int[7];
     numPriceCuts = new int[7];
     // get start time
     now = DateTime.Now;
     Console.WriteLine(now);
     totalAgencies = numOfAgencies;
     for (int i = 0; i < 7; ++i)
     {
         numRooms[i]     = 50;
         numPriceCuts[i] = 0;
     }
     waitHandle    = new EventWaitHandle[1];
     waitHandle[0] = new EventWaitHandle(false, EventResetMode.AutoReset);
     MultiCellBuffer mcp = new MultiCellBuffer();
 }