示例#1
0
 //constructor for travel agency with two buffers and the travel agency ID
 public TravelAgency(MultiCellBuffer newMBuffer, Int32 newTravelAgencyID)
 {
     tBuffer        = newMBuffer;
     ticketsBought  = 0;
     travelAgencyID = newTravelAgencyID;
     willOrder      = false;
     salePrice      = 0;
 }
示例#2
0
        static void Main(string[] args)
        {
            //create a multicell buffer, a confirmation buffer, and release three resources for the multicellbuffer
            buffer = new MultiCellBuffer();
            multiCellBufferPool.Release(3);


            //create two airline objects and pass in the same multicellbuffer to be shared for receiving orders
            Airline airline1 = new Airline(buffer, "Southwest");
            Airline airline2 = new Airline(buffer, "Delta");

            //create two airline threads, name them, and start their airlinefunc running as a thread
            airline1T      = new Thread(new ThreadStart(airline1.airlineFunc));
            airline2T      = new Thread(new ThreadStart(airline2.airlineFunc));
            airline1T.Name = "Southwest";
            airline2T.Name = "Delta";
            airline1T.Start();
            airline2T.Start();
            //airline1T.Join();
            //airline2T.Join();

            //subscribing both airlines to the order placed event
            TravelAgency.orderPlaced += new orderPlacedDelegate(airline1.orderAvailable);
            TravelAgency.orderPlaced += new orderPlacedDelegate(airline2.orderAvailable);

            //this array will be used to store travel agency threads
            Thread[] travelAgency = new Thread[5];

            //Create five travel agency objects, assign it's id, subscribe it to the price cut event
            //and start a thread for it
            TravelAgency agency;

            for (int i = 0; i < 5; i++)
            {
                //create a travel agency object with it's own ID
                agency = new TravelAgency(buffer, (i + 1));

                //Subscribing the travel agency object to the price cut event
                Airline.priceCut += new priceCutDelegate(agency.ticketsOnSale);
                OrderProcessing.orderConfirmed += new orderConfirmationDelegate(agency.orderConfirmationDelegate);

                //create a new thread, rename it, and start it
                travelAgency[i]      = new Thread(new ThreadStart(agency.travelAgencyFunc));
                travelAgency[i].Name = "Travel Agency " + (i + 1).ToString();
                travelAgency[i].Start();
                //travelAgency[i].Join();
            }
        }
示例#3
0
 //airline constructor with two buffers
 public Airline(MultiCellBuffer newBuffer, string newAirlineName)
 {
     aBuffer           = newBuffer;
     airlineName       = newAirlineName;
     willProcessOrder  = false;
     orderAirlineName  = "";
     ticketPrice       = 80;
     pricesForWeek     = new Int32[7];
     pricesForWeek[0]  = 180; //Sunday
     pricesForWeek[1]  = 100; //Monday
     pricesForWeek[2]  = 100; //Tuesday
     pricesForWeek[3]  = 90;  //Wednesday
     pricesForWeek[4]  = 80;  //Thursday
     pricesForWeek[5]  = 120; //Friday
     pricesForWeek[6]  = 200; //Saturday
     currentDay        = 0;   //represents day of the week
     availableTickets  = 500;
     numberOfPriceCuts = 0;
 }