コード例 #1
0
        public void processOrder(OrderClass order)
        {
            //EncryptionDecryptionService.ServiceClient encrypt = new EncryptionDecryptionService.ServiceClient();
            myEncryptionService.ServiceClient encrypt = new myEncryptionService.ServiceClient();
            double numOfTickets        = order.GetAmount();
            double unitPrice           = order.GetUnitPrice();
            double tax                 = (numOfTickets * unitPrice) * .08;
            double locationCharge      = 5;
            double charges             = (unitPrice * numOfTickets) + tax + locationCharge;//Calculated total amount
            int    totalAmount         = (int)charges;
            int    creditCardNo        = order.getCardNo();
            String senderId            = order.GetSenderId();
            String encryptedCreditCard = "";
            String message             = "";

            try
            {
                /***1. Encrypt creditCardNo using service***/
                encryptedCreditCard = encrypt.Encrypt(creditCardNo.ToString());
            }
            catch
            {
                /***Failed to Encrypt***/
                Console.WriteLine("Failed Encyption terminating processing order!!, NOTIFYING AGENCY");
                message = "Failed Encyption terminating processing order!!, NOTIFYING AGENCY";
                Console.WriteLine("Done Processing!");
                sendConfirmationRejectMessage(senderId, message);
                return;
            }
            /***2. Charge the credit card***/
            String successfulCharge = MainClass.bank.charge(encryptedCreditCard, totalAmount);

            if (String.Equals(successfulCharge, "valid"))
            {
                /***3. send Confirmation***/
                Console.WriteLine("VALID PURCHASE SENDING CONFIRMATION");
                Console.WriteLine("SerderID: " + senderId);
                Console.WriteLine("Order Amount {0}", totalAmount);
                Console.WriteLine("Tickets ordered {0}", order.GetAmount());
                Console.WriteLine("Oder Unit Price {0} ", unitPrice);
                Console.WriteLine("Done Processing!");
                message = "VALID PURCHASE SENDING CONFIRMATION";
                sendConfirmationRejectMessage(senderId, message);
            }
            else
            {
                /***4. notifiy agency that purchase was denied ***/
                Console.WriteLine("INVALID PURCHASE NOTIFYING AGENCY");
                message = "INVALID PURCHASE NOTIFYING AGENCY";
                Console.WriteLine("Done Processing!");
                sendConfirmationRejectMessage(senderId, message);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ejsuarte2/cs598_Project2
        /***Check that if the price got lower and notify (emit event)
         * subscribers if any are available (subscribed) Process orders
         * received after event emitted and terminate current thread if
         * emmited events reaches 20***/
        public static void ChangePrice(double price)//, string airlineName)
        {
            if (p == priceChangeLimit)
            {
                /**Terminate an airline thread if priceCuts has reached 20**/
                if (Thread.CurrentThread.IsAlive)
                {
                    MainClass.airlinesKilled += 1;
                    Thread.CurrentThread.Abort();
                }
                System.Console.WriteLine("Airline Thread Killed");
                //keeps track of the number of airlines killed
            }
            if (price < ticketPrice)
            {
                if (priceCut != null)
                {
                    priceCut(price);
                    p += 1;

                    /**Example: will process actual result when remaining classes are implemented
                     * Just console writting for now and hardcoding vals**/
                    Thread.Sleep(200);
                    int availableCells = MainClass.mainCellBuffer.getAvailableCells();
                    if (availableCells < 3)
                    {
                        /***1.Receive order from multicellBuffer**/
                        OrderClass orderRetrieved = MainClass.mainCellBuffer.getOneCell();
                        currentOrder = orderRetrieved;
                        totalOrders++;
                        Console.WriteLine("Airline Received Order successfully!");
                        /***2.Create a thread to process the order***/
                        MainClass.rwLock.AcquireReaderLock(200);/***Critical sect: keep Airline threads from interacting with each other***/
                        try
                        {
                            Console.WriteLine("Processing Order!");
                            Thread processOrders = new Thread(new ThreadStart(Airline.OrderProcessingThread));
                            /***3.Process it***/
                            processOrders.Start();
                            /**4. Then Send Confirmation to trvel agency**/
                        }
                        finally
                        {
                            MainClass.rwLock.ReleaseLock();
                        }
                    }
                }
            }

            ticketPrice = price;
        }
コード例 #3
0
 /*event handler: creates an order object for each agency in TravelAgencyData.DataDict and creates
  * and places them in the buffer*/
 public void priceDropOrder(double newPrice, double previousPrice, string airline, string agency)
 {
     try
     {
         Console.WriteLine("Price drop event in Airline {0} from ${1} to ${2}.",
                           airline, previousPrice, newPrice);
         int numTickets = getNumTickets(newPrice, previousPrice);
         /*gets credit card number. and creates account */
         Bank       bank          = MainClass.bank;
         int        creditCardNum = bank.apply(10000);
         OrderClass order         = new OrderClass(agency, creditCardNum, airline, numTickets, newPrice);
         MainClass.mainCellBuffer.setOneCell(order);
     }
     catch
     {
         Console.WriteLine("{0} Could not place order", Thread.CurrentThread.Name);
     }
 }