public static OrderClass getDecodedValue(string encodedString) { string mergedString = encodedString;//Decrypt(encodedString, "ABCDEFGHIJKLMNOP"); string[] tokens = mergedString.Split('#'); OrderClass OrderClass = new OrderClass(); if (tokens.Length != 5) // String is not communicated properly { Console.WriteLine("Parameter missmatch"); OrderClass.setCreditCardNumber("-1"); OrderClass.setRoomPrice(-1); OrderClass.setNumberOfRooms(-1); OrderClass.setSenderID(-1); OrderClass.setReceiverID(-1); } else { OrderClass.setCreditCardNumber(tokens[0]); OrderClass.setRoomPrice(Int32.Parse(tokens[1])); OrderClass.setNumberOfRooms(Int32.Parse(tokens[2])); OrderClass.setSenderID(Int32.Parse(tokens[3])); OrderClass.setReceiverID(Int32.Parse(tokens[4])); } return OrderClass; }
/* * Generate and place orders from TravelAgency Randomly */ public void agency() { for (int i = 0; i < 2; i++) { Random random = new Random(); int r = random.Next(0, 2); OrderClass order = new OrderClass(); order.setCreditCardNumber(TransactionAgency.validCreditCard[random.Next(0, 2)]); order.setRoomPrice(price[r]); order.setNumberOfRooms(random.Next(1, 5)); order.setSenderID(tID); order.setReceiverID(r); string value = EncoderDecoder.getEncodedValue(order); lock (this) { Monitor.Enter(MainSystem.mcb); try { value = value +"?"+ DateTime.Now.Ticks; //append timestamp to order object MainSystem.mcb.setOneCell(value); Console.WriteLine("\n-----------------------------------------------------------------------"); Console.WriteLine("TravelAgency {0}=>\nOrder Details: \n\tRoomPrice:{1} \n\tNumberOfRooms:{2}", order.getSenderID(), order.getRoomPrice(), order.getNumberOfRooms()); Console.WriteLine("Order is initiated successfully for Hotel: " + order.getReceiverID()); Console.WriteLine("-----------------------------------------------------------------------"); MainSystem.placed++; } finally { Monitor.Exit(MainSystem.mcb); } } Thread.Sleep(600); } }