public string Receive(string chickenQ, string eggQ, string customerName, string drinkingType, TableRequests tableRequests) { this.tableRequests = tableRequests; if (receiveIndex > 7) { throw new Exception("Up to 8 customers are allowed per table. Send to Cook first!"); } var chQ = Convert.ToInt32(chickenQ); var eQ = Convert.ToInt32(eggQ); Drink drinking = new Pepsi(); if (drinkingType == "Cola") { drinking = new Cola(); } if (drinkingType == "Tea") { drinking = new Tea(); } ServeDrinkings.Add(customerName.ToUpper() + " is served " + drinking.GetType().Name); for (int i = 0; i < chQ; i++) { tableRequests.Add <Chicken>(customerName); } for (int i = 0; i < eQ; i++) { tableRequests.Add <Egg>(customerName); } receiveIndex++; return("Request received from: " + customerName.ToUpper()); }
private void Initialize() { server = new Server(); FirstCook = new Cook(); SecondCook = new Cook(); tableRequests = new TableRequests(); }
private void Initialize() { server = new Server(); cook = new Cook(); tableRequests = new TableRequests(); server.Ready += (TableRequests tableRequests) => cook.Process(tableRequests); cook.Processed += server.Serve; }
private void Reset() { SetResult("Enjoy your food!"); customerName.Text = ""; tableRequests = new TableRequests(); status = Statuses.NotRecieved; server.receiveIndex = 0; server.ServeDrinkings.Clear(); }
private void OnRunProcess(TableRequests tableRequests) { semaphore.WaitOne(); State = CookState.Busy; OnProcess(tableRequests); Thread.Sleep(14000); State = CookState.Free; semaphore.Release(); }
private void OnProcess(TableRequests tableRequests) { var chickenOrders = tableRequests.Get <Chicken>(); Parallel.ForEach(chickenOrders, chicken => { ((Chicken)chicken).PrepareFood(); }); var eggOrders = tableRequests.Get <Egg>(); Parallel.ForEach(eggOrders, egg => { using (egg as Egg) (egg as Egg).PrepareFood(); }); }
public Task Process(TableRequests tableRequests) => Task.Run(() => OnRunProcess(tableRequests));