/*gets the order confirmation from the RecieptBuffer class, wheather * the order is allocated romms or is cancelled*/ public void getReciept() { try { while (pendingReciept > 0 || atLeastOneIsAlive() || agencyAlive) { if (pendingReciept >= 0) { if (atLeastOneIsDead()) { for (int i = 0; i < HotelBookingSystem.Buffer.getLength(); i++) { String x = HotelBookingSystem.Buffer.getBuffer(i); if (x.Equals("-1")) { continue; } else { //Console.WriteLine("Hi"); Order o = EncoderDecoder.decode(x); for (int j = 0; j < h.Length; j++) { if (o.getAgencyId() == agencyId && h[j].getHotelId() == o.getHotelId() && !h[j].isHotelAlive()) { Buffer.freeBuffer(i); pendingReciept--; Console.WriteLine("Agency {1}-> Cancelling Order {0} to Hotel {2} because Hotel has terminated.", o.getOrderId(), agencyId, o.getHotelId(), System.DateTime.Now); } } } } } String receipt = ReceiptBuffer.getBuffer(agencyId); if (!receipt.Equals("-1")) { Console.WriteLine("Agency {0}-> Confirmation Received: " + receipt, agencyId); pendingReciept--; } Thread.Sleep(500); } } } catch (Exception e) { Console.WriteLine(e.Message); } }
//processes the order by checking the available rooms and validating credit card with BankService void processOrder(Object x) { try { float price1 = roomPrice; Order o = (Order)x; encryptionService.ServiceClient encrypt = new encryptionService.ServiceClient(); int orderID = o.getOrderId(); int agencyID = o.getAgencyId(); int hotelID = o.getHotelId(); int roomsOrdered = o.getRooms(); float quotedPrice = o.getQuotePrice(); float totalPrice = quotedPrice * roomsOrdered; String cardNo = o.getCardNo(); String success = "Order " + orderID + " booked with " + hotelID + " for " + roomsOrdered + " rooms was processed successfully with a total of $" + totalPrice; //String failure = "Order " + orderID + " for Agency " + agencyID + " failed to proccess"; lock (this) { //Console.WriteLine("Thread{2} : Orderporcess ..{0}..,{1}", quotedPrice, roomPrice,Thread.CurrentThread.ManagedThreadId); //Console.WriteLine("OrderProcess***********" + this); if (BankService.validateCard(encrypt.Encrypt(cardNo)) == false) { ReceiptBuffer.setBuffer(agencyID, "The card number for Order " + orderID + " booked with Hotel " + hotelID + " is invalid"); } else if (roomsOrdered > roomsAvailable) { ReceiptBuffer.setBuffer(agencyID, "The number of rooms ordered in Order " + orderID + " booked with " + hotelID + " is greater than the available rooms"); } else if ((int)quotedPrice != (int)price1) { //Console.WriteLine("Thread:"+Thread.CurrentThread.ManagedThreadId+" Orderporcess ..The quoted price for Order " + orderID + " for Agency " + agencyID + " of $" + quotedPrice + " does not match the current price of $" + roomPrice); ReceiptBuffer.setBuffer(agencyID, "The quoted price for Order " + orderID + " booked with Hotel " + hotelID + " of $" + quotedPrice + " does not match the current price of $" + price1); } else { roomsAvailable = roomsAvailable - roomsOrdered; ReceiptBuffer.setBuffer(agencyID, success); } } } catch (Exception e) { Console.WriteLine(e.Message); } }