Esempio n. 1
0
 public UserPromptService(IConsolePrinterService consolePrinterService,
                          IConsoleKeyMapperService consoleKeyMapperService,
                          IJokesJsonFeedService jsonFeedService,
                          IPersonService personService,
                          IMemoryCache cache
                          )
 {
     printer    = consolePrinterService;
     keyMapper  = consoleKeyMapperService;
     jsonFeed   = jsonFeedService;
     personFeed = personService;
     _cache     = cache;
 }
Esempio n. 2
0
        private async Task GetRandomJokesByCount(IConsolePrinterService printer, bool randomPerson, string category)
        {
            printer.PrintMessage(Constants.JokesCountPrompt);
            char key = keyMapper.GetEnteredKey(Console.ReadKey());

            // check if the joke count is a valid integer
            if (Int32.TryParse(key.ToString(), out int n))
            {
                printer.PrintNewline();
                string[] results = await GetRandomJokesAsync(randomPerson?await GetRandomPersonAsync() : null, category, n);

                PrintResults(printer, results);
            }
            else
            {
                printer.PrintNewline();
                printer.PrintErrorMessage(Constants.ErrorInvalidJokeCount);
            }
        }
Esempio n. 3
0
 public void PrintCategoryResults(IConsolePrinterService printer, string[] results)
 {
     // display categories
     printer.PrettyPrintCategories(results);
 }
Esempio n. 4
0
 public void PrintResults(IConsolePrinterService printer, string[] results)
 {
     // display jokes
     printer.PrettyPrintResults(results);
 }