public bool Remove(string eventName, MessageHandlerAction <T> handler = null) { if (eventName.IsEmpty()) { return(false); } try { _lock.EnterWriteLock(); var key = eventName.ToLower(); if (_specificHandlers.ContainsKey(key)) { if (handler == null) { _specificHandlers.Remove(key); return(true); } else { return(_specificHandlers[key].Remove(handler)); } } else { return(false); } } finally { _lock.ExitWriteLock(); } }
public void Add(string eventName, MessageHandlerAction <T> handler) { try { _lock.EnterWriteLock(); List <MessageHandlerAction <T> > result; var key = eventName.ToLower(); if (_specificHandlers.TryGetValue(key, out result)) { if (result != null) { result.Add(handler); return; } } _specificHandlers[key] = new List <MessageHandlerAction <T> > { handler }; } finally { _lock.ExitWriteLock(); } }
public static void SafeHandle <T>(this MessageHandlerAction <T> handler, T message, ILogger logger) where T : IMessage { try { handler.Handle(message); } catch (Exception ex) { logger.Error("Error notifying subscriber", ex); } }
/// <summary>Remove handler from the collection.</summary> /// <param name="handler"></param> /// <returns>True if removed, false if not found.</returns> public bool Remove(MessageHandlerAction <T> handler) { try { _lock.EnterWriteLock(); return(_handlers.RemoveAll(x => x.Equals(handler)) > 0); } finally { _lock.ExitWriteLock(); } }
/// <summary>Add handler to the collection.</summary> /// <param name="handler"></param> public void Add(MessageHandlerAction <T> handler) { try { _lock.EnterWriteLock(); _handlers.Add(handler); } finally { _lock.ExitWriteLock(); } }