private ITask GetTaskFromToodleDo(ToodleDoTask source) { var task = this.Workbook.CreateTask(); task.Title = source.Title; task.Note = source.Note; task.Tags = source.Tags; task.Added = source.Added; task.Priority = source.EnumPriority; task.Due = source.Due; task.Start = source.Start; task.Completed = source.Completed; task.SyncId = source.Id; task.Modified = source.Modified; task.UseFixedDate = (source.RepeatFrom == 0); task.CustomFrequency = ToodleDoRecurrencyHelpers.Get2DayRecurrency(source.Repeat); if (!string.IsNullOrWhiteSpace(source.ParentId)) { var parent = this.Workbook.Tasks.FirstOrDefault(t => t.SyncId == source.ParentId); if (parent != null) { parent.AddChild(task); } } return(task); }
private static bool IsEquivalentTo(ToodleDoTask toodleDoTask, ITask task) { bool match = toodleDoTask.Title.Equals(task.Title, StringComparison.CurrentCultureIgnoreCase) && ( (toodleDoTask.Note == null && task.Note == null) || (toodleDoTask.Note != null && task.Note != null && toodleDoTask.Note.Equals(task.Note, StringComparison.CurrentCultureIgnoreCase)) ) && toodleDoTask.EnumPriority == task.Priority && toodleDoTask.Due == task.Due && toodleDoTask.Start == task.Start && toodleDoTask.Tags == task.Tags && toodleDoTask.Completed == task.Completed && toodleDoTask.FolderId == task.Folder.SyncId && ((task.Context == null && (toodleDoTask.ContextId == string.Empty || toodleDoTask.ContextId == "0")) || (task.Context != null && toodleDoTask.ContextId == task.Context.SyncId)) && toodleDoTask.RepeatFrom == (task.UseFixedDate ? 0 : 1) && ToodleDoRecurrencyHelpers.Get2DayRecurrency(toodleDoTask.Repeat).Equals(task.CustomFrequency); if (!match) { return(false); } if (toodleDoTask.ParentId == null && task.ParentId == null) { return(true); } if (toodleDoTask.ParentId != null && task.ParentId == null) { return(false); } if (toodleDoTask.ParentId == null && task.ParentId != null) { return(false); } // check parent if (toodleDoTask.ParentId != null && task.ParentId != null) { var parentTask = task.Folder.Tasks.FirstOrDefault(t => t.Id == task.ParentId); return(parentTask != null && toodleDoTask.ParentId == parentTask.SyncId); } return(true); }
public void UpdateTask(ITask target, IWorkbook workbook, Func <IFolder> createDefaultFolder) { target.Title = this.Title; target.Note = this.Note; target.Due = this.Due; target.Start = this.Start; target.Completed = this.Completed; target.Priority = this.EnumPriority; target.Tags = this.Tags; target.Modified = DateTime.Now; target.UseFixedDate = this.RepeatFrom == 0; target.CustomFrequency = ToodleDoRecurrencyHelpers.Get2DayRecurrency(this.Repeat); IFolder folder = workbook.Folders.FirstOrDefault(f => f.SyncId == this.FolderId); if (folder == null) { folder = createDefaultFolder(); } IContext context = workbook.Contexts.FirstOrDefault(c => c.SyncId == this.ContextId); target.Context = context; if (this.ParentId != null) { var parent = workbook.Tasks.FirstOrDefault(t => t.SyncId == this.ParentId); if (parent != null && !parent.Children.Contains(target)) { parent.AddChild(target); } } target.Folder = folder; }