當前位置: 首頁>>代碼示例>>C#>>正文


C# ToDoLib.Task類代碼示例

本文整理匯總了C#中ToDoLib.Task的典型用法代碼示例。如果您正苦於以下問題:C# Task類的具體用法?C# Task怎麽用?C# Task使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Task類屬於ToDoLib命名空間,在下文中一共展示了Task類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Create_Priority_In_Body

        public void Create_Priority_In_Body()
        {
            var task = new Task("Oh (A) This is a test task @work +test ");

            var expectedTask = new Task("", _projects, _contexts, "Oh (A) This is a test task");
            AssertEquivalence(expectedTask, task);
        }
開發者ID:steppsr,項目名稱:todotxt.net,代碼行數:7,代碼來源:TaskTests.cs

示例2: Add

        public void Add(Task task)
        {
            try
            {
                var output = task.ToString();

                Log.Debug("Adding task '{0}'", output);

                var text = File.ReadAllText(_filePath);
                if (text.Length > 0 && !text.EndsWith(Environment.NewLine))
                    output = Environment.NewLine + output;

                File.AppendAllLines(_filePath, new string[] { output });

                Log.Debug("Task '{0}' added", output);

                ReloadTasks();
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to add your task to the task list file";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }

        }
開發者ID:slideep,項目名稱:todotxt.net,代碼行數:31,代碼來源:TaskList.cs

示例3: Create_Priority_Context_Project_Body

        public void Create_Priority_Context_Project_Body()
        {
            var task = new Task("(A) @work +test This is a test task");

            var expectedTask = new Task("(A)", _projects, _contexts, "This is a test task");
            AssertEquivalence(expectedTask, task);
        }
開發者ID:steppsr,項目名稱:todotxt.net,代碼行數:7,代碼來源:TaskTests.cs

示例4: Create_Trailing_Whitespace

        public void Create_Trailing_Whitespace()
        {
            var task = new Task("(A) This is a test task @work +test  ");

            var expectedTask = new Task("(A)", _projects, _contexts, "This is a test task");
            AssertEquivalence(expectedTask, task);
        }
開發者ID:steppsr,項目名稱:todotxt.net,代碼行數:7,代碼來源:TaskTests.cs

示例5: Create_UnCompleted

        public void Create_UnCompleted()
        {
            var task = new Task("(A) @work +test This is a test task");

            var expectedTask = new Task("(A)", _projects, _contexts, "This is a test task");
            AssertEquivalence(expectedTask, task);
        }
開發者ID:steppsr,項目名稱:todotxt.net,代碼行數:7,代碼來源:TaskTests.cs

示例6: Add_ToFile

        public void Add_ToFile()
        {
            var fileContents = File.ReadAllLines(Data.TestDataPath).ToList();
            fileContents.Add("(B) Add_ToFile +test @task");

            var task = new Task(fileContents.Last());
            var tl = new TaskList(Data.TestDataPath);
            tl.Add(task);

            var newFileContents = File.ReadAllLines(Data.TestDataPath);
            CollectionAssert.AreEquivalent(fileContents, newFileContents);
        }
開發者ID:robjefferies,項目名稱:todotxt.net,代碼行數:12,代碼來源:TaskListTests.cs

示例7: Add_Multiple

        public void Add_Multiple()
        {
            var tl = new TaskList(Data.TestDataPath);
            var c = tl.Tasks.Count();

            var task = new Task("Add_Multiple task one");
            tl.Add(task);

            var task2 = new Task("Add_Multiple task two");
            tl.Add(task2);

            Assert.AreEqual(c + 2, tl.Tasks.Count());
        }
開發者ID:robjefferies,項目名稱:todotxt.net,代碼行數:13,代碼來源:TaskListTests.cs

示例8: Delete

        public void Delete(Task task)
        {
            try
            {
                ReloadTasks(); // make sure we're working on the latest file
                if (_tasks.Remove(_tasks.First(t => t.Raw == task.Raw)))
                    File.WriteAllLines(_filePath, _tasks.Select(t => t.ToString()));

                ReloadTasks();
            }
            catch (IOException ex)
            {
                throw new TaskException("An error occurred while trying to remove your task from the task list file", ex);
            }
        }
開發者ID:pierskarsenbarg,項目名稱:todotxt.net,代碼行數:15,代碼來源:TaskList.cs

示例9: Add_ToCollection

        public void Add_ToCollection()
        {
            var task = new Task("(B) Add_ToCollection +test @task");

            var tl = new TaskList(Data.TestDataPath);

            var tasks = new List<Task>(tl.Tasks);
            tasks.Add(task);

            tl.Add(task);

            var newTasks = tl.Tasks.ToList();

            Assert.AreEqual(tasks.Count, newTasks.Count);

            for (int i = 0; i < tasks.Count; i++)
                Assert.AreEqual(tasks[i].ToString(), newTasks[i].ToString());
        }
開發者ID:robjefferies,項目名稱:todotxt.net,代碼行數:18,代碼來源:TaskListTests.cs

示例10: Update

        public void Update(Task currentTask, Task newTask)
        {
            try
            {
                ReloadTasks();
                var currentIndex = _tasks.IndexOf(_tasks.First(t => t.Raw == currentTask.Raw));

                _tasks[currentIndex] = newTask;

                File.WriteAllLines(_filePath, _tasks.Select(t => t.ToString()));
            }
            catch (IOException ex)
            {
                throw new TaskException("An error occurred while trying to update your task int the task list file", ex);
            }

            ReloadTasks();
        }
開發者ID:pierskarsenbarg,項目名稱:todotxt.net,代碼行數:18,代碼來源:TaskList.cs

示例11: GetConsoleColorForTask

        static ConsoleColor GetConsoleColorForTask(Task task)
        {
            switch (task.Priority)
            {
                case "(A)":
                    return ConsoleColor.Yellow;

                case "(B)":
                    return ConsoleColor.Green;

                case "(C)":
                    return ConsoleColor.Blue;

                case "(D)":
                    return ConsoleColor.Magenta;
            }

            return Console.ForegroundColor;
        }
開發者ID:zeevl,項目名稱:todo-exe,代碼行數:19,代碼來源:Program.cs

示例12: Add

        public void Add(Task task)
        {
            try
            {
                var output = task.ToString();

                var text = File.ReadAllText(_filePath);
                if (text.Length > 0 && !text.EndsWith(Environment.NewLine))
                    output = Environment.NewLine + output;

                File.AppendAllLines(_filePath, new string[] { output });

                ReloadTasks();
            }
            catch (IOException ex)
            {
                throw new TaskException("An error occurred while trying to add your task to the task list file", ex);
            }

        }
開發者ID:pierskarsenbarg,項目名稱:todotxt.net,代碼行數:20,代碼來源:TaskList.cs

示例13: ReloadTasks

        public void ReloadTasks()
        {
            try
            {
                _tasks = new List<Task>();

                var i = 0;
                var file = File.OpenRead(_filePath);
                using (var reader = new StreamReader(file))
                {
                    string raw;
                    while ((raw = reader.ReadLine()) != null)
                    {
                        if (raw.Trim() == "")
                            continue;

                        var task = new Task(i++, raw);

                        Projects.AddRange(task.Projects.Where(s => !Projects.Contains(s)));
                        Contexts.AddRange(task.Contexts.Where(s => !Contexts.Contains(s)));

                        _tasks.Add(task);
                    }
                }

            }
            catch (IOException ex)
            {
                var msg = "There was a problem trying to read from your todo.txt file";
                throw new TaskException(msg, ex);
            }
        }
開發者ID:zeevl,項目名稱:todo-exe,代碼行數:32,代碼來源:TaskList.cs

示例14: Update

		public void Update(Task currentTask, Task newTask)
		{
			try
			{
				Log.Debug("Updating task '{0}' to '{1}'", currentTask.ToString(), newTask.ToString());

				ReloadTasks();

				// ensure that the task list still contains the current task...
				if (!Tasks.Any(t => t.Raw == currentTask.Raw))
					throw new Exception("That task no longer exists in to todo.txt file");

				var currentIndex = Tasks.IndexOf(Tasks.First(t => t.Raw == currentTask.Raw));

				Tasks[currentIndex] = newTask;

				WriteAllTasksToFile();

				Log.Debug("Task '{0}' updated", currentTask.ToString());

				ReloadTasks();
			}
			catch (IOException ex)
			{
				var msg = "An error occurred while trying to update your task int the task list file";
				Log.Error(msg, ex);
				throw new TaskException(msg, ex);
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
				throw;
			}
		}
開發者ID:jerz4lunch,項目名稱:todotxt.net,代碼行數:34,代碼來源:TaskList.cs

示例15: Delete_InCollection

        public void Delete_InCollection()
        {
            var task = new Task("(B) Delete_InCollection +test @task");
            var tl = new TaskList(Data.TestDataPath);
            tl.Add(task);

            var tasks = new List<Task>(tl.Tasks);
            tasks.Remove(tasks.Where(x => x.Raw == task.Raw).First());

            
            tl.Delete(task);

            var newTasks = tl.Tasks.ToList();

            Assert.AreEqual(tasks.Count, newTasks.Count);

            for (int i = 0; i < tasks.Count; i++)
                Assert.AreEqual(tasks[i].ToString(), newTasks[i].ToString());
        }
開發者ID:robjefferies,項目名稱:todotxt.net,代碼行數:19,代碼來源:TaskListTests.cs


注:本文中的ToDoLib.Task類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。