Skip to content

Commit

Permalink
Merge branch 'bugfix/issue-2034/recurring-instances' into release
Browse files Browse the repository at this point in the history
Closes #2034
  • Loading branch information
phw198 committed Jan 12, 2025
2 parents 4867e0d + a4c5776 commit 531c932
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
14 changes: 11 additions & 3 deletions src/OutlookGoogleCalendarSync/Google/GoogleCalendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public void GetCalendars() {
this.CalendarList = result;
}

/// <summary>Retrieve all instances for a recurring series.</summary>
public List<Event> GetCalendarEntriesInRecurrence(String recurringEventId) {
List<Event> result = new List<Event>();
Events request = null;
Expand Down Expand Up @@ -280,12 +281,16 @@ public Event GetCalendarEntry(String eventId) {
}
}

public List<Event> GetCalendarEntriesInRange() {
/// <summary>Get calendar Events occurring between the sync date ranges</summary>
/// <returns>Single events, recurring master and exceptions</returns>
public List<Event> GetCalendarEntriesInRange(String recurringId = null) {
SettingsStore.Calendar profile = Settings.Profile.InPlay();
return GetCalendarEntriesInRange(profile.SyncStart, profile.SyncEnd);
return GetCalendarEntriesInRange(profile.SyncStart, profile.SyncEnd, false, recurringId);
}

public List<Event> GetCalendarEntriesInRange(System.DateTime from, System.DateTime to, Boolean suppressAdvisories = false) {
/// <summary>Get calendar Events occurring between the specified dates</summary>
/// <returns>Single events, recurring master and exceptions</returns>
public List<Event> GetCalendarEntriesInRange(System.DateTime from, System.DateTime to, Boolean suppressAdvisories = false, String recurringId = null) {
List<Event> result = new List<Event>();
Events request = null;
String pageToken = null;
Expand All @@ -304,6 +309,7 @@ public List<Event> GetCalendarEntriesInRange(System.DateTime from, System.DateTi
lr.ShowDeleted = false;
lr.SingleEvents = false;
lr.EventTypes = permittedEventTypes;
if (!string.IsNullOrEmpty(recurringId)) lr.ICalUID = recurringId + "@google.com";

int backoff = 0;
while (backoff < BackoffLimit) {
Expand Down Expand Up @@ -392,6 +398,8 @@ public List<Event> GetCalendarEntriesInRange(System.DateTime from, System.DateTi
}
}

Recurrence.Instance.SeparateGoogleExceptions(result);

log.Fine("Filtered down to " + result.Count);
return result;
}
Expand Down
30 changes: 14 additions & 16 deletions src/OutlookGoogleCalendarSync/Recurrence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public void SeparateGoogleExceptions(List<Event> allEvents) {
}

/// <summary>
/// Get occurrence that originally started on a particular date
/// Search cached exceptions for occurrence that originally started on a particular date
/// </summary>
/// <param name="recurringEventId">The recurring series to search within</param>
/// <param name="originalInstanceDate">The date to search for</param>
Expand Down Expand Up @@ -462,29 +462,27 @@ private Event getGoogleInstance(Microsoft.Office.Interop.Outlook.Exception oExcp
}
}
if (dirtyCache) {
log.Debug("Google exception cache not being used. Retrieving all recurring instances afresh...");
log.Debug("Google exception cache not being used. Retrieving all recurring exceptions afresh...");
//Remove dirty items
googleExceptions.RemoveAll(ev => ev.RecurringEventId == gRecurringEventID);
} else {
foreach (Event gExcp in googleExceptions) {
if (gExcp.RecurringEventId == gRecurringEventID) {
if (((oIsDeleted == DeletionState.NotDeleted || (oIsDeleted == DeletionState.Deleted && !oExcp.Deleted)) /* Weirdness when exception is cancelled by organiser but not yet deleted/accepted by recipient */
&& oExcp.OriginalDate == gExcp.OriginalStartTime.SafeDateTime()
) ||
(oIsDeleted == DeletionState.Deleted &&
oExcp.OriginalDate == gExcp.OriginalStartTime.SafeDateTime().Date
)) {
return gExcp;
}
Google.Calendar.Instance.GetCalendarEntriesInRange(gRecurringEventID);
}
foreach (Event gExcp in googleExceptions) {
if (gExcp.RecurringEventId == gRecurringEventID) {
if (((oIsDeleted == DeletionState.NotDeleted || (oIsDeleted == DeletionState.Deleted && !oExcp.Deleted)) /* Weirdness when exception is cancelled by organiser but not yet deleted/accepted by recipient */
&& oExcp.OriginalDate == gExcp.OriginalStartTime.SafeDateTime()
) ||
(oIsDeleted == DeletionState.Deleted &&
oExcp.OriginalDate == gExcp.OriginalStartTime.SafeDateTime().Date
)) {
return gExcp;
}
}
log.Debug("Google exception event is not cached. Retrieving all recurring instances...");
}
log.Debug("Google exception event is not cached. Retrieving all recurring instances...");
List<Event> gInstances = Ogcs.Google.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) {
if (gInst.RecurringEventId == gRecurringEventID) {
if (((oIsDeleted == DeletionState.NotDeleted || (oIsDeleted == DeletionState.Deleted && !oExcp.Deleted)) /* Weirdness when exception is cancelled by organiser but not yet deleted/accepted by recipient */
Expand Down
10 changes: 4 additions & 6 deletions src/OutlookGoogleCalendarSync/Sync/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,10 @@ private SyncResult synchronize() {
ex.Data["OGCS"] += " Please try again.";
throw;
}
Recurrence.Instance.SeparateGoogleExceptions(googleEntries);
if (Recurrence.Instance.GoogleExceptions != null && Recurrence.Instance.GoogleExceptions.Count > 0) {
console.Update(googleEntries.Count + " Google calendar entries found.");
console.Update(Recurrence.Instance.GoogleExceptions.Count + " are exceptions to recurring events.", Console.Markup.sectionEnd, newLine: false);
} else
console.Update(googleEntries.Count + " Google calendar entries found.", Console.Markup.sectionEnd, newLine: false);
String consoleOutput = googleEntries.Count + " Google calendar entries found.";
if (Recurrence.Instance.GoogleExceptions != null && Recurrence.Instance.GoogleExceptions.Count > 0)
consoleOutput += "<br/>" + Recurrence.Instance.GoogleExceptions.Count + " additional exceptions to recurring events.";
console.Update(consoleOutput, Console.Markup.sectionEnd, newLine: false);

if (Sync.Engine.Instance.CancellationPending) return SyncResult.UserCancelled;
#endregion
Expand Down

0 comments on commit 531c932

Please sign in to comment.