diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SharedFolders/SharedFoldersDialog.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SharedFolders/SharedFoldersDialog.cs index b8cd460..193ded5 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SharedFolders/SharedFoldersDialog.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SharedFolders/SharedFoldersDialog.cs @@ -191,7 +191,7 @@ namespace Acacia.Features.SharedFolders ctx.AddBusy(-count); // Sync account - _account.SendReceive(); + _account.Account.SendReceive(); // Show success ShowCompletion(Properties.Resources.SharedFolders_Applying_Success); diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAccount.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAccount.cs index 0a5e138..13ea339 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAccount.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAccount.cs @@ -13,6 +13,8 @@ namespace Acacia.Stubs IStore Store { get; } + void SendReceive(); + string DisplayName { get; } string SmtpAddress { get; } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs index a4448c0..3378573 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs @@ -8,14 +8,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -using NSOutlook = Microsoft.Office.Interop.Outlook; +using NSOutlookDelegates = Microsoft.Office.Interop.Outlook; namespace Acacia.Stubs { public interface IAddIn { - NSOutlook.Application RawApp { get; } // TODO: remove - ZPushWatcher Watcher { get; } MailEvents MailEvents { get; } IEnumerable Features { get; } @@ -35,8 +33,8 @@ namespace Acacia.Stubs #region Event handlers // TODO: custom event types - event NSOutlook.ApplicationEvents_11_ItemLoadEventHandler ItemLoad; - event NSOutlook.ApplicationEvents_11_ItemSendEventHandler ItemSend; + event NSOutlookDelegates.ApplicationEvents_11_ItemLoadEventHandler ItemLoad; + event NSOutlookDelegates.ApplicationEvents_11_ItemSendEventHandler ItemSend; #endregion diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IExplorer.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IExplorer.cs index 33ec004..2df93ac 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IExplorer.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IExplorer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using NSOutlookDelegates = Microsoft.Office.Interop.Outlook; namespace Acacia.Stubs { @@ -19,5 +20,11 @@ namespace Acacia.Stubs /// /// The folder. The caller is responsible for disposing. IFolder GetCurrentFolder(); + + #region Events + // TODO: custom delegates + event NSOutlookDelegates.ExplorerEvents_10_SelectionChangeEventHandler SelectionChange; + + #endregion } } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AccountWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AccountWrapper.cs index 7b711c9..eb5d082 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AccountWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AccountWrapper.cs @@ -45,12 +45,11 @@ namespace Acacia.Stubs.OutlookWrappers } /// - /// Triggers an Outlook send/receive operation. + /// Triggers an Outlook send/receive operation for this account. /// public void SendReceive() { - // TODO: ThisAddIn.Instance.SendReceive(); - throw new NotImplementedException(); + ThisAddIn.Instance.SendReceive(this); } #region Properties diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs index 85d3994..e940be1 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs @@ -91,14 +91,6 @@ namespace Acacia.Stubs.OutlookWrappers remove { _app.ItemSend -= value; } } - public NSOutlook.Application RawApp - { - get - { - return _app; - } - } - public ISyncObject GetSyncObject() { using (ComRelease com = new ComRelease()) diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ExplorerWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ExplorerWrapper.cs index 6350abe..22dbe31 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ExplorerWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ExplorerWrapper.cs @@ -14,6 +14,12 @@ namespace Acacia.Stubs.OutlookWrappers { } + public event NSOutlook.ExplorerEvents_10_SelectionChangeEventHandler SelectionChange + { + add { _item.SelectionChange += value; } + remove { _item.SelectionChange -= value; } + } + protected override void DoRelease() { base.DoRelease(); @@ -28,5 +34,7 @@ namespace Acacia.Stubs.OutlookWrappers { return _item.CurrentFolder.Wrap(); } + + } } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/Mapping.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/Mapping.cs index c8d0ebd..050491f 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/Mapping.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/Mapping.cs @@ -24,6 +24,7 @@ using NSOutlook = Microsoft.Office.Interop.Outlook; namespace Acacia.Stubs.OutlookWrappers { + // TODO: a clean up is needed, move as much as possible to Wrappers.cs public static class Mapping { @@ -32,7 +33,6 @@ namespace Acacia.Stubs.OutlookWrappers /// /// The Outlook object. /// The IItem wrapper, or null if the object could not be wrapped - // TODO: made this private to see if it's still used private static IBase Wrap(object o, bool mustRelease = true) { if (o == null) diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoresWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoresWrapper.cs index 094bbd5..2ad6dbc 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoresWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoresWrapper.cs @@ -169,7 +169,6 @@ namespace Acacia.Stubs.OutlookWrappers // And fetch it and wrap return Mapping.Wrap(_item[_item.Count]); } - throw new NotImplementedException(); } public IEnumerator GetEnumerator() diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/SettingsDialog.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/SettingsDialog.cs index 68bc4a9..4bcceb5 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/SettingsDialog.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/SettingsDialog.cs @@ -48,7 +48,6 @@ namespace Acacia.UI get { return null; - // TODO return ThisAddIn.Instance.Application; } } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushAccount.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushAccount.cs index 768c095..294329d 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushAccount.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushAccount.cs @@ -61,14 +61,6 @@ namespace Acacia.ZPush return _account.SmtpAddress; } - /// - /// Triggers an Outlook send/receive operation for this account. - /// - public void SendReceive() - { - ThisAddIn.Instance.SendReceive(Account); - } - #endregion #region Identification and capabilities diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushWatcher.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushWatcher.cs index a00e888..f3d5a2c 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushWatcher.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushWatcher.cs @@ -26,7 +26,6 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; -using NSOutlook = Microsoft.Office.Interop.Outlook; namespace Acacia.ZPush { @@ -35,15 +34,12 @@ namespace Acacia.ZPush /// A global watcher is used, as a lot of features are interested in the same accounts, /// and it is easier to centralise all event registrations. /// - public class ZPushWatcher + public class ZPushWatcher : DisposableWrapper { private readonly IAddIn _addIn; - - // TODO: remove - private readonly NSOutlook.Application _app; public readonly ZPushAccounts Accounts; public readonly ZPushSync Sync; - private NSOutlook.Explorer _explorer2; + private readonly IExplorer _explorer; #region Setup @@ -51,13 +47,19 @@ namespace Acacia.ZPush public ZPushWatcher(IAddIn addIn) { this._addIn = addIn; - this._app = addIn.RawApp; Sync = new ZPushSync(this, addIn); Accounts = new ZPushAccounts(this, addIn); // Need to keep a link to keep receiving events - _explorer2 = _app.ActiveExplorer(); - _explorer2.SelectionChange += Explorer_SelectionChange; + _explorer = _addIn.GetActiveExplorer(); + _explorer.SelectionChange += Explorer_SelectionChange; + } + + protected override void DoRelease() + { + Accounts.Dispose(); + Sync.Dispose(); + _explorer.Dispose(); } /// @@ -150,8 +152,7 @@ namespace Acacia.ZPush internal void OnAccountRemoved(ZPushAccount account) { // Notify any account listeners - if (AccountRemoved != null) - AccountRemoved(account); + AccountRemoved?.Invoke(account); // TODO: unregister event listeners }