当前位置: 首页>>代码示例>>C#>>正文


C# Task.ToString方法代码示例

本文整理汇总了C#中ToDoLib.Task.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Task.ToString方法的具体用法?C# Task.ToString怎么用?C# Task.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ToDoLib.Task的用法示例。


在下文中一共展示了Task.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: 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

示例3: Update

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

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

                _tasks[currentIndex] = newTask;

                File.WriteAllLines(_filePath, _tasks.Select(t => t.ToString()));

                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:slideep,项目名称:todotxt.net,代码行数:29,代码来源:TaskList.cs

示例4: TaskListKeyUp


//.........这里部分代码省略.........
					User.Default.Save();
					break;

				case Key.NumPad2:
				case Key.D2:
					User.Default.FilterText = User.Default.FilterTextPreset2;
					UpdateDisplayedTasks();
					User.Default.Save();
					break;

				case Key.NumPad3:
				case Key.D3:
					User.Default.FilterText = User.Default.FilterTextPreset3;
					UpdateDisplayedTasks();
					User.Default.Save();
					break;

				case Key.OemPeriod:
					Reload();
					UpdateDisplayedTasks();
					break;
				case Key.X:
					ToggleComplete((Task)_window.lbTasks.SelectedItem);
					UpdateDisplayedTasks();
					break;
				case Key.D:
					if (modifierKeys != ModifierKeys.Windows)
					{
						var res = MessageBox.Show("Permanently delete the selected task?",
									 "Confirm Delete",
									 MessageBoxButton.YesNo,
									 MessageBoxImage.Warning);

						if (res == MessageBoxResult.Yes)
						{
							try
							{
								_taskList.Delete((Task)_window.lbTasks.SelectedItem);
							}
							catch (Exception ex)
							{
								ex.Handle("Error deleting task");
							}

							UpdateDisplayedTasks();
						}
					}
					break;
				case Key.U:
					_updating = (Task)_window.lbTasks.SelectedItem;
					_window.taskText.Text = _updating.ToString();
					_window.taskText.Focus();
					break;
				case Key.P:
					_updating = (Task)_window.lbTasks.SelectedItem;

					int iPostponeCount = ShowPostponeDialog();
					if (iPostponeCount <= 0)
					{
						// User canceled, or entered a non-positive number or garbage
						break;
					}

					// Get the current DueDate from the item being updated
					DateTime dtNewDueDate;
					string postponedString;
					if (_updating.DueDate.Length > 0)
					{
						dtNewDueDate = Convert.ToDateTime(_updating.DueDate);
					}
					else
					{
						// Current item doesn't have a due date.  Use today as the due date
						dtNewDueDate = Convert.ToDateTime(DateTime.Now.ToString());
					}

					// Add days to that date
					dtNewDueDate = dtNewDueDate.AddDays(iPostponeCount);

					// Build a dummy string which we'll display so the rest of the system thinks we edited the current item.  
					// Otherwise we end up with 2 items which differ only by due date
					if (_updating.DueDate.Length > 0)
					{
						// The item has a due date, so exchange the current with the new
						postponedString = _updating.Raw.Replace(_updating.DueDate, dtNewDueDate.ToString("yyyy-MM-dd"));
					}
					else
					{
						// The item doesn't have a due date, so just append the new due date to the task
						postponedString = _updating.Raw.ToString() + " due:" + dtNewDueDate.ToString("yyyy-MM-dd");
					}

					// Display our "dummy" string.  If they cancel, no changes are committed.  
					_window.taskText.Text = postponedString;
					_window.taskText.Focus();
					break;
				default:
					break;
			}
		}
开发者ID:sy-vv,项目名称:todotxt.net,代码行数:101,代码来源:MainWindowViewModel.cs

示例5: KeyboardShortcut


//.........这里部分代码省略.........
					return;
				case Key.O:
					File_Open(null, null);
					return;
			}

			if (_taskList == null)
				return;

			if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
			{
				return;
			}

			switch (key)
			{
				case Key.N:
					// create one-line string of all filter but not ones beginning with a minus, and use as the starting text for a new task
					string filters = "";
					foreach (var filter in User.Default.FilterText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
					{
						if (filter.Substring(0, 1) != "-")
						{
                            if (filter.Contains("active"))
                            {
                                // If the current filter is "active", replace it here with "today"
                                filters = filters + " " + "due:today";
                            }
                            else
                            {
                                filters = filters + " " + filter;
                            }
						}
					}
					taskText.Text = filters;
					taskText.Focus();
					break;
				case Key.OemQuestion:
					Help(null, null);
					break;
				case Key.F:
					Filter(null, null);
					break;

                case Key.RightShift:
                    // Add Calendar to the titlebar
                    AddCalendarToTitle();
                    break;
                
                // Filter Presets
                case Key.NumPad1:
                case Key.D1:
                    User.Default.FilterText = User.Default.FilterTextPreset1;
                    FilterAndSort(_currentSort);
                    User.Default.Save();
                    break;

                case Key.NumPad2:
                case Key.D2:
                    User.Default.FilterText = User.Default.FilterTextPreset2;
                    FilterAndSort(_currentSort);
                    User.Default.Save();
                    break;

                case Key.NumPad3:
                case Key.D3:
                    User.Default.FilterText = User.Default.FilterTextPreset3;
                    FilterAndSort(_currentSort);
                    User.Default.Save();
                    break;
                
                case Key.OemPeriod:
					Reload();
					FilterAndSort(_currentSort);
					break;
				case Key.X:
					ToggleComplete((Task)lbTasks.SelectedItem);
					FilterAndSort(_currentSort);
					break;
				case Key.D:
					var res = MessageBox.Show("Permanently delete the selected task?",
								 "Confirm Delete",
								 MessageBoxButton.YesNo,
								 MessageBoxImage.Warning);

					if (res == MessageBoxResult.Yes)
					{
						Try(() => _taskList.Delete((Task)lbTasks.SelectedItem), "Error deleting task");
						FilterAndSort(_currentSort);
					}
					break;
				case Key.U:
					_updating = (Task)lbTasks.SelectedItem;
					taskText.Text = _updating.ToString();
					taskText.Focus();
					break;
				default:
					break;
			}
		}
