1
0
mirror of https://github.com/Kopano-dev/kopano-ol-extension.git synced 2023-10-10 13:37:40 +02:00

Cleaned up ZPushWatcher.

Small cleanups.
All access to Outlook objects is now contained in wrappers/stubs.
This commit is contained in:
Patrick Simpson 2017-02-14 15:16:13 +01:00
parent cb32513ed3
commit b3ac1bd6b0
12 changed files with 36 additions and 39 deletions

View File

@ -191,7 +191,7 @@ namespace Acacia.Features.SharedFolders
ctx.AddBusy(-count); ctx.AddBusy(-count);
// Sync account // Sync account
_account.SendReceive(); _account.Account.SendReceive();
// Show success // Show success
ShowCompletion(Properties.Resources.SharedFolders_Applying_Success); ShowCompletion(Properties.Resources.SharedFolders_Applying_Success);

View File

@ -13,6 +13,8 @@ namespace Acacia.Stubs
IStore Store { get; } IStore Store { get; }
void SendReceive();
string DisplayName { get; } string DisplayName { get; }
string SmtpAddress { get; } string SmtpAddress { get; }

View File

@ -8,14 +8,12 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using NSOutlook = Microsoft.Office.Interop.Outlook; using NSOutlookDelegates = Microsoft.Office.Interop.Outlook;
namespace Acacia.Stubs namespace Acacia.Stubs
{ {
public interface IAddIn public interface IAddIn
{ {
NSOutlook.Application RawApp { get; } // TODO: remove
ZPushWatcher Watcher { get; } ZPushWatcher Watcher { get; }
MailEvents MailEvents { get; } MailEvents MailEvents { get; }
IEnumerable<Feature> Features { get; } IEnumerable<Feature> Features { get; }
@ -35,8 +33,8 @@ namespace Acacia.Stubs
#region Event handlers #region Event handlers
// TODO: custom event types // TODO: custom event types
event NSOutlook.ApplicationEvents_11_ItemLoadEventHandler ItemLoad; event NSOutlookDelegates.ApplicationEvents_11_ItemLoadEventHandler ItemLoad;
event NSOutlook.ApplicationEvents_11_ItemSendEventHandler ItemSend; event NSOutlookDelegates.ApplicationEvents_11_ItemSendEventHandler ItemSend;
#endregion #endregion

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using NSOutlookDelegates = Microsoft.Office.Interop.Outlook;
namespace Acacia.Stubs namespace Acacia.Stubs
{ {
@ -19,5 +20,11 @@ namespace Acacia.Stubs
/// </summary> /// </summary>
/// <returns>The folder. The caller is responsible for disposing.</returns> /// <returns>The folder. The caller is responsible for disposing.</returns>
IFolder GetCurrentFolder(); IFolder GetCurrentFolder();
#region Events
// TODO: custom delegates
event NSOutlookDelegates.ExplorerEvents_10_SelectionChangeEventHandler SelectionChange;
#endregion
} }
} }

View File

@ -45,12 +45,11 @@ namespace Acacia.Stubs.OutlookWrappers
} }
/// <summary> /// <summary>
/// Triggers an Outlook send/receive operation. /// Triggers an Outlook send/receive operation for this account.
/// </summary> /// </summary>
public void SendReceive() public void SendReceive()
{ {
// TODO: ThisAddIn.Instance.SendReceive(); ThisAddIn.Instance.SendReceive(this);
throw new NotImplementedException();
} }
#region Properties #region Properties

View File

@ -91,14 +91,6 @@ namespace Acacia.Stubs.OutlookWrappers
remove { _app.ItemSend -= value; } remove { _app.ItemSend -= value; }
} }
public NSOutlook.Application RawApp
{
get
{
return _app;
}
}
public ISyncObject GetSyncObject() public ISyncObject GetSyncObject()
{ {
using (ComRelease com = new ComRelease()) using (ComRelease com = new ComRelease())

View File

@ -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() protected override void DoRelease()
{ {
base.DoRelease(); base.DoRelease();
@ -28,5 +34,7 @@ namespace Acacia.Stubs.OutlookWrappers
{ {
return _item.CurrentFolder.Wrap(); return _item.CurrentFolder.Wrap();
} }
} }
} }

