From 71e55c3c648d94dae60152f39e14819439a8cd0d Mon Sep 17 00:00:00 2001 From: Paul Woolcock <11843015+phw198@users.noreply.github.com> Date: Sat, 8 Aug 2020 11:34:20 +0100 Subject: [PATCH] Sync Outlook deletion on first 2-way sync. Resolves #1050 --- .../GoogleOgcs/GoogleCalendar.cs | 2 +- .../OutlookOgcs/OutlookCalendar.cs | 2 +- src/OutlookGoogleCalendarSync/Sync/Engine.cs | 23 ++++++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs b/src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs index b71ab96c..0635ea33 100644 --- a/src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs +++ b/src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs @@ -1093,7 +1093,7 @@ public void IdentifyEventDifferences( //Don't delete any items that aren't yet in Outlook or just created in Outlook during this sync for (int g = google.Count - 1; g >= 0; g--) { if (!CustomProperty.Exists(google[g], CustomProperty.MetadataId.oEntryId) || - google[g].Updated > Settings.Instance.LastSyncDate) + google[g].Updated > Sync.Engine.Instance.SyncStarted) google.Remove(google[g]); } } diff --git a/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs b/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs index 972d2720..5c17a121 100644 --- a/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs +++ b/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs @@ -1322,7 +1322,7 @@ public static void IdentifyEventDifferences( //Don't delete any items that aren't yet in Google or just created in Google during this sync for (int o = outlook.Count - 1; o >= 0; o--) { if (!CustomProperty.Exists(outlook[o], CustomProperty.MetadataId.gEventID) || - outlook[o].LastModificationTime > Settings.Instance.LastSyncDate) + outlook[o].LastModificationTime > Sync.Engine.Instance.SyncStarted) outlook.Remove(outlook[o]); } } diff --git a/src/OutlookGoogleCalendarSync/Sync/Engine.cs b/src/OutlookGoogleCalendarSync/Sync/Engine.cs index 2d37a0bd..671e7f17 100644 --- a/src/OutlookGoogleCalendarSync/Sync/Engine.cs +++ b/src/OutlookGoogleCalendarSync/Sync/Engine.cs @@ -25,6 +25,8 @@ public static Engine Instance { public Engine() { } + /// The time the current sync started + public DateTime SyncStarted { get; protected set; } public SyncTimer OgcsTimer; public Sync.PushSyncTimer OgcsPushTimer; private AbortableBackgroundWorker bwSync; @@ -134,7 +136,7 @@ public void AbortSync() { public void Start(Boolean updateSyncSchedule = true) { Forms.Main mainFrm = Forms.Main.Instance; try { - DateTime syncStarted = DateTime.Now; + this.SyncStarted = DateTime.Now; String cacheNextSync = mainFrm.NextSyncVal; mainFrm.Console.Clear(); @@ -149,7 +151,7 @@ public void Start(Boolean updateSyncSchedule = true) { //Check network availability if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { mainFrm.Console.Update("There does not appear to be any network available! Sync aborted.", Console.Markup.warning, notifyBubble: true); - setNextSync(syncStarted, false, updateSyncSchedule, cacheNextSync); + setNextSync(false, updateSyncSchedule, cacheNextSync); return; } //Check if Outlook is Online @@ -157,7 +159,7 @@ public void Start(Boolean updateSyncSchedule = true) { if (OutlookOgcs.Calendar.Instance.IOutlook.Offline() && Settings.Instance.AddAttendees) { mainFrm.Console.Update("

You have selected to sync attendees but Outlook is currently offline.

" + "

Either put Outlook online or do not sync attendees.

", Console.Markup.error, notifyBubble: true); - setNextSync(syncStarted, false, updateSyncSchedule, cacheNextSync); + setNextSync(false, updateSyncSchedule, cacheNextSync); return; } } catch (System.Exception ex) { @@ -174,7 +176,7 @@ public void Start(Boolean updateSyncSchedule = true) { StringBuilder sb = new StringBuilder(); mainFrm.Console.BuildOutput("Sync version: " + System.Windows.Forms.Application.ProductVersion, ref sb); - mainFrm.Console.BuildOutput((ManualForceCompare ? "Full s" : "S") + "ync started at " + syncStarted.ToString(), ref sb); + mainFrm.Console.BuildOutput((ManualForceCompare ? "Full s" : "S") + "ync started at " + this.SyncStarted.ToString(), ref sb); mainFrm.Console.BuildOutput("Syncing from " + Settings.Instance.SyncStart.ToShortDateString() + " to " + Settings.Instance.SyncEnd.ToShortDateString(), ref sb); mainFrm.Console.BuildOutput(Settings.Instance.SyncDirection.Name, ref sb); @@ -302,7 +304,7 @@ public void Start(Boolean updateSyncSchedule = true) { mainFrm.Console.Update("Sync aborted after " + failedAttempts + " failed attempts!", syncResult == SyncResult.UserCancelled ? Console.Markup.fail : Console.Markup.error); } - setNextSync(syncStarted, syncResult == SyncResult.OK, updateSyncSchedule, cacheNextSync); + setNextSync(syncResult == SyncResult.OK, updateSyncSchedule, cacheNextSync); mainFrm.CheckSyncMilestone(); } finally { @@ -317,25 +319,24 @@ public void Start(Boolean updateSyncSchedule = true) { OutlookOgcs.Calendar.Disconnect(onlyWhenNoGUI: true); } } - + /// /// Set the next scheduled sync /// - /// The time the current sync started /// The result of the current sync /// Whether to calculate the next sync time or not /// The time previously calculated for the next sync when the current one started. /// If updateSyncSchedule is false, this value persists. - private void setNextSync(DateTime syncStarted, Boolean syncedOk, Boolean updateSyncSchedule, String cacheNextSync) { + private void setNextSync(Boolean syncedOk, Boolean updateSyncSchedule, String cacheNextSync) { if (syncedOk) { - Forms.Main.Instance.LastSyncVal = syncStarted.ToLongDateString() + " @ " + syncStarted.ToLongTimeString(); - Settings.Instance.LastSyncDate = syncStarted; + Forms.Main.Instance.LastSyncVal = this.SyncStarted.ToLongDateString() + " @ " + this.SyncStarted.ToLongTimeString(); + Settings.Instance.LastSyncDate = this.SyncStarted; } if (!updateSyncSchedule) { Forms.Main.Instance.NextSyncVal = cacheNextSync; } else { if (syncedOk) { - OgcsTimer.LastSyncDate = syncStarted; + OgcsTimer.LastSyncDate = this.SyncStarted; OgcsTimer.SetNextSync(); } else { if (Settings.Instance.SyncInterval != 0) {