/// <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(); }
private int credit_card; //Variable to hold credit card number //---------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// This is the args constructor of the TravelAgency class. /// </summary> /// <param name="agency_id">String to be set as the id of this TravelAgency</param> public TravelAgency(string agency_id) { //Set TravelAgencies ID: this.agency_id = agency_id; //Add function Handler for processed orders: OrderProcessing.addOrderBeenProcessedListener(processedOrder); }
private event PriceCut price_cut_event; //A PriceCut event variable for the Hotel to emit to it's subscribers. //---------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// This is the args constructor of the Hotel class. /// </summary> /// <param name="new_id">The unique string representation of an id for identifying and instance of this class.</param> public Hotel(string new_id) { this.id = new_id; // Initialize the Hotel's ID. this.current_number_of_available_rooms = MAX_ROOMS; // Initialize the Hotel's this.current_pricecuts_made = 0; // Instantiate the current number of price cuts made. 20 is the max. this.price_model = new PriceModel(this.price, this.current_number_of_available_rooms); // Instantiate a new Price Model object for this Hotel. this.price = BankService.formatCurrency(((Hotel.MAX_PRICE + Hotel.MIN_PRICE) / 2)); // TODO::Initialize first price value using the price model; OrderProcessing.addOrderToProcessListener(orderProcessHandler); }
/// <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 is subscribed to an OrderToBeProcessed Event and handles it using the orderProcessor function in the OrderProcessing class. /// </summary> /// <param name="hotel_id">The Id of the hotel that needs to process the respective order that triggered the orderToBeProcessed event</param> public void orderProcessHandler(string hotel_id) { //If this Hotel matches with this event that emitted this: if (this.id == hotel_id) { //Get encoded orderObject string from MultiCellBuffer: string encoded_order__object_to_process = OrderProcessing.getOrderToProcess(this.id); //Process Order via the OrderProcessing class: OrderProcessing.orderProcessor(encoded_order__object_to_process); }//END IF STATEMENT }
/// <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(); }