public static void retalierFunc() { while (true) { Order orderObj = new Order(); orderObj.setSenderId(Thread.CurrentThread.Name); orderObj.setCardNum(rng.Next(4800, 6999)); rw.AcquireReaderLock(Timeout.Infinite); try{ if (flag) //flag value is based on event. So Retilers actions are based on pricecut event { orderObj.setNumOfChicken(rng.Next(50, 70)); } else { orderObj.setNumOfChicken(rng.Next(10, 20)); } } finally { rw.ReleaseReaderLock(); } orderObj.setStartTime(DateTime.Now.TimeOfDay); string encodedObject = Encoder.convertObjectToString(orderObj); MultiBufferCell.setOneCell(encodedObject); Console.WriteLine("{0} gave an order of {1} chickens", Thread.CurrentThread.Name, orderObj.getNumOfChicken()); Thread.Sleep(750); } }
public static Order convertStringToObject(String encodedOrder) { Order decodedOrderObj = new Order(); try { String[] orderVariables = encodedOrder.Split('#'); decodedOrderObj.setSenderId(orderVariables[0]); decodedOrderObj.setCardNum(int.Parse(orderVariables[1])); decodedOrderObj.setNumOfChicken(int.Parse(orderVariables[2])); decodedOrderObj.setStartTime (TimeSpan.Parse(orderVariables[3])); } catch(Exception e) { } return decodedOrderObj; }