/// <summary> /// 删除Google Task /// </summary> private void DeleteGoogleTask(GoogleTaskSyncData taskData, TasksService googleTaskService, TaskList defaultTaskList) { bool success = false; try { googleTaskService.Tasks.Delete(defaultTaskList.Id, taskData.Id).Fetch(); _logger.InfoFormat("删除Google任务#{0}|{1}|{2}", taskData.Id, taskData.Subject, _account.ID); success = true; } catch (Exception ex) { _logger.Error("DeleteGoogleTask has exception.", ex); } if (success) { //删除同步信息 SyncInfo syncInfo = new SyncInfo(); syncInfo.AccountId = _account.ID; syncInfo.LocalDataId = taskData.SyncId; syncInfo.SyncDataId = taskData.Id; syncInfo.SyncDataType = taskData.SyncType; DeleteSyncInfo(syncInfo); } }
/// <summary> /// 创建Google Task /// </summary> private void CreateGoogleTask(GoogleTaskSyncData taskData, TasksService googleTaskService, TaskList defaultTaskList) { global::Google.Apis.Tasks.v1.Data.Task googleTask = null; bool success = false; try { //创建Google Task googleTask = googleTaskService.Tasks.Insert(taskData.GoogleTask, defaultTaskList.Id).Fetch(); _logger.InfoFormat("新增Google任务#{0}|{1}|{2}", googleTask.Id, googleTask.Title, _account.ID); success = true; } catch (Exception ex) { _logger.Error("CreateGoogleTask has exception.", ex); } if (success) { //更新任务最后更新时间,确保与Google Task的最后更新时间一致 UpdateTaskLastUpdateTime(long.Parse(taskData.SyncId), Rfc3339DateTime.Parse(googleTask.Updated).ToLocalTime()); //创建同步信息 if (defaultTaskList.Title == GoogleSyncSettings.DefaultTaskListName) { SyncInfo syncInfo = new SyncInfo(); syncInfo.AccountId = _account.ID; syncInfo.LocalDataId = taskData.SyncId; syncInfo.SyncDataId = googleTask.Id; syncInfo.SyncDataType = taskData.SyncType; InsertSyncInfo(syncInfo); } } }
/// <summary> /// 更新Google Task /// </summary> private void UpdateGoogleTask(GoogleTaskSyncData taskData, TasksService googleTaskService, TaskList defaultTaskList) { try { googleTaskService.Tasks.Update(taskData.GoogleTask, defaultTaskList.Id, taskData.Id).Fetch(); _logger.InfoFormat("更新Google任务#{0}|{1}|{2}", taskData.Id, taskData.Subject, _account.ID); var updatedGoogleTask = googleTaskService.Tasks.Get(defaultTaskList.Id, taskData.Id).Fetch(); UpdateTaskLastUpdateTime(long.Parse(taskData.SyncId), Rfc3339DateTime.Parse(updatedGoogleTask.Updated).ToLocalTime()); } catch (Exception ex) { _logger.Error("UpdateGoogleTask has exception.", ex); } }