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

[KOE-130] Cleanup and fixes for disabling wrapper tracing

This commit is contained in:
Patrick Simpson 2017-07-05 17:33:17 +02:00
parent f2b80da909
commit 0d42105f93
2 changed files with 41 additions and 31 deletions

View File

@ -74,6 +74,9 @@ namespace Acacia.Features.DebugSupport
private void RefreshWrappers() private void RefreshWrappers()
{ {
if (_tracer == null)
return;
// Wrapper types // Wrapper types
listWrapperTypes.Items.Clear(); listWrapperTypes.Items.Clear();
foreach(KeyValuePair<Type, int> type in _tracer.GetTypes()) foreach(KeyValuePair<Type, int> type in _tracer.GetTypes())
@ -146,6 +149,9 @@ namespace Acacia.Features.DebugSupport
private void RefreshItemEvents() private void RefreshItemEvents()
{ {
if (_tracer == null)
return;
listItemEvents.Items.Clear(); listItemEvents.Items.Clear();
foreach(MailEvents.MailEventDebug events in MailEvents.MailEventsDebug) foreach(MailEvents.MailEventDebug events in MailEvents.MailEventsDebug)
{ {

View File

@ -386,10 +386,11 @@ namespace Acacia.Utils
public static IEnumerable<MailEventDebug> MailEventsDebug public static IEnumerable<MailEventDebug> MailEventsDebug
{ {
get { return _hookers.Values; } get { return _hookers?.Values; }
} }
private static readonly ConcurrentDictionary<int, MailEventDebugImpl> _hookers = new ConcurrentDictionary<int, MailEventDebugImpl>(); private static readonly ConcurrentDictionary<int, MailEventDebugImpl> _hookers =
GlobalOptions.INSTANCE.WrapperTrace ? new ConcurrentDictionary<int, MailEventDebugImpl>() : null;
private static int _nextHookerId; private static int _nextHookerId;
private class MailEventHooker : DisposableWrapper private class MailEventHooker : DisposableWrapper
@ -400,8 +401,11 @@ namespace Acacia.Utils
public MailEventHooker(IItem item, MailEvents events) public MailEventHooker(IItem item, MailEvents events)
{ {
_debug = new MailEventDebugImpl(Interlocked.Increment(ref _nextHookerId)); if (_hookers != null)
_hookers.TryAdd(_debug._id, _debug); {
_debug = new MailEventDebugImpl(Interlocked.Increment(ref _nextHookerId));
_hookers.TryAdd(_debug._id, _debug);
}
this._item = item; this._item = item;
this._events = events; this._events = events;
@ -412,17 +416,21 @@ namespace Acacia.Utils
{ {
if (_item != null) if (_item != null)
{ {
_debug.RecordEvent(DebugEvent.Dispose);
_item.Dispose(); _item.Dispose();
_item = null; _item = null;
} }
MailEventDebugImpl dummy;
_hookers.TryRemove(_debug._id, out dummy); if (_debug != null)
{
_debug.RecordEvent(DebugEvent.Dispose);
MailEventDebugImpl dummy;
_hookers.TryRemove(_debug._id, out dummy);
}
} }
~MailEventHooker() ~MailEventHooker()
{ {
_debug.RecordEvent(DebugEvent.GC); _debug?.RecordEvent(DebugEvent.GC);
} }
private void HookEvents(bool add) private void HookEvents(bool add)
@ -456,52 +464,48 @@ namespace Acacia.Utils
private void HandleBeforeDelete(object item, ref bool cancel) private void HandleBeforeDelete(object item, ref bool cancel)
{ {
_debug.RecordEvent(DebugEvent.BeforeDelete); _debug?.RecordEvent(DebugEvent.BeforeDelete);
//using (IItem wrapped = item.WrapOrDefault<IItem>(false)) using (IItem wrapped = item.WrapOrDefault<IItem>(false))
// _events.OnBeforeDelete(wrapped, ref cancel); _events.OnBeforeDelete(wrapped, ref cancel);
} }
private void HandleForward(object response, ref bool cancel) private void HandleForward(object response, ref bool cancel)
{ {
_debug.RecordEvent(DebugEvent.Forward); _debug?.RecordEvent(DebugEvent.Forward);
//using (IItem wrapped = response.WrapOrDefault<IItem>(false)) using (IItem wrapped = response.WrapOrDefault<IItem>(false))
// _events.OnForward(_item as IMailItem, wrapped as IMailItem); _events.OnForward(_item as IMailItem, wrapped as IMailItem);
} }
private void HandlePropertyChange(string name) private void HandlePropertyChange(string name)
{ {
_debug.RecordEvent(DebugEvent.PropertyChange); _debug?.RecordEvent(DebugEvent.PropertyChange);
//_events.OnPropertyChange(_item, name); _events.OnPropertyChange(_item, name);
} }
private void HandleRead() private void HandleRead()
{ {
_debug.RecordEvent(DebugEvent.Read); _debug?.RecordEvent(DebugEvent.Read);
// TODO: should this not be simply an IItem? // TODO: should this not be simply an IItem?
IMailItem mail = _item as IMailItem; _events.OnRead(_item as IMailItem);
if (mail != null)
{
_events.OnRead(mail);
}
} }
private void HandleReply(object response, ref bool cancel) private void HandleReply(object response, ref bool cancel)
{ {
_debug.RecordEvent(DebugEvent.Reply); _debug?.RecordEvent(DebugEvent.Reply);
//using (IItem wrapped = response.WrapOrDefault<IItem>(false)) using (IItem wrapped = response.WrapOrDefault<IItem>(false))
// _events.OnReply(_item as IMailItem, wrapped as IMailItem); _events.OnReply(_item as IMailItem, wrapped as IMailItem);
} }
private void HandleReplyAll(object response, ref bool cancel) private void HandleReplyAll(object response, ref bool cancel)
{ {
_debug.RecordEvent(DebugEvent.ReplyAll); _debug?.RecordEvent(DebugEvent.ReplyAll);
//using (IItem wrapped = response.WrapOrDefault<IItem>(false)) using (IItem wrapped = response.WrapOrDefault<IItem>(false))
// _events.OnReplyAll(_item as IMailItem, wrapped as IMailItem); _events.OnReplyAll(_item as IMailItem, wrapped as IMailItem);
} }
private void HandleUnload() private void HandleUnload()
{ {
_debug.RecordEvent(DebugEvent.Unload); _debug?.RecordEvent(DebugEvent.Unload);
// All events must be unhooked on unload, otherwise a resource leak is created. // All events must be unhooked on unload, otherwise a resource leak is created.
HookEvents(false); HookEvents(false);
Dispose(); Dispose();
@ -509,8 +513,8 @@ namespace Acacia.Utils
private void HandleWrite(ref bool cancel) private void HandleWrite(ref bool cancel)
{ {
_debug.RecordEvent(DebugEvent.Write); _debug?.RecordEvent(DebugEvent.Write);
//_events.OnWrite(_item, ref cancel); _events.OnWrite(_item, ref cancel);
} }
} }