Пример #1
0
        //method to receive an OrderObject from the MultiCellBuffer
        public void runOrderFunc()
        {
            OrderClass order = Program.multiCellBuffer.getOneCell(); //to fetch an order from MultiCellBuffer

            Console.WriteLine("creating a new orderProcessing thread to process {0} order for {1} tickets for the price ${2}", order.getSenderId(), order.getAmount(), getcurrent_price());
            Thread threadObj = new Thread(() => OrderProcessing.processOrder(order, getcurrent_price())); //creating a new orderProcessing thread to process the order

            threadObj.Start();                                                                            // start the thread to process the request
        }
Пример #2
0
        //function to create a new order
        private void createOrderFunc(string senderId)
        {
            int cardNo = RandomClass.getNext(5000, 7000);                                         //to generate a random card number
            int amount = RandomClass.getNext(10, 200);                                            //to generate a random number of tickets

            OrderClass order = new OrderClass(senderId, cardNo, amount, PricingModel.getPrice()); // new order object

            Console.WriteLine("{0}'s order with {1} tickets has been created at {2}", senderId, amount, DateTime.Now.ToString("hh:mm:ss"));

            Program.multiCellBuffer.setOneCell(order); // insert the new order into multicellbuffer

            orderCreated();
        }
Пример #3
0
 // method to instantiate a new thread to process the order
 public static void processOrder(OrderClass order, double unitPrice)
 {
     if (validateCreditCard(order.getCardNo()))                                     //checking the validity of the credit card
     {
         double tax         = unitPrice * order.getAmount() * TaxPercentage;        //tax=unitprice * orderamount * 0.06
         double totalCharge = unitPrice * order.getAmount() + tax + LocationCharge; //totalcharge=unitprice * orderamount + tax + locationcharge
         orderProcessed(order.getSenderId(), Convert.ToInt32(totalCharge), unitPrice, order.getAmount());
     }
     else
     {
         Console.WriteLine("Invalid credit card number");
     }
 }