Ejemplo 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();
        }
Ejemplo n.º 2
0
        // Function to decrypt the order
        public static OrderObject decrypt(String s)
        {
            String[]    items = s.Split(':');
            OrderObject order = new OrderObject(items[0], Convert.ToInt32(items[1]), items[2],
                                                Convert.ToInt32(items[3]), Convert.ToDouble(items[4]));

            return(order);
        }
Ejemplo n.º 3
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
            }
        }
Ejemplo n.º 4
0
        //Function to check if there has been a reduction in price from airline 1 or airline 2. If yes then the order will be placed
        public void order()
        {
            while (Program.air1.countPriceCuts < 10 || Program.air2.countPriceCuts < 10)
            {
                if (currentFlightPrice < previousFlightPrice || currentFlightPrice2 < previousFlightPrice2)
                {
                    //if pricecut accours for airline 1
                    if (airline_name1 == "airline1" && Program.air1.countPriceCuts < 10)
                    {
                        Console.WriteLine("Pacing order for   " + Thread.CurrentThread.Name + "for airline " + airline_name1 + " for number of tickets " + number_of_tickets.ToString() + " tickets");

                        // creating new order object
                        OrderObject newOrder = new OrderObject(Thread.CurrentThread.Name, OrderObject.generateRandomCreditCardNo(), airline_name1, number_of_tickets, currentFlightPrice);

                        // encrypting the order object
                        string encryptedObject = encoderDecoder.encrypt(newOrder);

                        // put the encrypted order in multicell buffer
                        Program.m.Put(encryptedObject);
                        Program.placed_order++;
                        airline_name1 = null;  // remove the airline name so that it doesnt places the same order again
                    }

                    //if pricecut accours for airline 1
                    else if (airline_name2 == "airline2" && Program.air2.countPriceCuts < 10)
                    {
                        Console.WriteLine("Placing order for  " + Thread.CurrentThread.Name + "for airline " + airline_name2 + " for  " + number_of_tickets.ToString() + " tickets");
                        // creating new order object
                        OrderObject newOrder = new OrderObject(Thread.CurrentThread.Name, OrderObject.generateRandomCreditCardNo(), "airline2", number_of_tickets, currentFlightPrice2);

                        // encrypting the order object
                        string encryptedObject = encoderDecoder.encrypt(newOrder);

                        // put the encrypted order in multicell buffer
                        Program.m.Put(encryptedObject);
                        Program.placed_order++;
                        airline_name2 = null; // remove the airline name so that it doesnt places the same order again
                    }
                }
            }
        }
Ejemplo n.º 5
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);
        }