/*calulates the no of rooms based on the price difference and the need * calls the encoder to encode the order and places the order in the buffer*/ public void calcRooms(int i, float newPrice) { try { int need = rng.Next(0, 5); int maxRoomPriceDiff = 5000; float diff = currentPrice[i] - newPrice; currentPrice[i] = newPrice; float fraction = (diff + maxRoomPriceDiff) / (2 * maxRoomPriceDiff); int rooms = (Int32)Math.Round(fraction * need); if (rooms == 0) { return; } o1 = new Order(); int tempOrder = ++orderId; o1.setOrder(agencyId, cardNo, h[i].getHotelId(), rooms, tempOrder, newPrice); String buffer_str = EncoderDecoder.encode(o1); pendingReciept++;//increment the pending reciept with every order that is placed in buffer Buffer.setBuffer(buffer_str, agencyId, h[i].getHotelId(), tempOrder, newPrice); Thread.Sleep(rng.Next(400, 600)); return; } catch (Exception e) { Console.WriteLine(e.Message); } }
//decode the String object into Order object public static Order decode(String s) { if (s == null) { return(null); } else { String [] temp = s.Split(new char[] { '@' }); Order dec_obj = new Order(); dec_obj.setOrder(Convert.ToInt32(temp[0]), temp[1], Convert.ToInt32(temp[2]), Convert.ToInt32(temp[3]), Convert.ToInt32(temp[4]), float.Parse(temp[5])); return(dec_obj); } }
/*calulates the no of rooms based on the price difference and the need calls the encoder to encode the order and places the order in the buffer*/ public void calcRooms(int i, float newPrice) { try { int need = rng.Next(0, 5); int maxRoomPriceDiff = 5000; float diff = currentPrice[i] - newPrice; currentPrice[i] = newPrice; float fraction = (diff + maxRoomPriceDiff) / (2 * maxRoomPriceDiff); int rooms = (Int32)Math.Round(fraction * need); if (rooms == 0) return; o1 = new Order(); int tempOrder = ++orderId; o1.setOrder(agencyId, cardNo, h[i].getHotelId(), rooms, tempOrder, newPrice); String buffer_str = EncoderDecoder.encode(o1); pendingReciept++;//increment the pending reciept with every order that is placed in buffer Buffer.setBuffer(buffer_str, agencyId, h[i].getHotelId(), tempOrder, newPrice); Thread.Sleep(rng.Next(400, 600)); return; } catch (Exception e) { Console.WriteLine(e.Message); } }