Skip to content

Commit

Permalink
Sync Outlook deletion on first 2-way sync.
Browse files Browse the repository at this point in the history
Resolves #1050
  • Loading branch information
phw198 committed Aug 8, 2020
1 parent 980cb47 commit 71e55c3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
23 changes: 12 additions & 11 deletions src/OutlookGoogleCalendarSync/Sync/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static Engine Instance {

public Engine() { }

/// <summary>The time the current sync started</summary>
public DateTime SyncStarted { get; protected set; }
public SyncTimer OgcsTimer;
public Sync.PushSyncTimer OgcsPushTimer;
private AbortableBackgroundWorker bwSync;
Expand Down Expand Up @@ -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();
Expand All @@ -149,15 +151,15 @@ 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
try {
if (OutlookOgcs.Calendar.Instance.IOutlook.Offline() && Settings.Instance.AddAttendees) {
mainFrm.Console.Update("<p>You have selected to sync attendees but Outlook is currently offline.</p>" +
"<p>Either put Outlook online or do not sync attendees.</p>", Console.Markup.error, notifyBubble: true);
setNextSync(syncStarted, false, updateSyncSchedule, cacheNextSync);
setNextSync(false, updateSyncSchedule, cacheNextSync);
return;
}
} catch (System.Exception ex) {
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -317,25 +319,24 @@ public void Start(Boolean updateSyncSchedule = true) {
OutlookOgcs.Calendar.Disconnect(onlyWhenNoGUI: true);
}
}

/// <summary>
/// Set the next scheduled sync
/// </summary>
/// <param name="syncStarted">The time the current sync started</param>
/// <param name="syncedOk">The result of the current sync</param>
/// <param name="updateSyncSchedule">Whether to calculate the next sync time or not</param>
/// <param name="cacheNextSync">The time previously calculated for the next sync when the current one started.
/// If updateSyncSchedule is false, this value persists.</param>
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) {
Expand Down

0 comments on commit 71e55c3

Please sign in to comment.