/// <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();
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        /// <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);
            }
        }
Beispiel #4
0
            /// <summary>
            /// This function is the core of the Price model class. It uses the attributes of the price model to
            /// </summary>
            /// <returns>The new hotel price of its rooms</returns>
            public decimal generateNewPrice()
            {
                //Price Modifiers:
                decimal price_increase = 0; //Initial value of the price increase modifier.
                decimal price_discount = 1; //Initial value of the price decrease modifier.

                //If the availability of rooms is less than half (less supply), the drive for demand goes up, OR IF IT IS THE WEEKDAY:
                if ((this.available_number_of_rooms < (Hotel.MAX_ROOMS / 3)) || ((mod_count % 7) < 5))
                {
                    //Increase by 20%:
                    price_increase = BankService.formatCurrency((decimal)(this.current_price * 1.02M));
                }

                //If it is the (6 == ) Sunday discount or  wild card discount, apply the discount:
                Random wildcard         = new Random();
                int    wildCardSpecials = wildcard.Next(0, 7);

                if ((wildCardSpecials > 3) || (((mod_count % 7) > 4)))
                {
                    //Set the discount modifier to 1.2 or essentially taking 20% off if there is a price increase, if there is no high demand, take 45% off hotel room price for weekends.
                    price_discount = (price_increase == 0) ? BankService.formatCurrency(1.35M) : BankService.formatCurrency(1.20M);
                }
                mod_count++;


                this.current_price = BankService.formatCurrency(((this.current_price + price_increase) / price_discount));  //The actual Price model function.

                if (this.current_price < Hotel.MIN_PRICE)
                {
                    this.current_price = BankService.formatCurrency(Hotel.MIN_PRICE);
                }                                                                                                                        //Adjust price if model goes over minimum Hotel price.
                else if (this.current_price > Hotel.MAX_PRICE)
                {
                    this.current_price = BankService.formatCurrency(Hotel.MAX_PRICE);
                }                                                                                                            //Adjust price if model goes over maximum Hotel price
                //this.current_price = test.Next(MIN_PRICE,MAX_PRICE+1);
                return(this.current_price);                                                                                  //Return the new price.
            }
Beispiel #5
0
        /// <summary>
        /// This function is for use of External Services. Provided a credit card number and an amount to charge to the credit card number, this function verifies the card, and the amount to charge.
        /// That is, provided the card exists, and the client associated to that card has sufficient funds, the client will be charged the specified amount, and the function will return a confirmation
        /// to the calling service.
        /// </summary>
        /// <param name="credit_card_number">The credit card number to charge.</param>
        /// <param name="amt_to_charge">the amount to charge to the account associated to the specified credit card number.</param>
        /// <returns>Returns a "valid" confirmation if the account was successfully charged, and "not valid" if the account was not succesfully charged.</returns>
        public static Boolean confirmCreditCard(String credit_card_number, String amt_to_charge)
        {
            //Decrypt Received data:
            String cc_decrypted_data  = decryptReceivedData(credit_card_number);
            String amt_decrypted_data = decryptReceivedData(amt_to_charge);

            //Convert decrypted String data to integer representation of credit card number:
            Int32   cc_number           = Convert.ToInt32(cc_decrypted_data);
            decimal amount_to_charge_cc = BankService.formatCurrency(Convert.ToDecimal(amt_decrypted_data));

            //Confirm Valid account with provided credit card number:
            if (clients.ContainsKey(cc_number))
            {
                //If Client has sufficient funds, charge the client's account and return a valid confirmation:
                if (withdrawFromClientAmount(amount_to_charge_cc, cc_number))
                {
                    //Return valid confirmation:
                    return(true);
                }
            }

            //Else return not valid confirmation:
            return(false);
        }
