/// <summary> /// Will be executed on any meal change event but in fact is looking for when /// the customer is done /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnCurrentCustomerMealChanged(object sender, MealChangeEventArg e) { if ((sender == null && e == null) || e.NewMeal == Meal.Done) { Customer customer = RestaurantQueue.Remove(); // If there's no other customer in the queue if (customer == null) { Console.WriteLine("\nEveryone is full."); return; } // If this isn't the first customer, previous customer // which is done should stop listening to TableOpen event if (sender != null) { Customer prevCustomer = sender as Customer; RestaurantTable.TableOpenEvent -= prevCustomer.OnTableOpenHappened; Console.WriteLine(); } RestaurantTable.TableOpenEvent += customer.OnTableOpenHappened; RestaurantTable.Clean(); } else { if (e == null) { return; } Customer customer = e.theCustomer; Console.WriteLine($"{customer.FirstName} {customer.LastName}" + $" is having {e.NewMeal}"); } }
private void AnnounceMealChange(Meal oldMeal, Meal newMeal) { MealChangeEventArg arg = new MealChangeEventArg(this, oldMeal, newMeal); MealChangeEvent?.Invoke(this, arg); }