Cleaned up ZPushSync.

This commit is contained in:
Patrick Simpson 2017-02-14 10:47:51 +01:00
parent f913ed5a01
commit d4b03c2eb9
7 changed files with 122 additions and 6 deletions

View File

@ -288,6 +288,7 @@
<Compile Include="Stubs\IItemEvents.cs" />
<Compile Include="Stubs\IOutlookWindow.cs" />
<Compile Include="Stubs\IRecipient.cs" />
<Compile Include="Stubs\ISyncObject.cs" />
<Compile Include="Stubs\OutlookWrappers\AddInWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\AddressEntryWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\CommandBarsWrapper.cs" />
@ -295,6 +296,7 @@
<Compile Include="Stubs\OutlookWrappers\ItemEventsWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\OutlookItemWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\RecipientWrapper.cs" />
<Compile Include="Stubs\OutlookWrappers\SyncObjectWrapper.cs" />
<Compile Include="Stubs\Wrappers.cs" />
<Compile Include="UI\Outlook\OutlookImageList.cs" />
<Compile Include="UI\Outlook\RibbonToggleButton.cs" />

View File

@ -21,6 +21,7 @@ namespace Acacia.Stubs
IEnumerable<Feature> Features { get; }
IEnumerable<KeyValuePair<string,string>> COMAddIns { get; }
string Version { get; }
ISyncObject GetSyncObject();
#region UI

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NSOutlook = Microsoft.Office.Interop.Outlook;
namespace Acacia.Stubs
{
public interface ISyncObject : IComWrapper
{
#region Properties
string Name { get; }
#endregion
#region Methods
void Start();
void Stop();
#endregion
#region Events
// TODO: custom delegates
event NSOutlook.SyncObjectEvents_OnErrorEventHandler OnError;
event NSOutlook.SyncObjectEvents_ProgressEventHandler Progress;
event NSOutlook.SyncObjectEvents_SyncEndEventHandler SyncEnd;
event NSOutlook.SyncObjectEvents_SyncStartEventHandler SyncStart;
#endregion
}
}

View File

@ -82,6 +82,16 @@ namespace Acacia.Stubs.OutlookWrappers
}
}
public ISyncObject GetSyncObject()
{
using (ComRelease com = new ComRelease())
{
NSOutlook.NameSpace session = com.Add(_app.Session);
NSOutlook.SyncObjects syncObjects = com.Add(session.SyncObjects);
return new SyncObjectWrapper(syncObjects.AppFolders);
}
}
#region UI
public OutlookUI OutlookUI { get { return _thisAddIn.OutlookUI; } }

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NSOutlook = Microsoft.Office.Interop.Outlook;
namespace Acacia.Stubs.OutlookWrappers
{
class SyncObjectWrapper : ComWrapper<NSOutlook.SyncObject>, ISyncObject
{
public SyncObjectWrapper(NSOutlook.SyncObject item) : base(item)
{
}
#region Properties
public string Name { get { return _item.Name; } }
#endregion
#region Methods
public void Start()
{
_item.Start();
}
public void Stop()
{
_item.Stop();
}
#endregion
#region Events
public event NSOutlook.SyncObjectEvents_OnErrorEventHandler OnError
{
add { _item.OnError += value; }
remove { _item.OnError -= value; }
}
public event NSOutlook.SyncObjectEvents_ProgressEventHandler Progress
{
add { _item.Progress += value; }
remove { _item.Progress -= value; }
}
public event NSOutlook.SyncObjectEvents_SyncEndEventHandler SyncEnd
{
add { _item.SyncEnd += value; }
remove { _item.SyncEnd -= value; }
}
public event NSOutlook.SyncObjectEvents_SyncStartEventHandler SyncStart
{
add { _item.SyncStart += value; }
remove { _item.SyncStart -= value; }
}
#endregion
}
}

View File

@ -15,6 +15,7 @@
/// Consult LICENSE file for details
using Acacia.Features;
using Acacia.Stubs;
using Acacia.Utils;
using Acacia.ZPush.Connect;
using System;
@ -23,14 +24,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NSOutlook = Microsoft.Office.Interop.Outlook;
namespace Acacia.ZPush
{
/// <summary>
/// Helper for synchronising state with ZPush servers
/// </summary>
public class ZPushSync
public class ZPushSync : DisposableWrapper
{
#region SyncTask
@ -77,7 +77,7 @@ namespace Acacia.ZPush
#region Setup
private readonly NSOutlook.SyncObject _syncObject;
private readonly ISyncObject _syncObject;
private readonly Timer _timer;
private ZPushWatcher _watcher;
private bool _started;
@ -86,7 +86,7 @@ namespace Acacia.ZPush
public readonly bool Enabled;
public readonly TimeSpan Period;
public ZPushSync(ZPushWatcher watcher, NSOutlook.Application app)
public ZPushSync(ZPushWatcher watcher, IAddIn addIn)
{
// Get the settings
Enabled = GlobalOptions.INSTANCE.ZPushSync;
@ -104,12 +104,17 @@ namespace Acacia.ZPush
_timer.Start();
// Need to keep a reference to keep receiving events
_syncObject = app.Session.SyncObjects.AppFolders;
_syncObject = addIn.GetSyncObject();
_syncObject.SyncStart += SyncObject_SyncStart;
watcher.AccountDiscovered += Watcher_AccountDiscovered;
}
}
protected override void DoRelease()
{
_syncObject.Dispose();
}
#endregion
#region Public interface

View File

@ -52,7 +52,7 @@ namespace Acacia.ZPush
{
this._addIn = addIn;
this._app = addIn.RawApp;
Sync = new ZPushSync(this, _app);
Sync = new ZPushSync(this, addIn);
Accounts = new ZPushAccounts(this, _app);
// Need to keep a link to keep receiving events