Exemplo n.º 1
0
        //Function to get order fom buffer and process the order
        // and to call the changePrice function based of new price
        public void AirlineFunc(string name)
        {
            while (true)

            {
                if (Program.buffer_count == 0 && Flag == 1) // exit the loop
                {
                    break;
                }
                Thread.Sleep(1000);

                string orderencoded = "";
                Console.WriteLine("number of price cuts:" + countPriceCuts);



                orderencoded = Program.m.Get();  // get the order from buffer


                if (orderencoded != "")
                {
                    Flag = 1;
                    OrderObject orderDecoded = encoderDecoder.decrypt(orderencoded); // decrypt the order

                    //Decide the price based on the orders
                    if (name == orderDecoded.getReceiverID())  // if the order is for this airline thread
                    {
                        Console.WriteLine("Processing the order for " + orderDecoded.getReceiverID() + " of amount " + orderDecoded.getAmount() + "for " + orderDecoded.getSenderID());
                        Thread orderProc = new Thread(new ThreadStart(() => op.orderFunc(orderDecoded))); //  createthread  and start the processing of order
                        orderProc.Start();
                        Program.m.delete_from_Cell(encoderDecoder.encrypt(orderDecoded));                 // delete the order form multicell buffer
                        total_number_order++;
                    }
                }

                if (i < 14) // iterate through price table to check for price cuts
                {
                    p = price_table[i];
                    i++;
                }
                if (countPriceCuts < 10) // if pricecut less than 10 then call the changePrice function
                {
                    changePrice(name, p);
                }
            }

            //Print the summary for each airline thread
            Console.WriteLine(" ");
            Console.WriteLine("SUMMARY FOR AIRLINE: " + Thread.CurrentThread.Name);
            Console.WriteLine("Total Price cut events " + countPriceCuts.ToString());
            Console.WriteLine("Total orders from travel agents for this airline " + total_number_order.ToString());
            Console.WriteLine("Successfull orders for this airline " + (total_number_order - op.getRejected_order()).ToString());
            Console.WriteLine("Total Rejected orders for this airline " + op.getRejected_order().ToString());
            Console.WriteLine(" ");

            // Terminate the thread of processing is done with required amount of pricecut
            abort = 1;
            Thread.CurrentThread.Abort();
        }
Exemplo n.º 2
0
        public Int32 rejected_order = 0;   // get the count of rejected order
        public void orderFunc(OrderObject order)
        {
            // get the card number for the order
            int cardNo = order.getCardNum();

            // check if the card is vald
            if (cardNo >= 5000 && cardNo <= 7000)
            {
                // get the total amount of the order
                double orderTotal = order.getUnitPrice() * order.getAmount() * .081;
                string recev_id   = order.getReceiverID();

                // order valid , so put the order in the confirmation buffer
                Program.confirmed_order.Put(order.getSenderID(), orderTotal, recev_id);
            }
            else
            {
                rejected_order++; // if order rejected then increament the count of rejected order
            }
        }
Exemplo n.º 3
0
        //Function to encrypt the order
        public static string encrypt(OrderObject oo)
        {
            string encrypted = oo.getSenderID() + ":" + oo.getCardNum() + ":" + oo.getReceiverID() + ":" + oo.getAmount() + ":" + oo.getUnitPrice();

            return(encrypted);
        }