public void StartTheApplication()
		{
			this.console = new FakeConsole();
			var taskList = new TaskList(console);
			this.applicationThread = new System.Threading.Thread(() => taskList.Run());
			applicationThread.Start();
		}
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("*** Welcome to Task List ***\r\n");

            // Create the tasklist by loading in the previously saved tasks, if they exist
            theGlobalTaskList = new TaskList(@".\Tasks.txt");
            theGlobalTaskList.Load();

            // Create a loop that will run the menu until the user breaks out by typing "Q"
            while (true)
            {
                // Clear the screen
                Console.Clear();

                // Call the local method which prints the task list on the screen
                ListTasks();

                // Display the menu to the user
                Console.WriteLine();
                Console.WriteLine("What do you want to do?");
                Console.WriteLine("(A)dd a task");
                Console.WriteLine("(C)omplete a task");
                Console.WriteLine("(D)elete a task");
                Console.WriteLine("(Q)uit");

                // Wait for input from the user
                string input = Console.ReadLine().Trim().ToUpper();

                // If they typed nothing, simply go back to the top of this while and re-display everything.
                if (input.Length == 0)
                {
                    continue;
                }

                // If the user typed "q", break out of the while loop (exit the program)
                if (input.Substring(0, 1) == "Q")
                {
                    break;
                }

                // The following switch statement handles the rest of the possible selections from the user. If
                // the user's selection is not handled below, control will fall to the end of the switch. And the
                // while loop will start again.
                Task task;
                switch (input.Substring(0, 1))
                {
                // Add a task
                case "A":
                    task = GetTaskInfo();
                    theGlobalTaskList.AddTask(task);
                    break;

                // Complete a task
                case "C":
                    task          = SelectATask();
                    task.Complete = true;
                    theGlobalTaskList.Save();
                    break;

                // Delete a task
                case "D":
                    task = SelectATask();
                    theGlobalTaskList.RemoveTask(task);
                    break;
                }
            }
        }