コード例 #1
0
ファイル: Server.cs プロジェクト: hfortegcmlp/DevQuiz
        /// <summary>
        /// Fetches the dishes to be prepared
        /// </summary>
        /// <param name="timeOfDay"></param>
        /// <param name="timeSlots">Array of numbers</param>
        /// <returns></returns>
        private string GetDishes(Enumerations.TimeOfDay timeOfDay, string[] timeSlots)
        {
            //Extracted as interface to provide the capabiltiy to use IOC to inject the MealProcessorStaticData
            _mealProcessor.Initialize(timeOfDay);

            //TODO: start at index 0
            for (var i = 1; i < timeSlots.Length; i++)
            {
                if (!_mealProcessor.AddDishType(timeSlots[i]))
                {
                    break;
                }
            }
            return _mealProcessor.GetMeals();
        }
コード例 #2
0
 /// <summary>
 /// resets the processor and makes it ready for a new batch of dishes
 /// </summary>
 /// <param name="timeOfDay"></param>
 public void Initialize(Enumerations.TimeOfDay timeOfDay)
 {
     _encounteredError = false;
     _timeOfDay = timeOfDay;
     _meals = GetMealsByPeriod(timeOfDay);
 }
コード例 #3
0
 /// <summary>
 /// Fetches the allowed meals for a given meal period
 /// This function is the only one that contains data which could easily be extracted out to a datastore
 /// 
 /// </summary>
 /// <param name="timeOfDay"></param>
 /// <returns></returns>
 private Dictionary<Enumerations.DishType, MealWithCount> GetMealsByPeriod(Enumerations.TimeOfDay timeOfDay)
 {
     var meals = new Dictionary<Enumerations.DishType, MealWithCount>();
     if (timeOfDay == Enumerations.TimeOfDay.Morning)
     {
         meals.Add(Enumerations.DishType.Entree, new MealWithCount { DishType = Enumerations.DishType.Entree, Name = "eggs" });
         meals.Add(Enumerations.DishType.Side, new MealWithCount { DishType = Enumerations.DishType.Side, Name = "toast" });
         meals.Add(Enumerations.DishType.Drink, new MealWithCount { DishType = Enumerations.DishType.Drink, Name = "coffee", AllowMultiples = true });
     } else
     {
         meals.Add(Enumerations.DishType.Entree, new MealWithCount { DishType = Enumerations.DishType.Entree, Name = "steak" });
         meals.Add(Enumerations.DishType.Side, new MealWithCount { DishType = Enumerations.DishType.Side, Name = "potato", AllowMultiples = true });
         meals.Add(Enumerations.DishType.Drink, new MealWithCount { DishType = Enumerations.DishType.Drink, Name = "wine" });
         meals.Add(Enumerations.DishType.Dessert, new MealWithCount { DishType = Enumerations.DishType.Dessert, Name = "cake" });
     }
     return meals;
 }
コード例 #4
0
 /// <summary>
 /// returns true if dish exists in the meal period AND
 /// multiples are allowed or the current count is 0
 /// </summary>
 /// <param nameB="dish"></param>
 /// <returns></returns>
 private bool IsDishAllowed(Enumerations.DishType dish)
 {
     return _meals.ContainsKey(dish) && (
         _meals[dish].AllowMultiples ||
         _meals[dish].Count == 0);
 }