mirror of
https://github.com/Kopano-dev/kopano-ol-extension.git
synced 2023-10-10 13:37:40 +02:00
Further fixes for item events
This commit is contained in:
parent
b3c0aae951
commit
49efb68298
@ -35,12 +35,9 @@ namespace Acacia.Stubs
|
||||
string Subject { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the events for the item. The same object is returned, it does not need to be disposed.
|
||||
/// Returns the events for the item. The caller is responsible for disposing.
|
||||
/// </summary>
|
||||
IItemEvents Events
|
||||
{
|
||||
get;
|
||||
}
|
||||
IItemEvents GetEvents();
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -7,7 +7,7 @@ using NSOutlook = Microsoft.Office.Interop.Outlook;
|
||||
|
||||
namespace Acacia.Stubs
|
||||
{
|
||||
public interface IItemEvents
|
||||
public interface IItemEvents : IComWrapper
|
||||
{
|
||||
#region Event handlers
|
||||
|
||||
|
@ -7,13 +7,11 @@ using NSOutlook = Microsoft.Office.Interop.Outlook;
|
||||
|
||||
namespace Acacia.Stubs.OutlookWrappers
|
||||
{
|
||||
class ItemEventsWrapper : IItemEvents
|
||||
class ItemEventsWrapper : ComWrapper<NSOutlook.ItemEvents_10_Event>, IItemEvents
|
||||
{
|
||||
private readonly NSOutlook.ItemEvents_10_Event _item;
|
||||
|
||||
internal ItemEventsWrapper(object item)
|
||||
internal ItemEventsWrapper(NSOutlook.ItemEvents_10_Event item) : base(item)
|
||||
{
|
||||
this._item = (NSOutlook.ItemEvents_10_Event)item;
|
||||
MustRelease = false;
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
@ -16,15 +16,9 @@ namespace Acacia.Stubs.OutlookWrappers
|
||||
{
|
||||
}
|
||||
|
||||
private ItemEventsWrapper _events;
|
||||
public IItemEvents Events
|
||||
public IItemEvents GetEvents()
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_events == null)
|
||||
_events = new ItemEventsWrapper(_item);
|
||||
return _events;
|
||||
}
|
||||
return new ItemEventsWrapper((NSOutlook.ItemEvents_10_Event)_item);
|
||||
}
|
||||
|
||||
public Type GetUserProperty<Type>(string name)
|
||||
|
@ -190,8 +190,8 @@ namespace Acacia.Utils
|
||||
|
||||
private void OnItemLoad(object item)
|
||||
{
|
||||
IItem wrapped = Wrappers.Wrap<IItem>(item);
|
||||
// TODO: check type
|
||||
IItem wrapped = Wrappers.Wrap<IItem>(item, false);
|
||||
// TODO: only register for desired types
|
||||
if (wrapped != null)
|
||||
{
|
||||
new MailEventHooker(wrapped, this);
|
||||
@ -214,40 +214,37 @@ namespace Acacia.Utils
|
||||
HookEvents(true);
|
||||
}
|
||||
|
||||
/*~MailEventHooker()
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
protected override void DoRelease()
|
||||
{
|
||||
Logger.Instance.Debug(this, "DoRelease: {0}", _id);
|
||||
// TODO: It looks like release _itemEvents is not only not needed, but causes exceptions.
|
||||
// If that is really the case, this doesn't need to be a ComWrapper
|
||||
_item.Dispose();
|
||||
}
|
||||
|
||||
private void HookEvents(bool add)
|
||||
{
|
||||
if (add)
|
||||
using (IItemEvents events = _item.GetEvents())
|
||||
{
|
||||
_item.Events.BeforeDelete += HandleBeforeDelete;
|
||||
_item.Events.Forward += HandleForward;
|
||||
_item.Events.Read += HandleRead;
|
||||
_item.Events.Reply += HandleReply;
|
||||
_item.Events.ReplyAll += HandleReplyAll;
|
||||
_item.Events.Unload += HandleUnload;
|
||||
_item.Events.Write += HandleWrite;
|
||||
}
|
||||
else
|
||||
{
|
||||
_item.Events.BeforeDelete -= HandleBeforeDelete;
|
||||
_item.Events.Forward -= HandleForward;
|
||||
_item.Events.Read -= HandleRead;
|
||||
_item.Events.Reply -= HandleReply;
|
||||
_item.Events.ReplyAll -= HandleReplyAll;
|
||||
_item.Events.Unload -= HandleUnload;
|
||||
_item.Events.Write -= HandleWrite;
|
||||
if (add)
|
||||
{
|
||||
|
||||
events.BeforeDelete += HandleBeforeDelete;
|
||||
events.Forward += HandleForward;
|
||||
events.Read += HandleRead;
|
||||
events.Reply += HandleReply;
|
||||
events.ReplyAll += HandleReplyAll;
|
||||
events.Unload += HandleUnload;
|
||||
events.Write += HandleWrite;
|
||||
}
|
||||
else
|
||||
{
|
||||
events.BeforeDelete -= HandleBeforeDelete;
|
||||
events.Forward -= HandleForward;
|
||||
events.Read -= HandleRead;
|
||||
events.Reply -= HandleReply;
|
||||
events.ReplyAll -= HandleReplyAll;
|
||||
events.Unload -= HandleUnload;
|
||||
events.Write -= HandleWrite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user