开发者ID:alesprimozic,项目名称:todotxt.net,代码行数:101,代码来源:MainWindow.xaml.cs

示例6: 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

示例7: ToString_From_Raw

 public void ToString_From_Raw()
 {
     var task = new Task("(A) @work +test This is a test task");
     Assert.AreEqual("(A) @work +test This is a test task", task.ToString());
 }
开发者ID:steppsr,项目名称:todotxt.net,代码行数:5,代码来源:TaskTests.cs

示例8: ToString_From_Parameters

 public void ToString_From_Parameters()
 {
     var task = new Task("(A)", _projects, _contexts, "This is a test task");
     Assert.AreEqual("(A) This is a test task +test @work", task.ToString());
 }
开发者ID:steppsr,项目名称:todotxt.net,代码行数:5,代码来源:TaskTests.cs

示例9: KeyboardShortcut


//.........这里部分代码省略.........
                            }
						}
					}
					taskText.Text = filters;
					taskText.Focus();
					break;
				case Key.OemQuestion:
					Help(null, null);
					break;
				case Key.F:
					Filter(null, null);
					break;

                case Key.RightShift:
                    // Add Calendar to the titlebar
                    AddCalendarToTitle();
                    break;
                
                // Filter Presets
                case Key.NumPad0:
                case Key.D0:
                    User.Default.FilterText = "";
                    FilterAndSort(_currentSort);
					User.Default.Save();
                    break;

                case Key.NumPad1:
                case Key.D1:
                    User.Default.FilterText = User.Default.FilterTextPreset1;
                    FilterAndSort(_currentSort);
                    User.Default.Save();
                    break;

                case Key.NumPad2:
                case Key.D2:
                    User.Default.FilterText = User.Default.FilterTextPreset2;
                    FilterAndSort(_currentSort);
                    User.Default.Save();
                    break;

                case Key.NumPad3:
                case Key.D3:
                    User.Default.FilterText = User.Default.FilterTextPreset3;
                    FilterAndSort(_currentSort);
                    User.Default.Save();
                    break;
                
                case Key.OemPeriod:
					Reload();
					FilterAndSort(_currentSort);
					break;
				case Key.X:
					ToggleComplete((Task)lbTasks.SelectedItem);
					FilterAndSort(_currentSort);
					break;
				case Key.D:
					var res = MessageBox.Show("Permanently delete the selected task?",
								 "Confirm Delete",
								 MessageBoxButton.YesNo,
								 MessageBoxImage.Warning);

					if (res == MessageBoxResult.Yes)
					{
						Try(() => _taskList.Delete((Task)lbTasks.SelectedItem), "Error deleting task");
						FilterAndSort(_currentSort);
					}
					break;
				case Key.U:
					_updating = (Task)lbTasks.SelectedItem;
					taskText.Text = _updating.ToString();
					taskText.Focus();
					break;
                case Key.P:
                    _updating = (Task)lbTasks.SelectedItem;

                    int iPostponeCount = Postpone(null, null);
                    if (iPostponeCount <= 0)
                    {
                        // User canceled, or entered a non-positive number or garbage
                        break;
                    }
                    
                    // Get the current DueDate from the item being updated
                    DateTime dtNewDueDate = Convert.ToDateTime(_updating.DueDate);

                    // Add days to that date
                    dtNewDueDate = dtNewDueDate.AddDays(iPostponeCount);

                    // Build a dummy string which we'll display so the rest of the system thinks we edited the current item.  
                    // Otherwise we end up with 2 items which differ only by due date
                    string postponedString = _updating.Raw.Replace(_updating.DueDate, dtNewDueDate.ToString("yyyy-MM-dd"));

                    // Display our "dummy" string.  If they cancel, no changes are committed.  
                    taskText.Text = postponedString;
                    taskText.Focus();
                    break;
				default:
					break;
			}
		}
