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:
parent
cb32513ed3
commit
b3ac1bd6b0
@ -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);
|
||||
|
@ -13,6 +13,8 @@ namespace Acacia.Stubs
|
||||
|
||||
IStore Store { get; }
|
||||
|
||||
void SendReceive();
|
||||
|
||||
string DisplayName { get; }
|
||||
|
||||
string SmtpAddress { get; }
|
||||
|
@ -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<Feature> 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
|
||||
|
||||
|
@ -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
|
||||
/// </summary>
|
||||
/// <returns>The folder. The caller is responsible for disposing.</returns>
|
||||
IFolder GetCurrentFolder();
|
||||
|
||||
#region Events
|
||||
// TODO: custom delegates
|
||||
event NSOutlookDelegates.ExplorerEvents_10_SelectionChangeEventHandler SelectionChange;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -45,12 +45,11 @@ namespace Acacia.Stubs.OutlookWrappers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers an Outlook send/receive operation.
|
||||
/// Triggers an Outlook send/receive operation for this account.
|
||||
/// </summary>
|
||||
public void SendReceive()
|
||||
{
|
||||
// TODO: ThisAddIn.Instance.SendReceive();
|
||||
throw new NotImplementedException();
|
||||
ThisAddIn.Instance.SendReceive(this);
|
||||
}
|
||||
|
||||
#region Properties
|
||||
|
@ -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())
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
/// </summary>
|
||||
/// <param name="o">The Outlook object.</param>
|
||||
/// <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)
|
||||
{
|
||||
if (o == null)
|
||||
|
@ -169,7 +169,6 @@ namespace Acacia.Stubs.OutlookWrappers
|
||||
// And fetch it and wrap
|
||||
return Mapping.Wrap(_item[_item.Count]);
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerator<IStore> GetEnumerator()
|
||||
|
@ -48,7 +48,6 @@ namespace Acacia.UI
|
||||
get
|
||||
{
|
||||
return null;
|
||||
// TODO return ThisAddIn.Instance.Application;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,14 +61,6 @@ namespace Acacia.ZPush
|
||||
return _account.SmtpAddress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers an Outlook send/receive operation for this account.
|
||||
/// </summary>
|
||||
public void SendReceive()
|
||||
{
|
||||
ThisAddIn.Instance.SendReceive(Account);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Identification and capabilities
|
||||
|
@ -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.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user