Example #1
0
        /// <summary>
        /// Once the Hotel Supplier Receives the Order process order is called for processing the order
        /// and sends back the result to the travel agency
        /// </summary>
        public void processOrder()
        {
            while (OrderProcessingQueue.Count != 0)
            {
                String result = "";
                try
                {
                    OrderClass currentOrder = OrderProcessingQueue.Dequeue();

                    if (currentOrder.getReceiverID().Equals("HotelSupplier1"))
                    {
                        int roomsRequired = currentOrder.getNoOfRooms();
                        if (roomsRequired <= H1RoomCount)
                        {
                            //Total Cost Inclusive of 15 Percent Tax + 2 Percent Location Charges
                            double amount = (roomsRequired * H1RoomPrice) + ((roomsRequired * H1RoomPrice) * 0.15) + ((roomsRequired * H1RoomPrice) * 0.02);
                            if (BankService.verifyaccount(currentOrder.getSenderID(), currentOrder.getCardNo()))
                            {
                                H1RoomCount = H1RoomCount - roomsRequired;
                                result      = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result      = result + "Required No. of rooms are booked by " + currentOrder.getSenderID() + " at " + currentOrder.getReceiverID() + ": " + currentOrder.getNoOfRooms() + " Rooms |";
                                result      = result + "Total Cost of Booking (including taxes+location charges): $" + amount + " |";
                                result      = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                            else
                            {
                                result = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result = "Invalid Credit Card Number for: " + currentOrder.getSenderID() + "|";
                                result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                        }
                        else
                        {
                            result = "Sorry HotelSupplier1 Rooms are full.. Not Enough rooms Available!!! |" + "Order from " + currentOrder.getSenderID() + " could not be processed. |";
                            result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                        }
                    }

                    else if (currentOrder.getReceiverID().Equals("HotelSupplier2"))
                    {
                        int roomsRequired = currentOrder.getNoOfRooms();
                        if (roomsRequired <= H2RoomCount)
                        {
                            //Total Cost Inclusive of 17 Percent Tax + 3 Percent Location Charges
                            double amount = (roomsRequired * H2RoomPrice) + ((roomsRequired * H2RoomPrice) * 0.17) + ((roomsRequired * H2RoomPrice) * 0.03);
                            if (BankService.verifyaccount(currentOrder.getSenderID(), currentOrder.getCardNo()))
                            {
                                H2RoomCount = H2RoomCount - roomsRequired;
                                result      = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + " :|";
                                result      = result + "Required No. of rooms are booked by " + currentOrder.getSenderID() + " at " + currentOrder.getReceiverID() + ": " + currentOrder.getNoOfRooms() + " Rooms |";
                                result      = result + "Total Cost of Booking (including taxes+location charges): $" + amount + " |";
                                result      = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                            else
                            {
                                result = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result = "Invalid Credit Card Number for: " + currentOrder.getSenderID() + "|";
                                result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                        }
                        else
                        {
                            result = "Sorry HotelSupplier2 Rooms are full.. Not Enough rooms Available!!! |" + "Order from " + currentOrder.getSenderID() + " could not be processed. |";
                            result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                        }
                    }

                    else if (currentOrder.getReceiverID().Equals("HotelSupplier3"))
                    {
                        int roomsRequired = currentOrder.getNoOfRooms();
                        if (roomsRequired <= H3RoomCount)
                        {
                            //Total Cost Inclusive of 14 Percent Tax + 4 percent Location Charges
                            double amount = (roomsRequired * H3RoomPrice) + ((roomsRequired * H3RoomPrice) * 0.14) + ((roomsRequired * H3RoomPrice) * 0.04);
                            if (BankService.verifyaccount(currentOrder.getSenderID(), currentOrder.getCardNo()))
                            {
                                H3RoomCount = H3RoomCount - roomsRequired;
                                result      = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result      = result + "Required No. of rooms are booked by " + currentOrder.getSenderID() + " at " + currentOrder.getReceiverID() + ": " + currentOrder.getNoOfRooms() + " Rooms |";
                                result      = result + "Total Cost of Booking (including taxes+location charges): $" + amount + " |";
                                result      = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                            else
                            {
                                result = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result = "Invalid Credit Card Number for: " + currentOrder.getSenderID() + "|";
                                result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                        }
                        else
                        {
                            result = "Sorry HotelSupplier3 Rooms are full.. Not Enough rooms Available!!! |" + "Order from " + currentOrder.getSenderID() + " could not be processed. |";
                            result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                        }
                    }
                    //Sends back the order to Travel Agency using a separate buffer cell
                    if (Monitor.TryEnter(CardinalMain.n4))
                    {
                        try
                        {
                            CardinalMain.n4.setOneCell(result);//Order Status Sent to Travel Agency
                        }
                        finally
                        {
                            result = "";
                            Monitor.Exit(CardinalMain.n4);
                        }
                    }
                }
                finally
                {
                }
            }
        }
Example #2
0
        /// <summary>
        /// Encoder Method for Coverting Order Object to String
        /// </summary>
        /// <param name="CurrentOrder">Instance of Order Object</param>
        /// <returns>String with order information separated by '-'</returns>
        public String Encoder(OrderClass CurrentOrder)
        {
            String OrderToString = null;

            if (CurrentOrder != null)
            {
                OrderToString = CurrentOrder.getSenderID() + "-" + CurrentOrder.getNoOfRooms() + "-" + CurrentOrder.getCardNo() + "-" + CurrentOrder.getReceiverID() + "-" + CurrentOrder.getNoOfDays();
            }
            return(OrderToString);
        }
Example #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();
                }
            }
        }