View File

@ -24,6 +24,7 @@ using NSOutlook = Microsoft.Office.Interop.Outlook;
namespace Acacia.Stubs.OutlookWrappers namespace Acacia.Stubs.OutlookWrappers
{ {
// TODO: a clean up is needed, move as much as possible to Wrappers.cs
public static class Mapping public static class Mapping
{ {
@ -32,7 +33,6 @@ namespace Acacia.Stubs.OutlookWrappers
/// </summary> /// </summary>
/// <param name="o">The Outlook object.</param> /// <param name="o">The Outlook object.</param>
/// <returns>The IItem wrapper, or null if the object could not be wrapped</returns> /// <returns>The IItem wrapper, or null if the object could not be wrapped</returns>
// TODO: made this private to see if it's still used
private static IBase Wrap(object o, bool mustRelease = true) private static IBase Wrap(object o, bool mustRelease = true)
{ {
if (o == null) if (o == null)

View File

@ -169,7 +169,6 @@ namespace Acacia.Stubs.OutlookWrappers
// And fetch it and wrap // And fetch it and wrap
return Mapping.Wrap(_item[_item.Count]); return Mapping.Wrap(_item[_item.Count]);
} }
throw new NotImplementedException();
} }
public IEnumerator<IStore> GetEnumerator() public IEnumerator<IStore> GetEnumerator()

View File

@ -48,7 +48,6 @@ namespace Acacia.UI
get get
{ {
return null; return null;
// TODO return ThisAddIn.Instance.Application;
} }
} }

View File

@ -61,14 +61,6 @@ namespace Acacia.ZPush
return _account.SmtpAddress; return _account.SmtpAddress;
} }
/// <summary>
/// Triggers an Outlook send/receive operation for this account.
/// </summary>
public void SendReceive()
{
ThisAddIn.Instance.SendReceive(Account);
}
#endregion #endregion
#region Identification and capabilities #region Identification and capabilities

View File

@ -26,7 +26,6 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using NSOutlook = Microsoft.Office.Interop.Outlook;
namespace Acacia.ZPush 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, /// 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. /// and it is easier to centralise all event registrations.
/// </summary> /// </summary>
public class ZPushWatcher public class ZPushWatcher : DisposableWrapper
{ {
private readonly IAddIn _addIn; private readonly IAddIn _addIn;
// TODO: remove
private readonly NSOutlook.Application _app;
public readonly ZPushAccounts Accounts; public readonly ZPushAccounts Accounts;
public readonly ZPushSync Sync; public readonly ZPushSync Sync;
private NSOutlook.Explorer _explorer2; private readonly IExplorer _explorer;
#region Setup #region Setup
@ -51,13 +47,19 @@ namespace Acacia.ZPush
public ZPushWatcher(IAddIn addIn) public ZPushWatcher(IAddIn addIn)
{ {
this._addIn = addIn; this._addIn = addIn;
this._app = addIn.RawApp;
Sync = new ZPushSync(this, addIn); Sync = new ZPushSync(this, addIn);
Accounts = new ZPushAccounts(this, addIn); Accounts = new ZPushAccounts(this, addIn);
// Need to keep a link to keep receiving events // Need to keep a link to keep receiving events
_explorer2 = _app.ActiveExplorer(); _explorer = _addIn.GetActiveExplorer();
_explorer2.SelectionChange += Explorer_SelectionChange; _explorer.SelectionChange += Explorer_SelectionChange;
}
protected override void DoRelease()
{
Accounts.Dispose();
Sync.Dispose();
_explorer.Dispose();
} }
/// <summary> /// <summary>
@ -150,8 +152,7 @@ namespace Acacia.ZPush
internal void OnAccountRemoved(ZPushAccount account) internal void OnAccountRemoved(ZPushAccount account)
{ {
// Notify any account listeners // Notify any account listeners
if (AccountRemoved != null) AccountRemoved?.Invoke(account);
AccountRemoved(account);
// TODO: unregister event listeners // TODO: unregister event listeners
} }