/// <summary> /// This takes an OrderObject to be confirmed, and creates a timestamp of when this is called as well as writing to Console /// </summary> /// <param name="order_confirm">The OrderObject retreived from the ProcessedOrder MultiCellBuffer.</param> private void confirmOrder(OrderObject order_confirm) { string timeStamp = DateTime.Now.ToString(); //Create a time stamp for when order is confirmed //Print Order Confirmation received message: Console.WriteLine("Travel Agency {0} received a new order confirmation:", this.agency_id); //Print header and Body of Order Confirmation Receipt: Console.WriteLine("---------------------------------"); Console.WriteLine("Order Confirmation:"); Console.WriteLine("Agency ID: {0}", order_confirm.getSenderID()); Console.WriteLine("Hotel ID: {0}", order_confirm.getReceiverID()); Console.WriteLine("Rooms Ordered: {0}", order_confirm.getNumberOfRoomsOrdered()); Console.WriteLine("Room Price: {0}", order_confirm.getUnitPrice()); Console.WriteLine("Total(+tax): {0}", order_confirm.getAmount()); if (order_confirm.isValid()) { Console.WriteLine("Order Confirmation: VALID"); } else { Console.WriteLine("Order Confirmation: NOT VALID"); } //Footer of the Order Confirmation Receipt: Console.WriteLine("TimeStamp: {0}", timeStamp); Console.WriteLine("---------------------------------"); Console.WriteLine(); }
/// <summary> /// The Function that actually processes an order, Validates Order with the BankService and returns a confirmation. /// </summary> /// <param name="encoded_order_object">The encoded OrderObject string to process as an OrderObject, once it is decoded of course.</param> public static void orderProcessor(string encoded_order_object) { //Decode string into an object: OrderObject new_order_object = EnDecoder.Decode(encoded_order_object); //Update total amount to account for Sales tax: decimal total = BankService.formatCurrency((new_order_object.getAmount() + (new_order_object.getAmount() * SALES_TAX))); new_order_object.setAmount(total); //Create an encryption service via ASU's Repo: Service encryption = new Service(); //Encrypt the credit card number: string encrypted_cc_number = encryption.Encrypt(Convert.ToString(new_order_object.getCardNo())); //encrypt the total amount to charge the account: string encrypted_amount = encryption.Encrypt(Convert.ToString(new_order_object.getAmount())); //Have Bank validate the Account charge given the encrypted credit card number and amount to charge: new_order_object.setIsValid(BankService.confirmCreditCard(encrypted_cc_number, encrypted_amount)); //Get the Travel_agencies ID: string travel_agency_id = new_order_object.getSenderID(); //Encode the Processed Order Object: string encoded_processed_order = EnDecoder.Encode(new_order_object); //Create a new thread to handle the processed order: OrderProcessing.submitProcessedOrderObject(encoded_processed_order, travel_agency_id); Thread processed_order_thread = new Thread(() => OrderProcessing.submitProcessedOrderObject(encoded_processed_order, travel_agency_id)); //Start the thread: processed_order_thread.Start(); }
/// <summary> /// This takes the ID of the TravelAgency it will be processing for and checks for correct destination. It then processes the order and confirms it. /// </summary> /// <param name="travel_agency_id">The travelAgency id that was emitted </param> public void processedOrder(string travel_agency_id) //Method to check if order was meant for specific travel agency and confirm it { if (travel_agency_id == this.agency_id) //Basic check for correct agency ID { string encryptedOrder = OrderProcessing.getProcessedOrderObject(this.agency_id); //Encrypted order is retrieved from OrderProcessing OrderObject newOrder = EnDecoder.Decode(encryptedOrder); //decrypt order via decode method in EnDecoder confirmOrder(newOrder); //confirm the order of the neworder that was created (and also holds timestamp!) } }
/// <summary> /// This function takes in an OrderObject and "encodes" it into a string format. /// </summary> /// <param name="orderObj">The OrderObject to encode into a string.</param> /// <returns>The "encoded" string representation of the OrderObject passed in.</returns> public static String Encode(OrderObject orderObj) { //Generate the new string to be the "encoded" orderObject: string orderObj_toString = orderObj.getSenderID(); orderObj_toString += (" " + orderObj.getReceiverID()); orderObj_toString += (" " + orderObj.getCardNo()); orderObj_toString += (" " + orderObj.getAmount()); orderObj_toString += (" " + orderObj.getUnitPrice()); //Return the encoded String of the orderObject passed in: return(orderObj_toString); }
/// <summary> /// This takes an OrderObject and encrypts it into a string. /// </summary> /// <param name="order">The OrderObject to place an order with.</param> private void placeOrder(OrderObject order) { //Get the ID of the hotel who will receive this order for processing: string hotel_id = order.getReceiverID(); //encrypt the orderobject into a string: string encrypted_order = EnDecoder.Encode(order); //Create a new OrderProcessing thread to handle the unprocessed order: Thread place_order_thread = new Thread(() => OrderProcessing.submitOrderToProcess(encrypted_order, hotel_id)); //Start the thread: place_order_thread.Start(); }
/// <summary> /// This function takes in a string which has an OrderOjbect "encoded" into it, and decodes it back into an OrderObject. /// </summary> /// <param name="orderStr">The "encoded" OrderObject string to decode into an OrderObject.</param> /// <returns>The OderObject that was "decoded" from the "encoded" data passed in.</returns> public static OrderObject Decode(string orderStr) { //"decode" the "encoded" data: string[] orderData = orderStr.Split(' '); //Create a new orderObject to set up with the "decoded" data: OrderObject orderObj = new OrderObject(); //Set up orderObject based on data in the encoded string: orderObj.setSenderID(orderData[0]); //Set the Sender ID orderObj.setReceiverID(orderData[1]); //Set the receiver ID orderObj.setCardNo(Convert.ToInt32(orderData[2])); //Set the Card Number orderObj.setAmount(Convert.ToDecimal(orderData[3])); //Set the Amount orderObj.setUnitPrice(Convert.ToDecimal(orderData[4])); //Set the Unit Price orderObj.setIsValid(Convert.ToBoolean(orderData[5])); //Set the Order Validator orderObj.setRoomsOrdered(Convert.ToInt32(orderData[6])); //Return the newly orderObject that has been created from the "decoded" data: return(orderObj); }
/// <summary> /// This is the main function that handles hotel price cuts via PriceCut delegate created in Hotel.cs /// </summary> /// <param name="current_price">the current price of rooms in the Hotel.</param> /// <param name="new_price">the new price of rooms in the Hotel.</param> /// <param name="available_rooms">the current number of available rooms in the Hotel.</param> /// <param name="hotel_id">The string id of the Hotel.</param> public void hotelPriceBeenCut(decimal current_price, decimal new_price, int available_rooms, string hotel_id) //Using delegate in hotel.cs { int rooms_to_order; int demand = 0; //Demand is a variable that will be used as a multiplier for how many rooms to order int sum = Hotel.MAX_PRICE + Hotel.MIN_PRICE; int avg = sum / 2; Boolean do_buy = (new_price > (decimal)(1.15 * avg)) ? false : true; //Take anywhere from 1-25% of the available rooms: Random rand = new Random(); rooms_to_order = (int)(available_rooms / rand.Next(20, 80)); if ((do_buy) && (rooms_to_order > 0)) { decimal amount = BankService.formatCurrency(rooms_to_order * new_price); //create a new order Object: OrderObject new_order_object = new OrderObject(this.agency_id, hotel_id, this.credit_card, rooms_to_order, amount, new_price, false); //Place Order: placeOrder(new_order_object); } }