public void EventHandler_ConfirmationStatus(string message)
        {
            Decoder decode_test = new Decoder();
            OrderClass obj = new OrderClass();
            obj = decode_test.decryptString(message);

            if (obj.get_senderId() == this.name)
            {
                Console.WriteLine("\n\n\n***************  ORDER STATUS  ***************");
                Console.WriteLine("Travel {0} placed an order of {1} ticktes to Airline {2}", obj.get_senderId(), obj.get_amount(), obj.get_receiverId());
                Console.WriteLine("The price of each ticket is ${0}", obj.get_unitprice());
                Console.WriteLine("The total amount charged is : ${0}", obj.get_totalamount());
                Console.WriteLine("The order is charged to card number  : {0}", obj.get_cardNo());

                if (obj.get_confirmationstatus())
                {
                    Console.WriteLine("Congratulations !! the order has been processed. Have a safe Flight !");
                }
                else
                {
                    Console.WriteLine("No Tickets Available. Your order could not be processed at this time !");
                }

                stopWatch.Stop();
                timeSpan = stopWatch.Elapsed;
                Console.WriteLine("Total time taken for order confirmation: " + timeSpan.Milliseconds);

                Console.WriteLine("**************************************************");
                Console.WriteLine("\n\n\n");

            }
        }
        public static string getOneCell(string AirlineName)
        {
            if (sem_empty.WaitOne(300))
            {
                for (int i = 0; i < 3; i++)
                {
                    if (IsEmpty[i] == false)
                    {
                        string ObjectString = buffer[i];
                        Decoder decode_test = new Decoder();
                        OrderClass obj = new OrderClass();
                        if (ObjectString != null)
                        {
                            obj = decode_test.decryptString(ObjectString);
                            //Console.WriteLine("string name passed is {0} actual name is {1}", AirlineName, obj.get_receiverId());
                            if (obj.get_receiverId() == AirlineName)
                            {
                                //Console.WriteLine("Readposition is {0}\n", i);
                                mutex_lock.WaitOne();
                                buffer[i] = null;
                                IsEmpty[i] = true;
                                mutex_lock.ReleaseMutex();
                                sem_full.Release();
                                return ObjectString;
                            }
                        }

                    }
                }
                sem_empty.Release();
            }
            return null;
        }
        public void OrderProcessingFun(OrderClass obj_1)
        {
            Encoder encode = new Encoder();
            senderId = obj_1.get_senderId();
            cardNo = obj_1.get_cardNo();
            receiverId = obj_1.get_receiverId();
            amount = obj_1.get_amount();
            unitprice = obj_1.get_unitprice();

            string encodedString;

            if (!IsValidCardNo(cardNo) || amount == 0)
            {
                obj_1.set_confirmationstatus(false);
                obj_1.set_totalamount(0);
                encodedString = encode.encryptString(obj_1);
              //  ConfirmationBuffer.setOneCell(encodedString);

            }
            else
            {
                CalculatePrice();
                obj_1.set_confirmationstatus(true);
                obj_1.set_totalamount(TotalAmount);

                encodedString = encode.encryptString(obj_1);
            //    ConfirmationBuffer.setOneCell(encodedString);

            }
            if (encodedString != null)
            {
                OrderConfirmation(encodedString);
            }
        }
        private OrderClass generate_obj()
        {
            OrderClass obj = new OrderClass();

            timeSpan = TimeSpan.Zero;

            obj.set_senderId(name);
            obj.set_cardNo(rnd.Next(1000, 9000));
            obj.set_receiverId(AirlineName);
            obj.set_amount(rnd.Next(3, 15));
            obj.set_unitprice(thread_price);
            obj.set_totalamount(0);
            obj.set_confirmationstatus(false);

            return(obj);
        }
Пример #5
0
        public string encryptString(OrderClass order)
        {
            try
            {
                temp = (order.get_senderId()) + "," + Convert.ToString(order.get_cardNo()) + "," + (order.get_receiverId())
                    + "," + Convert.ToString(order.get_amount()) + "," + Convert.ToString(order.get_unitprice()) + "," +
                    Convert.ToString(order.get_totalamount()) + "," + Convert.ToString(order.get_confirmationstatus());

                encryptedString = client.Encrypt(temp);
            }
            catch(Exception e)
            {
                Console.WriteLine("Exception Occured while Encoding" + e.Message.ToString());
            }

            return encryptedString;
        }
Пример #6
0
        public string encryptString(OrderClass order)
        {
            try
            {
                temp = (order.get_senderId()) + "," + Convert.ToString(order.get_cardNo()) + "," + (order.get_receiverId())
                       + "," + Convert.ToString(order.get_amount()) + "," + Convert.ToString(order.get_unitprice()) + "," +
                       Convert.ToString(order.get_totalamount()) + "," + Convert.ToString(order.get_confirmationstatus());

                encryptedString = client.Encrypt(temp);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception Occured while Encoding" + e.Message.ToString());
            }

            return(encryptedString);
        }
        public void TravelAgencyFun()
        {
            while (Program.AirlineThread1.IsAlive || Program.AirlineThread2.IsAlive || Program.AirlineThread3.IsAlive)
            {
                if (this.flag)
                {
                    OrderClass obj = new OrderClass();
                    obj = generate_obj();

                    Encoder encode_test = new Encoder();
                    encodedOrderString = encode_test.encryptString(obj);
                    stopWatch.Start();

                    MultiCellBuffer.setOneCell(encodedOrderString);
                    //Console.WriteLine("Travel Agency Sender id {0} receiver id {1} Amount {2} Unitprice {3}", obj.get_senderId(), obj.get_receiverId(), obj.get_amount(), obj.get_unitprice());
                    OrderCount++;

                    this.flag = false;
                }
            }
        }
