/// <summary> /// 持久化本地需要增删改的任务 /// </summary> private void PersistLocalTaskDatas(TaskSyncResult taskSyncResult, Account account) { if (taskSyncResult.LocalDatasToCreate.Count() == 0 && taskSyncResult.LocalDatasToUpdate.Count() == 0 && taskSyncResult.LocalDatasToDelete.Count() == 0) { return; } //处理在本地需要新增的任务 foreach (var taskData in taskSyncResult.LocalDatasToCreate) { //TODO, 以后下面这三步需要放在一个Transaction中实现 //创建任务 CooperTask task = new CooperTask(account); task.SetSubject(taskData.Subject ?? string.Empty); task.SetBody(FormatTaskBody(taskData.Body)); task.SetDueTime(FormatTaskDueTime(taskData.DueTime)); if (taskData.IsCompleted) { task.MarkAsCompleted(); } else { task.MarkAsInCompleted(); } task.SetPriority(ConvertToPriority(taskData.Priority)); _taskService.Create(task); //任务创建后更新最后更新时间,更新为和这条任务关联的外部系统任务的最后更新时间 task.SetLastUpdateTime(taskData.LastUpdateLocalTime); _taskService.Update(task); //创建同步信息 if (taskData.IsFromDefault) { SyncInfo syncInfo = new SyncInfo(); syncInfo.AccountId = account.ID; syncInfo.LocalDataId = task.ID.ToString(); syncInfo.SyncDataId = taskData.SyncId; syncInfo.SyncDataType = taskData.SyncType; InsertSyncInfo(syncInfo); } } //处理在本地需要更新的任务 foreach (var taskData in taskSyncResult.LocalDatasToUpdate) { //更新任务 CooperTask task = _taskService.GetTask(long.Parse(taskData.Id)); task.SetSubject(taskData.Subject ?? string.Empty); task.SetBody(FormatTaskBody(taskData.Body)); task.SetDueTime(FormatTaskDueTime(taskData.DueTime)); if (taskData.IsCompleted) { task.MarkAsCompleted(); } else { task.MarkAsInCompleted(); } task.SetPriority(ConvertToPriority(taskData.Priority)); _taskService.Update(task); //任务更新后更新最后更新时间,更新为和这条任务关联的外部系统任务的最后更新时间 task.SetLastUpdateTime(taskData.LastUpdateLocalTime); _taskService.Update(task); } //暂时去掉删除本地数据的功能 ////处理在本地需要删除的任务 //foreach (var taskData in taskSyncResult.LocalDatasToDelete) //{ // Cooper.Model.Tasks.Task task = _taskService.GetTask(long.Parse(taskData.Id)); // _taskService.Delete(task); // //删除同步信息 // SyncInfo syncInfo = new SyncInfo(); // syncInfo.AccountId = account.ID; // syncInfo.LocalDataId = task.ID.ToString(); // syncInfo.SyncDataId = taskData.SyncId; // syncInfo.SyncDataType = taskData.SyncType; // DeleteSyncInfo(syncInfo); //} }
/// <summary> /// 设置任务的最后更新时间 /// </summary> protected void UpdateTaskLastUpdateTime(long taskId, DateTime lastUpdateTime) { Cooper.Model.Tasks.Task task = _taskService.GetTask(taskId); task.SetLastUpdateTime(lastUpdateTime); _taskService.Update(task); }