开发者ID:Arphahat,项目名称:todotxt.net,代码行数:101,代码来源:MainWindow.xaml.cs

示例10: KeyboardShortcut

        private void KeyboardShortcut(Key key)
        {
            switch (key)
            {
                case Key.C:
                    File_New(null, null);
                    break;
                case Key.O:
                    File_Open(null, null);
                    break;
                case Key.N:
                    taskText.Text = User.Default.FilterText;
                    taskText.Focus();
                    break;
                case Key.OemQuestion:
                    Help(null, null);
                    break;
                case Key.F:
                    Filter(null, null);
                    break;
                case Key.OemPeriod:
                    _taskList.ReloadTasks();
                    FilterAndSort(_currentSort);
                    break;
                case Key.X:
                    ToggleComplete((Task)lbTasks.SelectedItem);
                    FilterAndSort(_currentSort);
                    break;
                case Key.D:
                    var res = MessageBox.Show("Permanently delete the selected task?",
                                 "Confirm Delete",
                                 MessageBoxButton.YesNo);

                    if (res == MessageBoxResult.Yes)
                    {
                        _taskList.Delete((Task)lbTasks.SelectedItem);
                        FilterAndSort(_currentSort);
                    }
                    break;
                case Key.U:
                    _updating = (Task)lbTasks.SelectedItem;
                    taskText.Text = _updating.ToString();
                    taskText.Focus();
                    break;
                default:
                    break;
            }
        }
开发者ID:pierskarsenbarg,项目名称:todotxt.net,代码行数:48,代码来源:MainWindow.xaml.cs

示例11: SetTaskPriority

        private Task SetTaskPriority(Task task, dynamic newPriority)
        {
            Regex rgx = new Regex(@"^\((?<priority>[A-Z])\)\s"); // matches priority strings such as "(A) " (including trailing space)

            string oldTaskRawText = task.ToString();
            string oldPriorityRaw = rgx.Match(oldTaskRawText).ToString(); // Priority letter plus parentheses and trailing space
            string oldPriority = rgx.Match(oldTaskRawText).Groups["priority"].Value.Trim(); // Priority letter 

            string newPriorityRaw = "(" + newPriority + ") ";
            string newTaskRawText = (String.IsNullOrEmpty(oldPriority)) ?
                newPriorityRaw + oldTaskRawText :            // prepend new priority
                rgx.Replace(oldTaskRawText, newPriorityRaw); // replace old priority (regex) with new priority (formatted)

            return new Task(newTaskRawText);
        }
开发者ID:aviera,项目名称:todotxt.net,代码行数:15,代码来源:MainWindowViewModel.cs

示例12: Delete

        public void Delete(Task task)
        {
            try
            {
                Log.Debug("Deleting task '{0}'", task.ToString());

                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()));
                
                Log.Debug("Task '{0}' deleted", task.ToString());

                ReloadTasks();
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to remove your task from 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,代码行数:27,代码来源:TaskList.cs

示例13: SetTaskCompletion

 private Task SetTaskCompletion(Task task, dynamic parameter = null)
 {
     task.Completed = !task.Completed;
     var newTask = new Task(task.ToString());
     return newTask;
 }
开发者ID:aviera,项目名称:todotxt.net,代码行数:6,代码来源:MainWindowViewModel.cs

示例14: UpdateTask

 public void UpdateTask()
 {
     // Abort if no task, or more than one task, is selected.
     if (!IsTaskSelected())
     {
         return;
     }
     _updating = (Task)_window.lbTasks.SelectedItem;
     _window.taskText.Text = _updating.ToString();
     _window.taskText.Select(_window.taskText.Text.Length, 0); // puts cursor at the end
     _window.taskText.Focus();
 }
开发者ID:aviera,项目名称:todotxt.net,代码行数:12,代码来源:MainWindowViewModel.cs

示例15: Update

        /// <summary>
        /// This method updates one task in the file. It works by replacing the "current task" with the "new task".
        /// </summary>
        /// <param name="currentTask">The task to replace.</param>
        /// <param name="newTask">The replacement task.</param>
        /// <param name="reloadTasksPriorToUpdate">Optionally reload task file prior to the update. Default is TRUE.</param>
        /// <param name="writeTasks">Optionally write task file after the update. Default is TRUE.</param>
        /// <param name="reloadTasksAfterUpdate">Optionally reload task file after the update. Default is TRUE.</param>
        public void Update(Task currentTask, Task newTask, bool writeTasks = true)
		{
            Log.Debug("Updating task '{0}' to '{1}'", currentTask.ToString(), newTask.ToString());

			try
			{

				// 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;

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

                if (writeTasks)
                {
                    WriteAllTasksToFile();
                }
			}
			catch (IOException ex)
			{
				var msg = "An error occurred while trying to update your task in the task list file.";
				Log.Error(msg, ex);
				throw new TaskException(msg, ex);
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
				throw;
			}
            finally
            {
                UpdateTaskListMetaData();
            }
		}
开发者ID:aviera,项目名称:todotxt.net,代码行数:47,代码来源:TaskList.cs


注:本文中的ToDoLib.Task.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。