Esempio n. 1
0
        public String ProcessOrder(OrderObject order)
        {
            bool isValidCardno = false;
            int  numRooms      = order.getAmount();

            Console.WriteLine("Checking card validity");
            // Check validity of cardNo
            long cardNo = order.getCardNo();

            if (cardNo > 5000000000000000 && cardNo < 7000000000000000)
            {
                isValidCardno = true;
            }

            if (isValidCardno)
            {
                Console.WriteLine("\tCardNo is valid");
                if (numRooms <= this.capacity)
                {
                    this.capacity -= numRooms;
                    Console.WriteLine(String.Format("\tCost per room = {0}", hotelPrice));
                    // Time between order placed and order processed
                    TimeSpan timeToProcessOrder = DateTime.Now - order.getOrderPlacedTime();
                    return(String.Format("ORDER CONFIRMED - Total amount = {0}, order process time = {1} milliseconds",
                                         numRooms * hotelPrice, timeToProcessOrder.Milliseconds));
                }
                else
                {
                    return("ORDER DECLINED - There are no sufficient rooms in this hotel");
                }
            }
            else
            {
                return("ORDER DECLINED - Card is invalid");
            }
        }
Esempio n. 2
0
        // Event handler for makingOrder event
        // This method is executed when an orderObj is inserted into the multicell buffer
        public static void retrieveOrder()
        {
            String encodedOrder;

            Monitor.Enter(Program.mb);
            try
            {
                encodedOrder = Program.mb.getOneCell();
            }
            finally {
                Monitor.Exit(Program.mb);
            }

            OrderObject decodedOrder = Decode(encodedOrder);

            Console.WriteLine(String.Format("\nNew order received -> From travel agency {0} to hotel supplier {1} for {2} rooms with card no. {3}",
                                            decodedOrder.getSenderId(), decodedOrder.getSupplierId(), decodedOrder.getAmount(), decodedOrder.getCardNo()));
            int supplierId = decodedOrder.getSupplierId();

            if (supplierId == 1)
            {
                Console.WriteLine("Hotel 1 is processing the order");
                Console.WriteLine(Program.hs1.ProcessOrder(decodedOrder));
            }
            if (supplierId == 2)
            {
                Console.WriteLine("Hotel 2 is processing the order");
                Console.WriteLine(Program.hs2.ProcessOrder(decodedOrder));
            }
        }
Esempio n. 3
0
 // Convert the object into a string
 public static string Encode(OrderObject orderObj)
 {
     return(String.Format("{0}|{1}|{2}|{3}|{4}", orderObj.getSenderId(), orderObj.getSupplierId(), orderObj.getCardNo(), orderObj.getAmount(), orderObj.getOrderPlacedTime()));
 }