Beispiel #1
0
        public void RoomsPriceCut(Int32 price, String HotelName)
        {
            Console.WriteLine();
            Console.WriteLine("{0} rooms are on sale with a low price  ${1} ", HotelName, price);
            Console.WriteLine("No. of Rooms Available at {0} are: {1}", HotelName, HotelSupplier.getRoomsAvailable(HotelName));
            Console.WriteLine();

            if (HotelName.Equals("HotelSupplier1"))
            {
                OrderClass CurrentOrder1 = new OrderClass();
                CurrentOrder1.setSenderID("TravelAgency1");
                CurrentOrder1.setReceieverID(HotelName);
                CurrentOrder1.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder1.setNoOfDays(2);
                CurrentOrder1.setCardNo(CreditCards[0]);
                CardinalMain.TravelAgency1.setCurrentOrder(CurrentOrder1);

                OrderClass CurrentOrder2 = new OrderClass();
                CurrentOrder2.setSenderID("TravelAgency2");
                CurrentOrder2.setReceieverID(HotelName);
                CurrentOrder2.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder2.setNoOfDays(4);
                CurrentOrder2.setCardNo(CreditCards[1]);
                CardinalMain.TravelAgency2.setCurrentOrder(CurrentOrder2);


                OrderClass CurrentOrder3 = new OrderClass();
                CurrentOrder3.setSenderID("TravelAgency3");
                CurrentOrder3.setReceieverID(HotelName);
                CurrentOrder3.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder3.setNoOfDays(3);
                CurrentOrder3.setCardNo(CreditCards[2]);
                CardinalMain.TravelAgency3.setCurrentOrder(CurrentOrder3);


                OrderClass CurrentOrder4 = new OrderClass();
                CurrentOrder4.setSenderID("TravelAgency4");
                CurrentOrder4.setReceieverID(HotelName);
                CurrentOrder4.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder4.setNoOfDays(4);
                CurrentOrder4.setCardNo(CreditCards[3]);
                CardinalMain.TravelAgency4.setCurrentOrder(CurrentOrder4);

                OrderClass CurrentOrder5 = new OrderClass();
                CurrentOrder5.setSenderID("TravelAgency5");
                CurrentOrder5.setReceieverID(HotelName);
                CurrentOrder5.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder5.setNoOfDays(5);
                CurrentOrder5.setCardNo(CreditCards[4]);
                CardinalMain.TravelAgency5.setCurrentOrder(CurrentOrder5);
                i = 1;
            }
            else if (HotelName.Equals("HotelSupplier2"))
            {
                OrderClass CurrentOrder1 = new OrderClass();
                CurrentOrder1.setSenderID("TravelAgency1");
                CurrentOrder1.setReceieverID(HotelName);
                CurrentOrder1.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder1.setNoOfDays(4);
                CurrentOrder1.setCardNo(CreditCards[0]);
                CardinalMain.HTravelAgency1.setCurrentOrder(CurrentOrder1);


                OrderClass CurrentOrder2 = new OrderClass();
                CurrentOrder2.setSenderID("TravelAgency2");
                CurrentOrder2.setReceieverID(HotelName);
                CurrentOrder2.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder2.setNoOfDays(2);
                CurrentOrder2.setCardNo(CreditCards[1]);
                CardinalMain.HTravelAgency2.setCurrentOrder(CurrentOrder2);

                OrderClass CurrentOrder3 = new OrderClass();
                CurrentOrder3.setSenderID("TravelAgency3");
                CurrentOrder3.setReceieverID(HotelName);
                CurrentOrder3.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder3.setNoOfDays(4);
                CurrentOrder3.setCardNo(CreditCards[2]);
                CardinalMain.HTravelAgency3.setCurrentOrder(CurrentOrder3);

                OrderClass CurrentOrder4 = new OrderClass();
                CurrentOrder4.setSenderID("TravelAgency4");
                CurrentOrder4.setReceieverID(HotelName);
                CurrentOrder4.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder4.setNoOfDays(3);
                CurrentOrder4.setCardNo(CreditCards[3]);
                CardinalMain.HTravelAgency4.setCurrentOrder(CurrentOrder4);

                OrderClass CurrentOrder5 = new OrderClass();
                CurrentOrder5.setSenderID("TravelAgency5");
                CurrentOrder5.setReceieverID(HotelName);
                CurrentOrder5.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder5.setNoOfDays(3);
                CurrentOrder5.setCardNo(CreditCards[4]);
                CardinalMain.HTravelAgency5.setCurrentOrder(CurrentOrder5);
                i = 2;
            }
            else if (HotelName.Equals("HotelSupplier3"))
            {
                OrderClass CurrentOrder1 = new OrderClass();
                CurrentOrder1.setSenderID("TravelAgency1");
                CurrentOrder1.setReceieverID(HotelName);
                CurrentOrder1.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder1.setNoOfDays(5);
                CurrentOrder1.setCardNo(CreditCards[0]);
                CardinalMain.STravelAgency1.setCurrentOrder(CurrentOrder1);

                OrderClass CurrentOrder2 = new OrderClass();
                CurrentOrder2.setSenderID("TravelAgency2");
                CurrentOrder2.setReceieverID(HotelName);
                CurrentOrder2.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder2.setNoOfDays(2);
                CurrentOrder2.setCardNo(CreditCards[1]);
                CardinalMain.STravelAgency2.setCurrentOrder(CurrentOrder2);

                OrderClass CurrentOrder3 = new OrderClass();
                CurrentOrder3.setSenderID("TravelAgency3");
                CurrentOrder3.setReceieverID(HotelName);
                CurrentOrder3.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder3.setNoOfDays(6);
                CurrentOrder3.setCardNo(CreditCards[2]);
                CardinalMain.STravelAgency3.setCurrentOrder(CurrentOrder3);

                OrderClass CurrentOrder4 = new OrderClass();
                CurrentOrder4.setSenderID("TravelAgency4");
                CurrentOrder4.setReceieverID(HotelName);
                CurrentOrder4.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder4.setNoOfDays(3);
                CurrentOrder4.setCardNo(CreditCards[3]);
                CardinalMain.STravelAgency4.setCurrentOrder(CurrentOrder4);

                OrderClass CurrentOrder5 = new OrderClass();
                CurrentOrder5.setSenderID("TravelAgency5");
                CurrentOrder5.setReceieverID(HotelName);
                CurrentOrder5.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder5.setNoOfDays(5);
                CurrentOrder5.setCardNo(CreditCards[4]);
                CardinalMain.STravelAgency5.setCurrentOrder(CurrentOrder5);
                i = 3;
            }
            {
                //All Travel Agencies Start Placing Orders to the Hotel Supplier which generated an Event
                CardinalMain.startOrders(i);
            }
        }
        /// <summary>
        /// Main Method for starting the application
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Console.SetBufferSize(200, 3000);
            Console.WriteLine("Welcome to Cardinal Hotel Booking System!!!");
            Console.WriteLine();
            Console.WriteLine("We hae follwoing hotels with price(per room) and No. of rooms available!!!");
            Console.WriteLine();
            Console.WriteLine("HotelSupplier1 with {1} Rooms at a price of ${0} per room.", HotelSupplier.getRoomPrice("HotelSupplier1"), HotelSupplier.getRoomsAvailable("HotelSupplier1"));
            Console.WriteLine("HotelSupplier2 with {1} Rooms at a price of ${0} per room.", HotelSupplier.getRoomPrice("HotelSupplier2"), HotelSupplier.getRoomsAvailable("HotelSupplier2"));
            Console.WriteLine("HotelSupplier3 with {1} Rooms at a price of ${0} per room.", HotelSupplier.getRoomPrice("HotelSupplier3"), HotelSupplier.getRoomsAvailable("HotelSupplier3"));
            Console.WriteLine();
            Console.WriteLine("Following are the Credit Card No.s for the respective Travel Agencies: ");
            Console.WriteLine();

            //Bank Service Operations .. Applying for New Credit Card
            String Card1 = BankService.generatecardno("TravelAgency1");
            String Card2 = BankService.generatecardno("TravelAgency2");
            String Card3 = BankService.generatecardno("TravelAgency3");
            String Card4 = BankService.generatecardno("TravelAgency4");
            String Card5 = BankService.generatecardno("TravelAgency5");

            Console.WriteLine("Credit Card Number for TravelAgency1: " + Card1);
            Console.WriteLine("Credit Card Number for TravelAgency2: " + Card2);
            Console.WriteLine("Credit Card Number for TravelAgency3: " + Card3);
            Console.WriteLine("Credit Card Number for TravelAgency4: " + Card4);
            Console.WriteLine("Credit Card Number for TravelAgency5: " + Card5);

            Console.WriteLine();
            //Getting the Input for Credit Card from respective Travel Agencies
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Type in the Credit for TravelAgency{0}: ", i + 1);
                String CardNum = Console.ReadLine();
                while (CardNum.Length != 8)
                {
                    Console.WriteLine("Invalid Credit Card format!! (Hint: Exaclty 8 characters>");
                    CardNum = Console.ReadLine();
                }
                TravelAgency.CreditCards[i] = BankService.EncryptCardNo(CardNum);
            }

            Console.WriteLine();
            Console.WriteLine("Thank You For Entering the Card Details !!!");
            Console.WriteLine();
            Console.WriteLine("<Hint: For Verfiying 'Rooms Full' Conditions specify the no. of events in the range of 25 plus..>");
            Console.WriteLine();
            Console.WriteLine("Do you want to Enter the No. of PriceCut Event to happen for Each Hotel Supplier??");
            Console.WriteLine("<Default is 5-10 per Supplier depending on the lowprice or highprice>(Y/N): ");

            String option = Console.ReadLine();

            if (option.ToUpper().Equals("Y"))
            {
                //Option to modify the no of event proabilities
                Console.WriteLine("Enter the No. of Price Cut Events: ");
                NoOfPriceCuts = Convert.ToInt32(Console.ReadLine());
                while (NoOfPriceCuts <= 0)
                {
                    Console.WriteLine("Enter a minimum value of 1 or more...");
                    NoOfPriceCuts = Convert.ToInt32(Console.ReadLine());
                }
            }
            Console.WriteLine();
            Console.WriteLine("Starting to Execute Events....");
            Thread.Sleep(2000);

            Thread h1 = new Thread(new ThreadStart(HotelSupplier1.InvokePricingModel));
            Thread h2 = new Thread(new ThreadStart(HotelSupplier2.InvokePricingModel));
            Thread h3 = new Thread(new ThreadStart(HotelSupplier3.InvokePricingModel));

            h1.Name = "HotelSupplier1";
            h2.Name = "HotelSupplier2";
            h3.Name = "HotelSupplier3";
            h1.Start();
            h2.Start();
            h3.Start();

            //Travel Agency Subscribing to PriceCut Event of Hotel Supplier
            HotelSupplier.priceCut += new priceCutEvent(TravelAgent.RoomsPriceCut);

            Console.Read();
        }
