/// <summary> /// 删除Google Calendar Event /// </summary> private void DeleteGoogleCalendarEvent(GoogleCalendarEventSyncData calendarEventData, CalendarService googleCalendarService, Calendar defaultCalendar) { bool success = false; try { googleCalendarService.Events.Delete(defaultCalendar.Id, calendarEventData.Id).Fetch(); _logger.InfoFormat("删除Google日历事件#{0}|{1}|{2}", calendarEventData.Id, calendarEventData.Subject, _account.ID); success = true; } catch (Exception ex) { _logger.Error("DeleteGoogleCalendarEvent has exception.", ex); } if (success) { //删除同步信息 SyncInfo syncInfo = new SyncInfo(); syncInfo.AccountId = _account.ID; syncInfo.LocalDataId = calendarEventData.SyncId; syncInfo.SyncDataId = calendarEventData.Id; syncInfo.SyncDataType = calendarEventData.SyncType; DeleteSyncInfo(syncInfo); } }
/// <summary> /// 创建Google Calendar Event /// </summary> private void CreateGoogleCalendarEvent(GoogleCalendarEventSyncData calendarEventData, CalendarService googleCalendarService, Calendar defaultCalendar) { global::Google.Apis.Calendar.v3.Data.Event calendarEvent = null; bool success = false; try { //创建Google Calendar Event calendarEvent = googleCalendarService.Events.Insert(calendarEventData.GoogleCalendarEvent, defaultCalendar.Id).Fetch(); _logger.InfoFormat("新增Google日历事件#{0}|{1}|{2}", calendarEvent.Id, calendarEvent.Summary, _account.ID); success = true; } catch (Exception ex) { _logger.Error("CreateGoogleCalendarEvent has exception.", ex); } if (success) { //更新任务最后更新时间,确保与Google Calendar Event的最后更新时间一致 UpdateTaskLastUpdateTime(long.Parse(calendarEventData.SyncId), Rfc3339DateTime.Parse(calendarEvent.Updated).ToLocalTime()); //创建同步信息 if (defaultCalendar.Summary == GoogleSyncSettings.DefaultCalendarName) { SyncInfo syncInfo = new SyncInfo(); syncInfo.AccountId = _account.ID; syncInfo.LocalDataId = calendarEventData.SyncId; syncInfo.SyncDataId = calendarEvent.Id; syncInfo.SyncDataType = calendarEventData.SyncType; InsertSyncInfo(syncInfo); } } }
/// <summary> /// 更新Google Calendar Event /// </summary> private void UpdateGoogleCalendarEvent(GoogleCalendarEventSyncData calendarEventData, CalendarService googleCalendarService, Calendar defaultCalendar) { try { googleCalendarService.Events.Update(calendarEventData.GoogleCalendarEvent, defaultCalendar.Id, calendarEventData.Id).Fetch(); _logger.InfoFormat("更新Google日历事件#{0}|{1}|{2}", calendarEventData.Id, calendarEventData.Subject, _account.ID); var updatedGoogleCalendarEvent = googleCalendarService.Events.Get(defaultCalendar.Id, calendarEventData.Id).Fetch(); UpdateTaskLastUpdateTime(long.Parse(calendarEventData.SyncId), Rfc3339DateTime.Parse(updatedGoogleCalendarEvent.Updated).ToLocalTime()); } catch (Exception ex) { _logger.Error("UpdateGoogleCalendarEvent has exception.", ex); } }