public TaskExpectation GetPendingExpectation(Task task) { var expectations = GetTaskExpectations(task); if(expectations.Count == 0) { return null; } foreach (var expectation in expectations) { if(HasExpectationBeenMet(expectation) || IsThereAMoreRecentExpectation(expectations, expectation)) { continue; } var hours = DateTime.Now.Subtract(expectation.ExpectedDateTime).TotalHours; if(hours >= -1) { return expectation; } } return null; }
public TaskExpectation GetDailyExpectation(Task task, DateTime dateTime) { if(!task.ShouldOccurOn(dateTime)) { return null; } return new TaskExpectation(task.Guid, dateTime.Date, task.TimeOfDay); }
public void AddTask(Task task) { if(null != FindTaskInRoutine(task)) { return; } Tasks.Add(task); }
public void CompleteTask(Task task) { var expectation = GetPendingExpectation(task); if(null == expectation) { throw new Exception("Task isn't pending"); } TaskAudits.Add(new TaskAudit(task.Guid, expectation, DateTime.Now)); }
public EditTaskForm(ManageTasksForm manageTasks, Task task, Routine routine) { Task = task; ManageTasks = manageTasks; Routine = routine; AlreadySaved = false; InitializeComponent(); taskNameTextbox.Text = task.Title; taskTimePicker.Value = DateTime.Now.Date.Add(task.TimeOfDay); repeatCheckbox.Checked = task.Repeat; sundayRepeat.Checked = task.RepeatSunday; mondayRepeat.Checked = task.RepeatMonday; tuesdayRepeat.Checked = task.RepeatTuesday; wednesdayRepeat.Checked = task.RepeatWednesday; thursdayRepeat.Checked = task.RepeatThursday; fridayRepeat.Checked = task.RepeatFriday; saturdayRepeat.Checked = task.RepeatSaturday; }
private void SaveTask() { var taskGuid = Task.Guid; var taskTitle = taskNameTextbox.Text.Trim() == "" ? "<untitled task>" : taskNameTextbox.Text; var taskTimeOfDay = taskTimePicker.Value.TimeOfDay; var task = new Task(taskTitle, DateTime.Now, taskTimeOfDay, repeatCheckbox.Checked, sundayRepeat.Checked, mondayRepeat.Checked, tuesdayRepeat.Checked, wednesdayRepeat.Checked, thursdayRepeat.Checked, fridayRepeat.Checked, saturdayRepeat.Checked); task.Guid = taskGuid; Routine.UpdateTask(taskGuid, task); }
public List<TaskExpectation> GetTaskExpectations(Task task, int days = 30) { var now = DateTime.Now; var expectations = new List<TaskExpectation>(); for(int x = 0; x < days; x++) { var dateTime = now.AddDays(-x); var expectation = GetDailyExpectation(task, dateTime); if(expectation == null) { continue; } expectations.Add(expectation); } return expectations; }
Task FindTaskInRoutine(Task task) { return FindTaskInRoutine(task.Guid); }
public void UpdateTask(Guid taskGuid, Task task) { for(int x = 0; x < Tasks.Count; x++) { if(Tasks[x].Guid != taskGuid) { continue; } Tasks[x] = task; break; } }
public void RemoveTask(Task task) { RemoveTask(task.Guid); }