Пример #1
0
 public void Save(ToDoTasks toDoList, string taskStatus = "open")
 {
     StreamWriter sw = new StreamWriter(this.path, false);
     IncludeHeadHtml(sw, "To Do Tasks!");
     IncludeBodyHtml(toDoList, sw, taskStatus);
     sw.Close();
 }
Пример #2
0
 public void AddOneTask()
 {
     List<Task> emptyList = new List<Task>();
     ToDoTasks test = new ToDoTasks(emptyList);
     string newLine = "new line";
     test.AddTask(newLine);
     newLine.ShouldEqual(test.GetTask(0).Name);
 }
Пример #3
0
 public void ChangeTaskStatus()
 {
     List<Task> emptyList = new List<Task>();
     ToDoTasks test = new ToDoTasks(emptyList);
     string newLine = "new line";
     test.AddTask(newLine);
     test.ChangeTaskStatus(0, false);
     false.ShouldEqual(test.GetTask(0).IsOpen);
 }
Пример #4
0
 public void Save(ToDoTasks toDoList)
 {
     StreamWriter sw = new StreamWriter(this.path, false);
     foreach (Task task in toDoList)
     {
         sw.WriteLine(task.IsOpen + "," + task.Name.Replace('\n', '#'));
     }
     sw.Close();
 }
Пример #5
0
        private static void IncludeBodyHtml(ToDoTasks toDoList, StreamWriter sw, string taskStatus)
        {
            sw.WriteLine("<body>");
            sw.WriteLine("<table>");
            int i = 0;
            switch (taskStatus)
            {
                case "done":
                    sw.WriteLine("Here are your finished tasks:");
                    sw.WriteLine("<tr><td>ID</td><td>Description</td></tr>");
                    foreach (Task task in toDoList)
                    {
                        i++;
                        if (!task.IsOpen)
                        {
                            sw.WriteLine("<tr>");
                            sw.WriteLine("<td>{0}</td>", i);
                            sw.WriteLine("<td>{0}</td>", task.Name);
                            sw.WriteLine("</tr>");
                        }
                    }
                    break;

                case "all":
                    sw.WriteLine("Here are all your tasks:");
                    sw.WriteLine("<tr><td>ID</td><td>Is Open</td><td>Description</td></tr>");
                    foreach (Task task in toDoList)
                    {
                        i++;
                        sw.WriteLine("<tr>");
                        sw.WriteLine("<td>{0}</td>", i);
                        sw.WriteLine("<td>{0}</td>", task.IsOpen);
                        sw.WriteLine("<td>{0}</td>", task.Name);
                        sw.WriteLine("</tr>");
                    }
                    break;

                default:
                    sw.WriteLine("Here are your opened tasks:");
                    sw.WriteLine("<tr><td>ID</td><td>Description</td></tr>");
                    foreach (Task task in toDoList)
                    {
                        i++;
                        if (task.IsOpen)
                        {
                            sw.WriteLine("<tr>");
                            sw.WriteLine("<td>{0}</td>", i);
                            sw.WriteLine("<td>{0}</td>", task.Name);
                            sw.WriteLine("</tr>");
                        }
                    }
                    break;
            }
            sw.WriteLine("</table>");
            sw.WriteLine("</body>");
            sw.WriteLine("</html>");
        }
Пример #6
0
 private static void GetDataFromMainDatabaseFile(out List<Task> appList, out ToDoTasks appTaskList)
 {
     string appPath = Path.GetFullPath("appPath");
     appPath = appPath.Substring(0, appPath.Length - 26);
     appPath += @"ToDoApp\bin\Debug\ToDoAppTasksList";
     TxtWorker appTxtWorker = new TxtWorker(appPath);
     appList = appTxtWorker.Load();
     appTaskList = new ToDoTasks(appList);
 }
Пример #7
0
 private static List<Task> GetListUsingSaveAndLoad(ToDoTasks appTaskList)
 {
     string path = Path.GetFullPath("ToDoAppListSaveLoadTest");
     TxtWorker testTxtWorker = new TxtWorker(path);
     path += ".txt";
     File.Delete(path);
     testTxtWorker.Save(appTaskList);
     List<Task> actualAppList = testTxtWorker.Load();
     return actualAppList;
 }
