diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Constants.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Constants.cs
index b45f9ef..8e16718 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Constants.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Constants.cs
@@ -102,8 +102,16 @@ namespace Acacia
public const string DATE_ISO_8601 = "yyyyMMddTHHmmssZ";
+ ///
+ /// Default period for synchronisation tasks
+ ///
public static readonly TimeSpan ZPUSH_SYNC_DEFAULT_PERIOD = new TimeSpan(1, 0, 0);
+ ///
+ /// Default period during which synchronisation tasks will not be executed again.
+ ///
+ public static readonly TimeSpan ZPUSH_SYNC_DEFAULT_PERIOD_THROTTLE = new TimeSpan(0, 15, 0);
+
#region Registry
public const string PLUGIN_REGISTRY_BASE = "Software\\" + PRODUCT_PREFIX + "\\" + PRODUCT_NAME;
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/DebugSupport/DebugInfo.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/DebugSupport/DebugInfo.cs
index e6ddead..dc0244f 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/DebugSupport/DebugInfo.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/DebugSupport/DebugInfo.cs
@@ -194,6 +194,16 @@ namespace Acacia.Features.DebugSupport
{
get { return ThisAddIn.Instance.Watcher.Sync.Period; }
}
+ [DebugCategory(DebugCategory.Misc)]
+ public TimeSpan ZPushSyncPeriodThrottle
+ {
+ get { return ThisAddIn.Instance.Watcher.Sync.PeriodThrottle; }
+ }
+ [DebugCategory(DebugCategory.Misc)]
+ public DateTime ZPushSyncLast
+ {
+ get { return ThisAddIn.Instance.Watcher.Sync.LastSyncTime; }
+ }
[DebugCategory(DebugCategory.Misc)]
public string Build
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs
index 72d9fc4..7d7e9d2 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs
@@ -90,6 +90,14 @@ namespace Acacia
}
private static readonly TimeSpanOption ZPUSH_SYNC_PERIOD = new TimeSpanOption("ZPushSyncPeriod", Constants.ZPUSH_SYNC_DEFAULT_PERIOD);
+ [AcaciaOption("Sets the interval during which ZPush synchronization tasks will be not executed to prevent overloading the server.")]
+ public TimeSpan ZPushSync_PeriodThrottle
+ {
+ get { return GetOption(null, ZPUSH_SYNC_PERIOD_THROTTLE); }
+ set { SetOption(null, ZPUSH_SYNC_PERIOD_THROTTLE, value); }
+ }
+ private static readonly TimeSpanOption ZPUSH_SYNC_PERIOD_THROTTLE = new TimeSpanOption("ZPushSyncPeriodThrottle", Constants.ZPUSH_SYNC_DEFAULT_PERIOD_THROTTLE);
+
[AcaciaOption("Disables the release of COM objects. This generally leads to resource leaks and should " +
"only be disabled for debug purposes.")]
public bool COMRelease
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushSync.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushSync.cs
index abed17b..179126c 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushSync.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushSync.cs
@@ -1,4 +1,4 @@
-/// Copyright 2016 Kopano b.v.
+/// Copyright 2017 Kopano b.v.
///
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License, version 3,
@@ -28,7 +28,7 @@ using System.Windows.Forms;
namespace Acacia.ZPush
{
///
- /// Helper for synchronising state with ZPush servers
+ /// Helper for periodically synchronising state with ZPush servers
///
public class ZPushSync : DisposableWrapper
{
@@ -85,6 +85,8 @@ namespace Acacia.ZPush
public readonly bool Enabled;
public readonly TimeSpan Period;
+ public readonly TimeSpan PeriodThrottle;
+ public DateTime LastSyncTime;
public ZPushSync(ZPushWatcher watcher, IAddIn addIn)
{
@@ -93,6 +95,9 @@ namespace Acacia.ZPush
Period = GlobalOptions.INSTANCE.ZPushSync_Period;
if (Period.Ticks == 0)
Period = Constants.ZPUSH_SYNC_DEFAULT_PERIOD;
+ PeriodThrottle = GlobalOptions.INSTANCE.ZPushSync_PeriodThrottle;
+ if (PeriodThrottle.Ticks == 0)
+ PeriodThrottle = Constants.ZPUSH_SYNC_DEFAULT_PERIOD_THROTTLE;
// Set up a timer and events if enabled
if (Enabled)
@@ -174,13 +179,24 @@ namespace Acacia.ZPush
#region Task execution
///
- /// Executes the tasks for all known ZPush accounts
+ /// Executes the tasks for all known ZPush accounts. Only executed if enough time has passed since the last check.
///
- private void ExecuteTasks()
+ private void PossiblyExecuteTasks()
{
+ // Don't contact the network if Outlook is offline
if (ThisAddIn.Instance.IsOffline)
return;
+ // Check for time
+ DateTime now = DateTime.Now;
+ if (LastSyncTime != null && now.Subtract(LastSyncTime) < PeriodThrottle)
+ {
+ // Back off
+ return;
+ }
+ LastSyncTime = now;
+
+ // Execute tasks for all accounts
foreach (ZPushAccount account in _watcher.Accounts.GetAccounts())
ExecuteTasks(account);
}
@@ -191,6 +207,11 @@ namespace Acacia.ZPush
///
private void ExecuteTasks(ZPushAccount account)
{
+ // Don't contact the network if Outlook is offline
+ if (ThisAddIn.Instance.IsOffline)
+ return;
+
+ // Execute the tasks for the account
foreach (SyncTask task in _tasks)
{
Tasks.Task(task.GetInstance(account));
@@ -202,7 +223,7 @@ namespace Acacia.ZPush
///
private void _timer_Tick(object sender, EventArgs e)
{
- ExecuteTasks();
+ PossiblyExecuteTasks();
}
///
@@ -225,7 +246,7 @@ namespace Acacia.ZPush
if (_started)
{
// Explicit sync, run tasks
- ExecuteTasks();
+ PossiblyExecuteTasks();
}
}