Esempio n. 1
0
        internal int Run()
        {
            m_consoleWriter.WriteLine("Prompt_PleaseWaitLoading");
            loadCategories();

            try
            {
                char key = AskQuestionsForASingleKeyStroke(new[] { "Prompt_IntroLine?OrQuit" }, new[] { '?' });
                if (key == '?')
                {
                    while (key != 'q')
                    {
                        JokeRequestBuilder jokeRequestBuilder = new JokeRequestBuilder();

                        key = AskQuestionsForASingleKeyStroke(new[] { "Prompt_CIsForCategories", "Prompt_RIsForRandomJokes", "Prompt_QIsToQuit" }, new[] { 'c', 'r', 'q' });

                        switch (key)
                        {
                        case 'c':
                            displayCategories();
                            break;

                        case 'r':
                            key = AskQuestionsForASingleKeyStroke(new[] { "Question_RandomName" }, new[] { 'y', 'n' });
                            switch (key)
                            {
                            case 'y':
                                GetNames();
                                break;

                            case 'n':
                                jokeRequestBuilder.FirstName = AskForAName(new[] { "Question_FirstName", "PRESS_ENTER" });
                                jokeRequestBuilder.LastName  = AskForAName(new[] { "Question_LastName", "PRESS_ENTER" });
                                break;
                            }

                            key = AskQuestionsForASingleKeyStroke(new[] { "Question_WantACategory" }, new[] { 'y', 'n' });
                            if (key == 'y')
                            {
                                jokeRequestBuilder.Category = AskForACategory(new[] { "Question_EnterACategory", "PRESS_ENTER" });
                            }

                            jokeRequestBuilder.JokeCount = AskQuestionsForANumber(new[] { "Question_HowManyJokes" });

                            DisplayJokes(GetRandomJokes(jokeRequestBuilder.ToJokeRequest()));
                            break;

                        case 'q':
                            break;
                        }
                    }
                }
            }
            catch (ApplicationException appex)
            {
                m_consoleWriter.WriteLine("ExpectedExceptionMessage");
                m_consoleWriter.WriteLine(appex.Message);
                return(1);
            }
            catch (Exception ex)
            {
                m_consoleWriter.WriteLine("GenericExceptionMessage");

                Exception e = ex;
                while (e != null)
                {
                    m_consoleWriter.WriteLine(e.Message);
                    m_consoleWriter.WriteLine(e.StackTrace);
                    e = e.InnerException;
                }
                return(2);
            }
            return(0);
        }