Пример #8
0
        public void AirlineFun()
        {
            while (Program.AirlineThread1.IsAlive || Program.AirlineThread2.IsAlive || Program.AirlineThread3.IsAlive || NullCount < 6)
            {
                string multiCell = MultiCellBuffer.getOneCell(this.name);
                if (multiCell != null)
                {
                    NullCount = 0;
                    Decoder decode_test = new Decoder();
                    OrderClass obj = new OrderClass();

                    obj = decode_test.decryptString(multiCell);

                    Console.WriteLine("\n\n------------ ORDER SENT --------------");
                    Console.WriteLine("Travel {0} is placing an order for {1} tickets to {2}",obj.get_senderId(),obj.get_amount(),obj.get_receiverId());
                    Console.WriteLine("The price for each ticket is : ${0}", obj.get_unitprice());
                    Console.WriteLine("-------------------------------------------\n\n");
                    this.remaining_tickets = this.remaining_tickets - obj.get_amount();
                    //Console.WriteLine("Remaining tic {0} {1}", this.remaining_tickets, obj.get_receiverId());

                    if (this.remaining_tickets < 0)
                    {
                        //Console.WriteLine("Amount not processed is {0} {1}", obj.get_amount(), obj.get_receiverId());
                        obj.set_amount(0);
                    }

                    OrderProcessing order = new OrderProcessing();
                    Thread OrderProcessingThread = new Thread(() => order.OrderProcessingFun(obj));
                    OrderProcessingThread.Start();
                    OrderProcessingThread.Join();
                    //Console.WriteLine("{0} Thread created", obj.get_receiverId());

                }
                    else
                {
                    NullCount++;
                }
                //Thread.Sleep(1000);
            }
        }
Пример #9
0
        public void AirlineFun()
        {
            while (Program.AirlineThread1.IsAlive || Program.AirlineThread2.IsAlive || Program.AirlineThread3.IsAlive || NullCount < 6)
            {
                string multiCell = MultiCellBuffer.getOneCell(this.name);
                if (multiCell != null)
                {
                    NullCount = 0;
                    Decoder    decode_test = new Decoder();
                    OrderClass obj         = new OrderClass();

                    obj = decode_test.decryptString(multiCell);

                    Console.WriteLine("\n\n------------ ORDER SENT --------------");
                    Console.WriteLine("Travel {0} is placing an order for {1} tickets to {2}", obj.get_senderId(), obj.get_amount(), obj.get_receiverId());
                    Console.WriteLine("The price for each ticket is : ${0}", obj.get_unitprice());
                    Console.WriteLine("-------------------------------------------\n\n");
                    this.remaining_tickets = this.remaining_tickets - obj.get_amount();
                    //Console.WriteLine("Remaining tic {0} {1}", this.remaining_tickets, obj.get_receiverId());

                    if (this.remaining_tickets < 0)
                    {
                        //Console.WriteLine("Amount not processed is {0} {1}", obj.get_amount(), obj.get_receiverId());
                        obj.set_amount(0);
                    }

                    OrderProcessing order = new OrderProcessing();
                    Thread          OrderProcessingThread = new Thread(() => order.OrderProcessingFun(obj));
                    OrderProcessingThread.Start();
                    OrderProcessingThread.Join();
                    //Console.WriteLine("{0} Thread created", obj.get_receiverId());
                }
                else
                {
                    NullCount++;
                }
                //Thread.Sleep(1000);
            }
        }
Пример #10
0
        public void TravelAgencyFun()
        {
            while (Program.AirlineThread1.IsAlive || Program.AirlineThread2.IsAlive || Program.AirlineThread3.IsAlive)
                {
                    if (this.flag)
                    {
                        OrderClass obj = new OrderClass();
                        obj = generate_obj();

                        Encoder encode_test = new Encoder();
                        encodedOrderString = encode_test.encryptString(obj);
                        stopWatch.Start();

                        MultiCellBuffer.setOneCell(encodedOrderString);
                        //Console.WriteLine("Travel Agency Sender id {0} receiver id {1} Amount {2} Unitprice {3}", obj.get_senderId(), obj.get_receiverId(), obj.get_amount(), obj.get_unitprice());
                        OrderCount++;

                        this.flag = false;
                    }
                }
        }
Пример #11
0
        private OrderClass generate_obj()
        {
            OrderClass obj = new OrderClass();
                timeSpan = TimeSpan.Zero;

                obj.set_senderId(name);
                obj.set_cardNo(rnd.Next(1000, 9000));
                obj.set_receiverId(AirlineName);
                obj.set_amount(rnd.Next(3, 15));
                obj.set_unitprice(thread_price);
                obj.set_totalamount(0);
                obj.set_confirmationstatus(false);

                return obj;
        }