public void ExecuteScenario(int scenarioId) { List <ActionsListBusiness> actionsList = actionsListService.GetByScenario(scenarioId); string[] nextAction = null; CustomersGroup customers = null; int tableNumber = 0; string actualScenarioAction = null; string[] actualScenarioActionParam = null; do { actualScenarioAction = GetNextScenarioAction(ref actionsList, ref nextAction); actualScenarioActionParam = GetNextScenarioActionParam(ref nextAction); Console.WriteLine(actualScenarioAction); switch (actualScenarioAction) { case "CreationReservation": customers = new CustomersGroup( CreateCustomersGroup(int.Parse(actualScenarioActionParam[1].Split('=')[1]), int.Parse(actualScenarioActionParam[2].Split('=')[1]), int.Parse(actualScenarioActionParam[3].Split('=')[1])), true); DateTime reservationDate = new DateTime(SimulationTimeOfServiceStart.Year, SimulationTimeOfServiceStart.Month, SimulationTimeOfServiceStart.Day, 18 /*int.Parse(actualScenarioActionParam[0].Split('h')[0])*/, 0, 0); lock (model.DiningRoom.Butler.lockObj) { tableNumber = model.DiningRoom.Butler.CreateBooking(customers, reservationDate); } break; case "ArriveeClientsReservation": model.DiningRoom.Reception.BookedCustomersArrive(customers); lock (model.DiningRoom.Butler.lockObj) { //tableNumber = model.DiningRoom.Butler.FindTable(customers); ThreadSyncByTableNumber.Add(tableNumber, new AutoResetEvent(false)); } break; case "ArriveeClientsNonReserve": customers = new CustomersGroup( CreateCustomersGroup(int.Parse(actualScenarioActionParam[0].Split('=')[1]), int.Parse(actualScenarioActionParam[1].Split('=')[1]), int.Parse(actualScenarioActionParam[2].Split('=')[1])), true); //model.DiningRoom.Reception.BookedCustomersArrive(customers); lock (model.DiningRoom.Butler.lockObj) { tableNumber = model.DiningRoom.Butler.FindTable(customers); ThreadSyncByTableNumber.Add(tableNumber, new AutoResetEvent(false)); } break; case "AmenerClientsATable": HeadWaiter headWaiter = null; do { headWaiter = model.DiningRoom.HeadWaiters.FirstOrDefault(x => x.IsBusy == false); } while (headWaiter == null); lock (headWaiter.lockObj) { headWaiter.PlaceCustomersAtTable(customers, tableNumber); } break; case "PrendreLesCommandes": headWaiter = null; do { headWaiter = model.DiningRoom.HeadWaiters.FirstOrDefault(x => x.IsBusy == false); } while (headWaiter == null); lock (headWaiter.lockObj) { headWaiter.TakeOrders(tableNumber); } break; case "PreparationDesCommandes": lock (model.Kitchen.HeadChef.lockObj) { model.Kitchen.HeadChef.StartCoursesOrderPreparation(model.DiningRoom.Tables.Find(x => x.TableNumber == tableNumber)); } break; case "AmenerPlatsEnSalle": ThreadSyncByTableNumber.First(x => x.Key == tableNumber).Value.WaitOne(); break; case "ClientsMangent": int i = 0; Thread[] eatingCustomersThreads = new Thread[model.DiningRoom.Tables.Find(x => x.TableNumber == tableNumber).ServedFood.Count]; foreach (Customer customer in model.DiningRoom.Tables.Find(x => x.TableNumber == tableNumber).SeatedCustomers) { if (i >= model.DiningRoom.Tables.Find(x => x.TableNumber == tableNumber).ServedFood.Count) { break; } int j = i; eatingCustomersThreads[i] = new Thread(delegate() { lock (customer.lockObj) { customer.EatFood(model.DiningRoom.Tables.Find(x => x.TableNumber == tableNumber).ServedFood[j]); } }); eatingCustomersThreads[i].Start(); i++; } for (int y = 0; y < eatingCustomersThreads.Length; y++) { if (eatingCustomersThreads[y] != null) { eatingCustomersThreads[y].Join(); } } break; case "DebarasserTable": Waiter waiter = null; //while (model.DiningRoom.Tables.Find(x => x.TableNumber == tableNumber).ServedFood.TrueForAll(x => x.IsFinished)) { } do { waiter = model.DiningRoom.Waiters.FirstOrDefault(x => x.IsBusy == false); } while (waiter == null); lock (waiter.lockObj) { waiter.ClearPlates(tableNumber); } break; case "ClientsPartent": waiter = null; do { waiter = model.DiningRoom.Waiters.FirstOrDefault(x => x.IsBusy == false); } while (waiter == null); lock (waiter.lockObj) { model.DiningRoom.Countertop.Orders.Remove(model.DiningRoom.Tables.Find(x => x.TableNumber == tableNumber)); model.DiningRoom.Tables.Find(x => x.TableNumber == tableNumber).SeatedCustomers.Clear(); model.DiningRoom.Tables.Find(x => x.TableNumber == tableNumber).NextCourseToServe = CourseType.Starter; model.DiningRoom.Waiters.Find(x => x.IsBusy == false).ClearAndCleanTable(tableNumber); } break; default: break; } } while (actualScenarioAction != "ClientsPartent"); }