Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Notebook       notebook           = new Notebook(); //"see", "create", "remove"
            NotebookLogger notebookLogger     = new NotebookLogger(notebook);
            const string   ExitProgramKeyword = "exit";
            string         commandPrompt      = "Please enter " + notebook.show + ", " + notebook.delete + ", " + notebook._new + ", or " + notebook.log;

            Console.WriteLine(Notebook.IntroMessage);
            Console.WriteLine(commandPrompt);
            string input = "";

            do
            {
                input = Console.ReadLine();

                //breaks input up into tokens in an array
                string[] commands = input.Split();


                try {
                    /*get the first command...show, new, or delete
                     * and pass the second command to the functions
                     * still needs to be in the correct format*/
                    notebook[commands[0]]((commands.Length > 1) ? commands[1] : "");
                }
                //Stops the program is ExitProgramKeyword is entered
                catch (KeyNotFoundException)
                {
                    if (input != ExitProgramKeyword)
                    {
                        Console.WriteLine(commandPrompt);
                    }
                }
                Console.WriteLine();
            } while (input != ExitProgramKeyword);

            Console.WriteLine(Notebook.OuttroMessage);
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            //Notebook notebook = new Notebook("see", "create", "remove");
            var notebook       = new Notebook();
            var notebookLogger = new NotebookLogger(notebook);

            const string ExitProgramKeyword = "exit";
            var          commandPrompt      = "\nPlease enter " + notebook.show + ", "
                                              + notebook.delete + ", " + notebook._new
                                              + " or " + notebook.log + "\n";

            Console.WriteLine(Notebook.IntroMessage);
            Console.WriteLine(commandPrompt);

            var input = "";

            do
            {
                input = Console.ReadLine() ?? "";
                var commands = input.Split();

                try
                {
                    notebook[commands[0]](commands.Length > 1 ? commands[1] : "");
                }
                catch (KeyNotFoundException)
                {
                    if (input != ExitProgramKeyword)
                    {
                        Console.WriteLine(commandPrompt);
                    }
                }
                Console.WriteLine();
            } while (input != ExitProgramKeyword);

            Console.WriteLine(Notebook.OutroMessage);
        }