예제 #1
0
        //To get order from the order buffer cell
        public OrderClass getOneCell()
        {
            Monitor.Enter(this);
            read_pool.WaitOne();
            OrderClass orderOutput = null;

            lock (this)
            {
                while (count <= 0)
                {
                    try
                    {
                        Monitor.Wait(this); //If no cells are full, the current thread waits
                    }
                    catch { }
                }

                orderOutput = orders_buffer[read_index]; //reading an order

                if (orderOutput != null)
                {
                    this.orders_buffer[read_index] = null;
                    read_index = (read_index + 1) % 2;
                    count--;
                    Console.WriteLine("Order {0} is fetched from the buffer cell", orderOutput.getSenderId());
                }


                read_pool.Release();
                Monitor.Pulse(this);
                Monitor.Exit(this);
            }

            return(orderOutput);
        }
예제 #2
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");
     }
 }
예제 #3
0
파일: Park.cs 프로젝트: Lokeshwar0304/445
        //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
        }