예제 #1
0
        public async Task Run(String[] args)
        {
            char key;

            (string first, string last)? names;
            string category;
            IAsyncEnumerable <string> jokes;

            try
            {
                while (true)
                {
                    names    = null;
                    category = null;
                    jokes    = null;

                    _printer.Print(UIPrompts.ToGetCategoriesList);
                    _printer.Print(UIPrompts.ToGetRandomJokes);
                    key = GetEnteredKey(Console.ReadKey());
                    if (key == 'c')
                    {
                        var categories = await _chuckNorrisService.GetCategoriesAsync();

                        _printer.Print(categories);
                    }
                    if (key == 'r')
                    {
                        names = await GetRandomNames();

                        category = await GetJokeCategory();

                        jokes = GetJokes(names: names, categoryOfJokes: category);

                        await foreach (var joke in jokes)
                        {
                            _printer.Print(joke);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
            }
            //}
        }