Skip to content

Commit

Permalink
Handle null being returned from GetCalendarEntriesInRecurrence()
Browse files Browse the repository at this point in the history
  • Loading branch information
phw198 committed Nov 1, 2020
1 parent 0ccc6a0 commit c06fb4b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public List<Event> GetCalendarEntriesInRecurrence(String recurringEventId) {
return result;

} catch (System.Exception ex) {
Forms.Main.Instance.Console.Update("Failed to retrieve recurring events", Console.Markup.error);
log.Error(ex.Message);
Forms.Main.Instance.Console.UpdateWithError("Failed to retrieve recurring events", OGCSexception.LogAsFail(ex));
OGCSexception.Analyse(ex);
return null;
}
}
Expand Down
72 changes: 37 additions & 35 deletions src/OutlookGoogleCalendarSync/Recurrence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ private Event getGoogleInstance(ref Microsoft.Office.Interop.Outlook.Exception o
log.Debug("Google exception event is not cached. Retrieving all recurring instances...");
}
List<Event> gInstances = GoogleOgcs.Calendar.Instance.GetCalendarEntriesInRecurrence(gRecurringEventID);
if (gInstances == null) return null;

//Add any new exceptions to local cache
googleExceptions = googleExceptions.Union(gInstances.Where(ev => !String.IsNullOrEmpty(ev.RecurringEventId))).ToList();
foreach (Event gInst in gInstances) {
Expand Down Expand Up @@ -524,47 +526,47 @@ public static void CreateGoogleExceptions(AppointmentItem ai, String recurringEv

log.Debug("Creating Google recurrence exceptions.");
List<Event> gRecurrences = GoogleOgcs.Calendar.Instance.GetCalendarEntriesInRecurrence(recurringEventId);
if (gRecurrences != null) {
RecurrencePattern rp = null;
Exceptions excps = null;
try {
rp = ai.GetRecurrencePattern();
excps = rp.Exceptions;
for (int e = 1; e <= excps.Count; e++) {
Microsoft.Office.Interop.Outlook.Exception oExcp = null;
try {
oExcp = excps[e];
for (int g = 0; g < gRecurrences.Count; g++) {
Event ev = gRecurrences[g];
DateTime gDate = ev.OriginalStartTime.DateTime ?? DateTime.Parse(ev.OriginalStartTime.Date);
Boolean isDeleted = exceptionIsDeleted(oExcp);
if (isDeleted && !ai.AllDayEvent) { //Deleted items get truncated?!
gDate = gDate.Date;
}
if (oExcp.OriginalDate == gDate) {
if (isDeleted) {
Forms.Main.Instance.Console.Update(GoogleOgcs.Calendar.GetEventSummary(ev), Console.Markup.calendar);
Forms.Main.Instance.Console.Update("Recurrence deleted.");
ev.Status = "cancelled";
GoogleOgcs.Calendar.Instance.UpdateCalendarEntry_save(ref ev);
} else {
int exceptionItemsModified = 0;
Event modifiedEv = GoogleOgcs.Calendar.Instance.UpdateCalendarEntry(oExcp.AppointmentItem, ev, ref exceptionItemsModified, forceCompare: true);
if (exceptionItemsModified > 0) {
GoogleOgcs.Calendar.Instance.UpdateCalendarEntry_save(ref modifiedEv);
}
if (gRecurrences == null) return;

RecurrencePattern rp = null;
Exceptions excps = null;
try {
rp = ai.GetRecurrencePattern();
excps = rp.Exceptions;
for (int e = 1; e <= excps.Count; e++) {
Microsoft.Office.Interop.Outlook.Exception oExcp = null;
try {
oExcp = excps[e];
for (int g = 0; g < gRecurrences.Count; g++) {
Event ev = gRecurrences[g];
DateTime gDate = ev.OriginalStartTime.DateTime ?? DateTime.Parse(ev.OriginalStartTime.Date);
Boolean isDeleted = exceptionIsDeleted(oExcp);
if (isDeleted && !ai.AllDayEvent) { //Deleted items get truncated?!
gDate = gDate.Date;
}
if (oExcp.OriginalDate == gDate) {
if (isDeleted) {
Forms.Main.Instance.Console.Update(GoogleOgcs.Calendar.GetEventSummary(ev), Console.Markup.calendar);
Forms.Main.Instance.Console.Update("Recurrence deleted.");
ev.Status = "cancelled";
GoogleOgcs.Calendar.Instance.UpdateCalendarEntry_save(ref ev);
} else {
int exceptionItemsModified = 0;
Event modifiedEv = GoogleOgcs.Calendar.Instance.UpdateCalendarEntry(oExcp.AppointmentItem, ev, ref exceptionItemsModified, forceCompare: true);
if (exceptionItemsModified > 0) {
GoogleOgcs.Calendar.Instance.UpdateCalendarEntry_save(ref modifiedEv);
}
break;
}
break;
}
} finally {
oExcp = (Microsoft.Office.Interop.Outlook.Exception)OutlookOgcs.Calendar.ReleaseObject(oExcp);
}
} finally {
oExcp = (Microsoft.Office.Interop.Outlook.Exception)OutlookOgcs.Calendar.ReleaseObject(oExcp);
}
} finally {
excps = (Exceptions)OutlookOgcs.Calendar.ReleaseObject(excps);
rp = (RecurrencePattern)OutlookOgcs.Calendar.ReleaseObject(rp);
}
} finally {
excps = (Exceptions)OutlookOgcs.Calendar.ReleaseObject(excps);
rp = (RecurrencePattern)OutlookOgcs.Calendar.ReleaseObject(rp);
}
}

Expand Down

0 comments on commit c06fb4b

Please sign in to comment.