public void sendOrder(Order ord) { Coder cod = new Coder(); MultiCellBuffer midcells = new MultiCellBuffer(); Thread setorder = new Thread(new ParameterizedThreadStart(midcells.setOneCell)); Console.WriteLine("Store{0} has sent one order", id); setorder.Start(cod.Encoder(ord)); //each order create a new thread }
public void chickenOnSale(Int32 p){ //will sendOrder Console.WriteLine("chickens are on sale: as low as ${0} each",p); Console.WriteLine("Store{0} wants buy {1} chickens", id, (10 - p) * 10); //(10-p)*p is amount Random rd = new Random(); int card = rd.Next(300,500); Order ord = new Order(id,card,(10-p)*10,p); //init order startTime= DateTime.Now; //track order sendOrder(ord); }
public string Encoder(Order order) { string str = Convert.ToString(order.getID()) + "_" + Convert.ToString(order.getCardNo()) + "_" + Convert.ToString(order.getAmt())+"_"+Convert.ToString(order.getPrice()); webEncrypt.ServiceClient proxy = new webEncrypt.ServiceClient();//make sure your internet is connected return proxy.Encrypt(str); // proxy.Close(); }
public Order Decoder(string orderstr) { Order ord = new Order(); webEncrypt.ServiceClient proxy = new webEncrypt.ServiceClient(); string str = proxy.Decrypt(orderstr); string[] arr = str.Split(new char[] { '_' }); //from string to order ord.setID(Convert.ToInt32(arr[0])); ord.setCardNo(Convert.ToInt32(arr[1])); ord.setAmt(Convert.ToInt32(arr[2])); ord.setPrice(Convert.ToInt32(arr[3])); return ord; }
public void Confirmation(Order ord) { endTime = DateTime.Now; //track end time if (Program.confirmed == false) { Console.WriteLine("Store{0} has bought {1} chickens sucessfully! spend{2} ", ord.getID(), ord.getAmt(), endTime - startTime); Program.confirmed = true; } }