Beispiel #3
0
        /// <summary>
        /// This method receives the order placed by the travel agencies. The orders are read from the multi-cell
        /// buffer
        /// </summary>
        public void receiveOrder()
        {
            Boolean[] arr = new Boolean[5];
            int       i   = 15;

            while (i != 0)
            {
                if (Thread.CurrentThread.Name.Equals("H1"))
                {
                    if (Monitor.TryEnter(CardinalMain.n1))
                    {
                        try
                        {
                            OrderClass OrderObject = Decoder(CardinalMain.n1.getOneCell());
                            Console.WriteLine("Order Object Received by " + OrderObject.getReceiverID() + " from: " + OrderObject.getSenderID());
                            OrderProcessingQueue.Enqueue(OrderObject);
                            Console.WriteLine();
                        }
                        finally
                        {
                            i--;
                            Monitor.Exit(CardinalMain.n1);
                        }
                    }
                }
                else if (Thread.CurrentThread.Name.Equals("H2"))
                {
                    if (Monitor.TryEnter(CardinalMain.n2))
                    {
                        try
                        {
                            OrderClass OrderObject = Decoder(CardinalMain.n2.getOneCell());
                            Console.WriteLine("Order Object Received by " + OrderObject.getReceiverID() + " from: " + OrderObject.getSenderID());
                            OrderProcessingQueue.Enqueue(OrderObject);
                            Console.WriteLine();
                        }
                        finally
                        {
                            i--;
                            Monitor.Exit(CardinalMain.n2);
                        }
                    }
                }
                else if (Thread.CurrentThread.Name.Equals("H3"))
                {
                    if (Monitor.TryEnter(CardinalMain.n3))
                    {
                        try
                        {
                            OrderClass OrderObject = Decoder(CardinalMain.n3.getOneCell());
                            Console.WriteLine("Order Object Received by " + OrderObject.getReceiverID() + " from: " + OrderObject.getSenderID());
                            OrderProcessingQueue.Enqueue(OrderObject);
                            Console.WriteLine();
                        }
                        finally
                        {
                            i--;
                            Monitor.Exit(CardinalMain.n3);
                        }
                    }
                }

                //Order Processing Block
                {
                    HotelSupplier OrderProcessingObject = new HotelSupplier();
                    TravelAgency  OrderStatusObject     = new TravelAgency();
                    Thread        OrderProcessingThread = new Thread(new ThreadStart(OrderProcessingObject.processOrder));
                    Thread        OrderStatusThread     = new Thread(new ThreadStart(OrderStatusObject.receiveOrderConfirmation));

                    OrderProcessingThread.Start();
                    OrderStatusThread.Start();
                    OrderStatusThread.Join();
                    OrderProcessingThread.Join();
                }
            }
        }