Exemple #1
0
        public static void OrderProcessing(OrderObject order)
        {
            Console.WriteLine("\n\n\nValidating credit card number...");
            Console.WriteLine("*********************ORDER CONFIRMATION***********************");


            //TO-DO Call BankService to validate credit card

            string        c       = Convert.ToString(order.getCard()); // card encrypt
            ServiceClient convert = new ServiceClient();

            c = convert.Encrypt(c);

            //IF credit card is valid do the following
            if (Program.bs.validate(c))
            {
                //Calcuates total charge for room order
                double totalCharge = ((double)order.getAmount() * (double)salePrice * .1) + ((double)order.getAmount() * (double)salePrice);

                //Send confirmation back to travelAgency
                Console.WriteLine("{0} has successfully placed order with {1} for {2} rooms.", order.getSender(), order.getRec(), order.getAmount());
                Console.WriteLine("Price: {0} (${1} x {2})", ((double)order.getAmount() * (double)salePrice), (double)salePrice, (double)order.getAmount());
                Console.WriteLine("Tax: ${0}", ((double)order.getAmount() * (double)salePrice * .1));
                Console.WriteLine("Grand Total: ${0} \nCard Number: {1}", totalCharge, order.getCard());
                Console.WriteLine("*********************************************************\n\n\n");
            }
            else
            {
                //Send message back to travelAgency saying creditCard invalid
                Console.WriteLine("Error: Agency {0} could not place order with {1} due to invalid card number: {2}", order.getSender(), order.getRec(), order.getCard());
            }
        }
Exemple #2
0
        public static void addtoBuffer()
        {
            //TO-DO: Create Order Object, then send order object to encoder.
            //The encoder should return order object as a string.
            //Add the string to the buffer.

            //TO-DO: A time stamp must be saved before sending the order to the buffer.

            //Example of creating an orderObject, encoding it, and then sending it into the buffer
            Encoder encode = new Encoder();

            /************************************
             *
             * We still need to figure out how to put the correct information into the order object
             *
             *************************************/
            string[] agencies = new string[5] {
                "Expedia", "Hotwire", "Orbitz", "Priceline", "Travelocity"
            };
            Random rng          = new Random();
            Int32  agencyNumber = rng.Next(0, 5);

            OrderObject order        = new OrderObject(agencies[agencyNumber], Program.bs.create(), Thread.CurrentThread.Name, 5);
            string      encodedOrder = encode.encode(order);

            Console.WriteLine("\n{0} received an order from {1}.", Thread.CurrentThread.Name, agencies[agencyNumber]);
            Program.mb.setOneCell(encodedOrder);
        }
Exemple #3
0
        public static void readFromBuffer()
        {
            //Get a value from the buffer. Normally this will be an encoded OrderObject
            //In which case we would then pass the string to the decoder to turn it back into and OrderObject
            string encodedOrder = Program.mb.getOneCell();

            //TO-DO: Decode the string
            Decoder     decode = new Decoder();
            OrderObject order  = new OrderObject();

            order = decode.decode(encodedOrder);

            //TO-DO: Process the order

            Console.WriteLine(Thread.CurrentThread.Name + " PROCESSING ORDER");
            new Thread(delegate()
            {
                OrderProcessing(order);
            }).Start();
        }
Exemple #4
0
        public OrderObject decode(string encoded)
        {
            OrderObject passed = new OrderObject();

            char[]   delimiter = { ' ' };
            string[] code      = encoded.Split(delimiter);

            byte[] s = Convert.FromBase64String(code[0]);
            passed.setSender(Encoding.UTF8.GetString(s));

            byte[] c = Convert.FromBase64String(code[1]);
            passed.setCard(Convert.ToInt32(Encoding.UTF8.GetString(c)));

            byte[] r = Convert.FromBase64String(code[2]);
            passed.setReceiver(Encoding.UTF8.GetString(r));

            byte[] a = Convert.FromBase64String(code[3]);
            passed.setAmount(Convert.ToInt32(Encoding.UTF8.GetString(a)));

            return(passed);
        }
Exemple #5
0
        public string encode(OrderObject item)
        {
            passed = item;
            byte[] s      = Encoding.UTF8.GetBytes(passed.getSender());
            string result = Convert.ToBase64String(s);

            string cc = Convert.ToString(passed.getCard());

            byte[] c = Encoding.UTF8.GetBytes(cc);
            result += " " + Convert.ToBase64String(c);

            byte[] r = Encoding.UTF8.GetBytes(passed.getRec());
            result += " " + Convert.ToBase64String(r);

            string aa = Convert.ToString(passed.getAmount());

            byte[] a = Encoding.UTF8.GetBytes(aa);
            result += " " + Convert.ToBase64String(a);

            return(result);
        }