Beispiel #6
0
        /// <summary>
        /// This is the main function/method, where the application logic ties together all of the classes and services in this project into a meaningful, event-driven application.
        /// </summary>
        /// <param name="args">Any commandline arguments passed in. This application does not use this however.</param>
        static void main(string[] args)
        {
            const int NUM_OF_HOTELS          = 1;
            const int NUM_OF_TRAVEL_AGENCIES = 2;

            //Print Out the E-Commerce ecosystem setup:
            //--------------------------------------------------------------------------------
            Console.WriteLine("E-Commerce System:");
            Console.WriteLine("Number of Hotels: {0}", NUM_OF_HOTELS);
            Console.WriteLine("Number of Travel Agencies: {0}", NUM_OF_TRAVEL_AGENCIES);
            Console.WriteLine();
            //--------------------------------------------------------------------------------

            Console.WriteLine("Simply press the enter key to run ecommerce simulation.\nEnter \"esc\" to cancel start of ecommerce");
            Console.Write(": ");
            string input = Console.ReadLine();

            if (input == "esc")
            {
                Console.WriteLine("Exiting E-Commerce Simulation Program...");  //Notify User that application is exiting.
                System.Environment.Exit(0);                                     //Safely Exit main program/function.
            }
            //Otherwise continue on with the Simulation:

            ArrayList travel_agencies = new ArrayList();
            ArrayList hotel_threads   = new ArrayList();

            Random rand = new Random();                     //Create a random number generator to randomly select the amount of money a travel agency with set up their bank account with.

            //Generate all of the Travel Agencies. have them apply for a new account with the bank, and finally, store them in the travel agency list:
            for (int i = 0; i < NUM_OF_TRAVEL_AGENCIES; i++)
            {
                //Create a new travel agency, giving it it's own unique id:
                TravelAgency new_agency = new TravelAgency("ta_" + i);

                //Have the new travel agency apply for a new credit card number with the bank. The bank will create an account for the travel agency with the amount they deposited and
                //issue them a new credit card number. Set the new agency's credit card number to this issued value returned by the Bnak's addClient function.:
                new_agency.setCCNumber(BankService.addClient(new_agency.getID(), rand.Next(1500, 5001)));

                //Finally, store the new agency in the travel agenct arraylist:
                travel_agencies.Add(new_agency);
            }//END FOR LOOP.


            //Generate all of the Hotels, and have each of the travel agencies subscribe to each of the Hotel's priceCut events, finally store each hotel as a new thread in the hotels arraylist:
            for (int i = 0; i < NUM_OF_HOTELS; i++)
            {
                //Create a new hotel giving it a unique id:
                Hotel new_hotel = new Hotel("ht_" + i);

                //For each travel agency, have it subscribe to this new hotel's price cut event:
                for (int t = 0; t < NUM_OF_TRAVEL_AGENCIES; t++)
                {
                    new_hotel.subscribeHandlerToPriceCutEvents(((TravelAgency)travel_agencies[t]).hotelPriceBeenCut);
                }

                //Store the new Hotel as a new thread in the arraylist:
                hotel_threads.Add(new Thread(new_hotel.hotelFunc));
            }//END FOR LOOP.

            //Once Everything has been initialized:

            //Start all of the Hotel Threads that were setup and stored in an arraylist earlier:
            for (int i = 0; i < hotel_threads.Count; i++)
            {
                ((Thread)hotel_threads[i]).Start();//Call the thread's Start() function.
            }


            //Finally, as the Threads finish, join:
            for (int i = 0; i < hotel_threads.Count; i++)
            {
                ((Thread)hotel_threads[i]).Join();//Call the thread's Join() function.
            }

            //Give a good enough to for all the threads to finish up and close out:
            Thread.Sleep(1000);
            Console.WriteLine("Program Terminating...");
        } //END MAIN METHOD.
Beispiel #7
0
 /// <summary>
 /// This is the args constructor of the PriceModel Class.
 /// </summary>
 /// <param name="price">The current price of the Hotel's rooms.</param>
 /// <param name="available_rooms">The current number of available rooms in the Hotel.</param>
 public PriceModel(decimal price, int available_rooms)
 {
     this.current_price             = BankService.formatCurrency(price);
     this.available_number_of_rooms = available_rooms;
     this.mod_count = 0;
 }
Beispiel #8
0
 /// <summary>
 /// This Getter function returns the total amount a Client has in the Bank in the proper format (to 2 decimal places).
 /// </summary>
 /// <returns>The decimal amount a Client has in the bank.</returns>
 public decimal getClientAmount()
 {
     return(BankService.formatCurrency(this.amount));//properly round decimal value for accuracy whilst handling currency.
 }
Beispiel #9
0
 /// <summary>
 /// This is an args constructor of the private Client class in the BankService class. This function constructs a new Client, provided a new credit card number, client ID, and an initial amount.
 /// </summary>
 /// <param name="cId">The new Client's ID that the banking system uses to identify the customer/client with.</param>
 /// <param name="cNumber">The new client's credit card number, which will be used for various transactions.</param>
 /// <param name="amt">The currecny amount that the client has in the banking system.</param>
 public Client(String cId, int cNumber, decimal amt)
 {
     this.clientID = cId;
     this.cardNo   = cNumber;
     this.amount   = BankService.formatCurrency(amt);
 }