public static void agencyFunction()
        {
            try
            {
                while (true)
                {
                    Thread.Sleep(3000);
                    lock (lockobj)
                    {
                        if (HotelSupplier.roomPrice1 < HotelSupplier.oldRoomPrice1) // if there is a price drop then a certain range of room are booked.
                        {
                            numberOfRooms = randamount.Next(30, 50);
                        }
                        else
                        {
                            numberOfRooms = randamount.Next(20, 30);
                        }
                        int         cardNumber = randcardNo.Next(5000, 7000);                                                         // uses a random functon to generate a creditcard number
                        OrderObject order      = new OrderObject(Thread.CurrentThread.Name, cardNumber, numberOfRooms, DateTime.Now); //stores the order in the orderobject
                        string      str        = EncodeDecode.encode(order);
                        Program.buffer1.SetCellOne(str);                                                                              // stores the order in the multi cell buffer after encoding

                        //  MultiCellBuffer.SetCellOne(str);

                        Console.WriteLine("\n{0} sent an order of {1} rooms \nTime Stamp Of Order = {2}", Thread.CurrentThread.Name, numberOfRooms, DateTime.Now);
                        Thread.Sleep(500);
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("Error" + e.Message);
            }
        }
Example #2
0
        public static String encode(OrderObject orderObject) // encodes the message and sends it back to the user

        {
            try
            {
                lock (encodeLock)
                {
                    byte[] encodebyte;
                    string order = orderObject.GetSenderId().ToString() + "#" + orderObject.GetCardNo().ToString() + "#" + orderObject.GetAmount().ToString() + "#" + orderObject.creationTime;
                    encodebyte = ASCIIEncoding.ASCII.GetBytes(order);
                    return(Convert.ToBase64String(encodebyte));
                }
            }
            catch (Exception e)
            {
                return(string.Empty);
            }
        }
Example #3
0
        public static void orderProcess(OrderObject orderObject, int currentRoomPrice)
        {
            Thread.Sleep(700);
            try
            {
                lock (lockObject)
                {
                    if (orderObject.GetCardNo() >= 5000 && orderObject.GetCardNo() <= 7000)                 // checks for a valid credit card number
                    {
                        int totalPrice = orderObject.GetAmount() * currentRoomPrice + tax + locationCharge; // calculates the total price including tax and location charge and return

                        Console.WriteLine("\nOrder processed for {0}. \nTotal price for {1} rooms with tax and location charge  = ${2} ", orderObject.GetSenderId(), orderObject.GetAmount(), totalPrice);
                        Console.WriteLine("Time taken for processing in seconds : " + (DateTime.Now - orderObject.creationTime).TotalSeconds + "\n");
                        // TravelAgency.orderConfirmation(orderObject);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occurred in process order method " + e.Message);
            }
        }
        public void HotelSuppliers()
        {
            Console.WriteLine("{0}  --- current room price $150 \n ---------------------------------", Thread.CurrentThread.Name);
            if (Thread.CurrentThread.Name == "hotel supplier 1")
            {
                // creates 5 travel agency threads
                Thread[] agencyThread = new Thread[5];
                for (int i = 0; i < 5; i++)
                {
                    agencyThread[i]      = new Thread(new ThreadStart(TravelAgency.agencyFunction));
                    agencyThread[i].Name = "agency " + (i + 1).ToString();
                    agencyThread[i].Start();
                }
                try
                {
                    while (true)
                    {
                        Thread.Sleep(500);
                        lock (lockObject)
                        {
                            if (counter >= 20)
                            {
                                break;
                            }
                            // gets the order object from the multicellbuffer and decodes it
                            OrderObject orderObject = EncodeDecode.decode(Program.buffer1.GetCellOne());

                            //  Console.WriteLine("{0}-----------", Thread.CurrentThread.Name);
                            int newRoomPrice1 = PricingModel.calculatePrice(roomPrice1);                                       // calls the pricing model to generate a new price
                            PriceChange(newRoomPrice1);                                                                        // checks the new room price using the price change function
                            //  Console.WriteLine("reciept from {0}", Thread.CurrentThread.Name);
                            Thread processingThread = new Thread(() => OrderProcessing.orderProcess(orderObject, roomPrice1)); // creates the order processing threads
                            processingThread.Start();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(" Error in hotel supplier " + e.Message);
                }
            }
            else
            {
                // creates 5 travel agency threads
                Thread[] agencyThread = new Thread[5];
                for (int i = 0; i < 5; i++)
                {
                    agencyThread[i]      = new Thread(new ThreadStart(TravelAgency.agencyFunction2));
                    agencyThread[i].Name = "agency " + (i + 1).ToString();
                    agencyThread[i].Start();
                }


                try
                {
                    while (true)
                    {
                        Thread.Sleep(500);
                        lock (lockObject)
                        {
                            if (counter >= 20)
                            {
                                Thread.Sleep(4500);
                                Console.WriteLine("------------EXCEEDED MAXIMUM ALLOWED PRICE CUTS------------- ");
                                break;
                            }
                            // gets the order object from the multicellbuffer and decodes it
                            OrderObject orderObject = EncodeDecode.decode(Program.buffer1.GetCellOne());

                            //  Console.WriteLine("{0}-----------", Thread.CurrentThread.Name);
                            int newRoomPrice2 = PricingModel.calculatePrice(roomPrice2);                                       // calls the pricing model to generate a new price
                            PriceChange2(newRoomPrice2);                                                                       // checks the new room price using the price change function
                            //  Console.WriteLine("reciept from {0}", Thread.CurrentThread.Name);
                            Thread processingThread = new Thread(() => OrderProcessing.orderProcess(orderObject, roomPrice2)); // creates the order processing threads
                            processingThread.Start();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(" Error in hotel supplier " + e.Message);
                }
            }
        }