Пример #8
0
        public void IsEmptyMethod()
        {
            List<Task> emptyList = new List<Task>();
            ToDoTasks test = new ToDoTasks(emptyList);
            bool testIsEmpty = true;

            testIsEmpty.ShouldEqual(test.IsEmpty());

            string newLine = "new line";
            test.AddTask(newLine);
            testIsEmpty = false;
            testIsEmpty.ShouldEqual(test.IsEmpty());
        }
Пример #9
0
        static void Main(string[] args)
        {
            string path = Path.GetFullPath("ToDoAppTasksList");
            TxtWorker txtWorker = new TxtWorker(path);
            HtmlWorker htmlWorker = new HtmlWorker(path);
            List<Task> initialList = txtWorker.Load();
            ToDoTasks tasksList = new ToDoTasks(initialList);

            if (IsNotAValidArgument(args))
            {
                Console.WriteLine("Use /? argument for help");
                return;
            }

            switch (args[0])
            {
                case "/?":
                    Console.WriteLine("Please enter one of the following arguments:");
                    Console.WriteLine("/add \"...\"- To add a new task");
                    Console.WriteLine("/done taskID - To set a particular task as done");
                    Console.WriteLine("/list - To see the list with opened tasks");
                    Console.WriteLine("/list done - To see the list with finished tasks");
                    Console.WriteLine("/export - To export All Tasks in html");
                    Console.WriteLine("E.g. ToDoApp.exe add \"pay electricity\"");
                    break;

                case "/add":
                    if (args.Length >= 2)
                    {
                        tasksList.AddTask(args[1]);
                        txtWorker.Save(tasksList);
                        Console.WriteLine("Task added successfully.");
                    }
                    break;

                case "/list":
                    int index = 1;
                    if (args.Length == 1)
                    {
                        if (tasksList.IsEmpty())
                        {
                            Console.WriteLine("No Tasks for today.\nEnjoy your day!");
                            break;
                        }
                        Console.WriteLine("Here is the list with your opened tasks:");
                        foreach (Task task in tasksList)
                        {
                            if (task.IsOpen == true)
                                Console.WriteLine(index + ". " + task.Name);
                            index++;
                        }
                        break;
                    }
                    else
                        switch (args[1])
                        {
                            case "done":
                                Console.WriteLine("Here is the list with the finished tasks:");
                                foreach (Task task in tasksList)
                                {
                                    if (task.IsOpen == false)
                                        Console.WriteLine(index + ". " + task.Name);
                                    index++;
                                }
                                break;
                            default:
                                Console.WriteLine("/list - To see the list with opened tasks");
                                Console.WriteLine("/list done - To see the list with finished tasks");
                                break;
                        }
                    break;

                case "/done":
                    if (args.Length >= 2)
                    {
                        int i;
                        bool numberValid = Int32.TryParse(args[1], out i);
                        if (numberValid && (i <= initialList.Count) && (i > 0))
                        {
                            tasksList.ChangeTaskStatus(i - 1, false);
                            txtWorker.Save(tasksList);
                            Console.WriteLine("Task " + i + " is set to done!");
                        }
                        else
                        {
                            Console.WriteLine("Please write the valid number of the finished task.");
                            Console.WriteLine("E.g. /done 1");
                        }
                    }
                    break;

                case "/export":
                    if (args.Length >= 2)
                    {
                        switch (args[1])
                        {
                            case "done":
                                htmlWorker.Save(tasksList, "done");
                                Console.WriteLine("Finished Tasks exported successfully to html!");
                                break;
                            case "all":
                                htmlWorker.Save(tasksList, "all");
                                Console.WriteLine("All Tasks exported successfully to html!");
                                break;
                            default:
                                Console.WriteLine("/export - To export opened tasks to html");
                                Console.WriteLine("/export done - To export finished tasks to html");
                                Console.WriteLine("/export all - To export all tasks to html");
                                break;
                        }
                        break;
                    }
                    htmlWorker.Save(tasksList);
                    Console.WriteLine("To DO Tasks exported successfully to html!");
                    break;

                default:
                    break;
            }
        }