示例#1
0
        public void Run()
        {
            var pizzaCount      = _config.GetValue <int>("pizzaCount");
            var cookingInterval = _config.GetValue <int>("cookingInterval");

            _log.LogInformation($"Welcome to pizza factory, {pizzaCount} pizzas coming up!");

            for (var i = 1; i < pizzaCount + 1; i++)
            {
                var pizza = CreateRandomPizza();

                if (pizza.Cooked)
                {
                    _log.LogError($"Can't cook {pizza.GetDescription()} again");
                    return;
                }

                if (pizza.PizzaBase == null)
                {
                    _log.LogError("Can't cook pizza there was no base");
                    return;
                }

                if (pizza.PizzaTopping == null)
                {
                    _log.LogError("Can't cook pizza there was no topping");
                    return;
                }

                _log.LogInformation($"Cooking {pizza.GetDescription()} for {pizza.TotalCookingTime} seconds");

                _timer.Delay((int)pizza.TotalCookingTime);

                _log.LogInformation($"Your {pizza.GetDescription()} pizza is ready");

                pizza.Cooked = true;

                _timer.Delay(cookingInterval);

                _writer.Write($"{i}. {pizza.GetDescription()}");
            }

            _writer.Close();
            _log.LogInformation("Thank you for your order.");
        }