//method that will be called when an unprocessed order is added to the orderprocessing public void unProcessedOrderAddedToBuffer(int destinationSupplierID) { //the order that was added is intended for this supplier if (destinationSupplierID == this.supplierID) { //get the encrypted order from the order processor string encryptedOrderToProcess = OrderProcessing.getUnProcessedOrder(this.supplierID); //decrypt the string and assign it to an Order Object Order newOrderToProcess = Decoder.Decrypt(encryptedOrderToProcess); //validate the order Boolean orderIsValid = validateOrder(newOrderToProcess); //if the order is valid if (orderIsValid) { //set order as a valid order newOrderToProcess.ValidOrder = true; } //create new thread and send to order processed as processed order //this occurs regardless of whether or not the order was validated //this thread is just creating a new thread to run the method after the => Thread threadToProcessOrder = new Thread(() => OrderProcessing.addProcessedOrder(this.supplierID, Encoder.Encrypt(newOrderToProcess))); //start thread threadToProcessOrder.Start(); } }
//Takes an order decrypts it and creates a new thread to submit the order //to the order processing object private void placeOrder(Order orderToPlace) { //encrypt order the order to string string encryptedOrder = Encoder.Encrypt(orderToPlace); //create thread to place order Thread threadToPlaceOrder = new Thread(() => OrderProcessing.addUnProcessedOrder(orderToPlace.HotelSupplierID, encryptedOrder)); threadToPlaceOrder.Start(); }
public HotelSupplier(int supplierID) { this.supplierID = supplierID; numPriceCuts = 0; //get first random number price = numGenerator.Next(MIN_PRICE, MAX_PRICE); //subscribe to the orderprocessing object to know //when an unprocessed order has been submitted OrderProcessing.callMethodWhenAnNewOrderIsSubmitted(unProcessedOrderAddedToBuffer); }
public TravelAgency(int agencyID) { this.agencyID = agencyID; //apply for a credit card number creditCardNumber = Bank.applyforCreditCard(); //subscribe the travel agency to the OrderProcessing so it can be informed //when an order has been reviewed by the hotel supplier //Without this, the travel agency would never know when their order had been reviewed //the travel agency has to confirm the order when it is returned. OrderProcessing.callMethodWhenAnOrderIsProcessed(processedOrderAddedToBuffer); }
public void processedOrderAddedToBuffer(int destinationTravelAgency) { //the order that was added is intended for this travel agency if (destinationTravelAgency == this.agencyID) { //get the encrypted order from the order processor string encryptedOrderToConfirm = OrderProcessing.getProcessedOrderForAgencyID(this.agencyID); //decrypt the string and assign it to an Order Object Order newOrderToProcess = Decoder.Decrypt(encryptedOrderToConfirm); //print or store a confirmation of the order confirmOrder(newOrderToProcess); } }