public void RemoveHandler(RoadEvent e, RoadEventHandler del) { try { this.m_lock.AcquireWriterLock(3000); try { WeakMulticastDelegate deleg = (WeakMulticastDelegate)this.m_events[e]; if (deleg != null) { deleg = WeakMulticastDelegate.Remove(deleg, del); if (deleg == null) { this.m_events.Remove(e); } else { this.m_events[e] = deleg; } } } finally { this.m_lock.ReleaseWriterLock(); } } catch (ApplicationException ex) { LogProvider.Default.Error("Failed to remove event handler!", ex); } }
public void RemoveHandler(RoadEvent e, RoadEventHandler del) { try { this.m_lock.AcquireWriterLock(3000); try { WeakMulticastDelegate weakMulticastDelegate = (WeakMulticastDelegate)this.m_events[e]; if (weakMulticastDelegate != null) { weakMulticastDelegate = WeakMulticastDelegate.Remove(weakMulticastDelegate, del); if (weakMulticastDelegate == null) { this.m_events.Remove(e); } else { this.m_events[e] = weakMulticastDelegate; } } } finally { this.m_lock.ReleaseWriterLock(); } } catch (ApplicationException exception) { if (RoadEventHandlerCollection.log.IsErrorEnabled) { RoadEventHandlerCollection.log.Error("Failed to remove event handler!", exception); } } }
public void AddHandlerUnique(RoadEvent e, RoadEventHandler del) { try { this.m_lock.AcquireWriterLock(3000); try { WeakMulticastDelegate deleg = (WeakMulticastDelegate)this.m_events[e]; if (deleg == null) { this.m_events[e] = new WeakMulticastDelegate(del); } else { this.m_events[e] = WeakMulticastDelegate.CombineUnique(deleg, del); } } finally { this.m_lock.ReleaseWriterLock(); } } catch (ApplicationException ex) { LogProvider.Default.Error("Failed to add event handler!", ex); } }
public static void RemoveHandler(object obj, RoadEvent e, RoadEventHandler del) { if (obj == null) { throw new ArgumentNullException("obj", "No object given!"); } if (e == null) { throw new ArgumentNullException("e", "No event type given!"); } if (del == null) { throw new ArgumentNullException("del", "No event handler given!"); } try { GameEventMgr.m_lock.AcquireReaderLock(3000); try { RoadEventHandlerCollection col = (RoadEventHandlerCollection)GameEventMgr.m_GameObjectEventCollections[obj]; if (col != null) { col.RemoveHandler(e, del); } } finally { GameEventMgr.m_lock.ReleaseReaderLock(); } } catch (ApplicationException ex) { LogProvider.Default.Error("Failed to remove local event handler!", ex); } }
/// <summary> /// Adds an event handler to the list, if it's already added do nothing /// </summary> /// <param name="e">The event from which we add a handler</param> /// <param name="del">The callback method</param> public void AddHandlerUnique(RoadEvent e, RoadEventHandler del) { try { m_lock.AcquireWriterLock(TIMEOUT); try { WeakMulticastDelegate deleg = (WeakMulticastDelegate)m_events[e]; if (deleg == null) { m_events[e] = new WeakMulticastDelegate(del); } else { m_events[e] = WeakMulticastDelegate.CombineUnique(deleg, del); } } finally { m_lock.ReleaseWriterLock(); } } catch (ApplicationException ex) { if (log.IsErrorEnabled) { log.Error("Failed to add event handler!", ex); } } }
/// <summary> /// Removes an event handler from the list /// </summary> /// <param name="e">The event from which to remove the handler</param> /// <param name="del">The callback method to remove</param> public void RemoveHandler(RoadEvent e, RoadEventHandler del) { try { m_lock.AcquireWriterLock(TIMEOUT); try { WeakMulticastDelegate deleg = (WeakMulticastDelegate)m_events[e]; if (deleg != null) { deleg = WeakMulticastDelegate.Remove(deleg, del); if (deleg == null) { m_events.Remove(e); } else { m_events[e] = deleg; } } } finally { m_lock.ReleaseWriterLock(); } } catch (ApplicationException ex) { if (log.IsErrorEnabled) { log.Error("Failed to remove event handler!", ex); } } }
/// <summary> /// Adds an event handler to the list /// </summary> /// <param name="e">The event from which we add a handler</param> /// <param name="del">The callback method</param> public void AddHandler(RoadEvent e, RoadEventHandler del) { try { m_lock.AcquireWriterLock(TIMEOUT); try { WeakMulticastDelegate deleg = (WeakMulticastDelegate)m_events[e]; if (deleg == null) { m_events[e] = new WeakMulticastDelegate(del); } else { m_events[e] = WeakMulticastDelegate.Combine(deleg, del); } } finally { m_lock.ReleaseWriterLock(); } } catch (ApplicationException ex) { if (log.IsErrorEnabled) log.Error("Failed to add event handler!", ex); } }
public void AddHandlerUnique(RoadEvent e, RoadEventHandler del) { try { this.m_lock.AcquireWriterLock(3000); try { WeakMulticastDelegate weakMulticastDelegate = (WeakMulticastDelegate)this.m_events[e]; if (weakMulticastDelegate == null) { this.m_events[e] = new WeakMulticastDelegate(del); } else { this.m_events[e] = WeakMulticastDelegate.CombineUnique(weakMulticastDelegate, del); } } finally { this.m_lock.ReleaseWriterLock(); } } catch (ApplicationException exception) { if (RoadEventHandlerCollection.log.IsErrorEnabled) { RoadEventHandlerCollection.log.Error("Failed to add event handler!", exception); } } }
private static void AddHandler(object obj, RoadEvent e, RoadEventHandler del, bool unique) { if (obj == null) { throw new ArgumentNullException("obj", "No object given!"); } if (e == null) { throw new ArgumentNullException("e", "No event type given!"); } if (del == null) { throw new ArgumentNullException("del", "No event handler given!"); } if (!e.IsValidFor(obj)) { throw new ArgumentException("Object is not valid for this event type", "obj"); } try { GameEventMgr.m_lock.AcquireReaderLock(3000); try { RoadEventHandlerCollection roadEventHandlerCollection = (RoadEventHandlerCollection)GameEventMgr.m_GameObjectEventCollections[obj]; if (roadEventHandlerCollection == null) { roadEventHandlerCollection = new RoadEventHandlerCollection(); LockCookie lockCookie = GameEventMgr.m_lock.UpgradeToWriterLock(3000); try { GameEventMgr.m_GameObjectEventCollections[obj] = roadEventHandlerCollection; } finally { GameEventMgr.m_lock.DowngradeFromWriterLock(ref lockCookie); } } if (unique) { roadEventHandlerCollection.AddHandlerUnique(e, del); } else { roadEventHandlerCollection.AddHandler(e, del); } } finally { GameEventMgr.m_lock.ReleaseReaderLock(); } } catch (ApplicationException exception) { if (GameEventMgr.log.IsErrorEnabled) { GameEventMgr.log.Error("Failed to add local event handler!", exception); } } }
public static void RemoveHandler(RoadEvent e, RoadEventHandler del) { if (e == null) { throw new ArgumentNullException("e", "No event type given!"); } if (del == null) { throw new ArgumentNullException("del", "No event handler given!"); } GameEventMgr.m_GlobalHandlerCollection.RemoveHandler(e, del); }
private static void AddHandler(RoadEvent e, RoadEventHandler del, bool unique) { if (e == null) { throw new ArgumentNullException("e", "No event type given!"); } if (del == null) { throw new ArgumentNullException("del", "No event handler given!"); } if (unique) { GameEventMgr.m_GlobalHandlerCollection.AddHandlerUnique(e, del); return; } GameEventMgr.m_GlobalHandlerCollection.AddHandler(e, del); }
/// <summary> /// Removes a single event handler from an object. /// You need to have registered the event before being /// able to remove it. /// </summary> /// <param name="obj">The object that needs to be the sender of events</param> /// <param name="e">The event type from which to deregister</param> /// <param name="del">The event handler to deregister for this event type</param> /// <exception cref="ArgumentNullException">If one of the parameters is null</exception> public static void RemoveHandler(object obj, RoadEvent e, RoadEventHandler del) { //Test the parameters if (obj == null) { throw new ArgumentNullException("obj", "No object given!"); } if (e == null) { throw new ArgumentNullException("e", "No event type given!"); } if (del == null) { throw new ArgumentNullException("del", "No event handler given!"); } try { m_lock.AcquireReaderLock(TIMEOUT); try { RoadEventHandlerCollection col = (RoadEventHandlerCollection)m_GameObjectEventCollections[obj]; if (col != null) { col.RemoveHandler(e, del); } } finally { m_lock.ReleaseReaderLock(); } } catch (ApplicationException ex) { if (log.IsErrorEnabled) { log.Error("Failed to remove local event handler!", ex); } } }
public static void RemoveHandler(object obj, RoadEvent e, RoadEventHandler del) { if (obj == null) { throw new ArgumentNullException("obj", "No object given!"); } if (e == null) { throw new ArgumentNullException("e", "No event type given!"); } if (del == null) { throw new ArgumentNullException("del", "No event handler given!"); } try { GameEventMgr.m_lock.AcquireReaderLock(3000); try { RoadEventHandlerCollection roadEventHandlerCollection = (RoadEventHandlerCollection)GameEventMgr.m_GameObjectEventCollections[obj]; if (roadEventHandlerCollection != null) { roadEventHandlerCollection.RemoveHandler(e, del); } } finally { GameEventMgr.m_lock.ReleaseReaderLock(); } } catch (ApplicationException exception) { if (GameEventMgr.log.IsErrorEnabled) { GameEventMgr.log.Error("Failed to remove local event handler!", exception); } } }
/// <summary> /// Registers a single global event handler. /// The global event handlers will be called for ALL events, /// so use them wisely, they might incure a big performance /// hit if used unwisely. /// If an equal handler has already been added, nothing will be done /// </summary> /// <param name="e">The event type to register for</param> /// <param name="del">The event handler to register for this event type</param> /// <exception cref="ArgumentNullException">If one of the parameters is null</exception> public static void AddHandlerUnique(RoadEvent e, RoadEventHandler del) { AddHandler(e, del, true); }
/// <summary> /// Registers a single local event handler. /// Local event handlers will only be called if the /// "sender" parameter in the Notify method equals /// the object for which a local event handler was /// registered. /// </summary> /// <remarks> /// Certain events will never have a local event handler. /// This happens if the Notify method is called without /// a sender parameter for example! /// </remarks> /// <param name="obj">The object that needs to be the sender of events</param> /// <param name="e">The event type to register for</param> /// <param name="del">The event handler to register for this event type</param> /// <exception cref="ArgumentNullException">If one of the parameters is null</exception> public static void AddHandler(object obj, RoadEvent e, RoadEventHandler del) { AddHandler(obj, e, del, false); }
/// <summary> /// Registers a single global event handler. /// The global event handlers will be called for ALL events, /// so use them wisely, they might incure a big performance /// hit if used unwisely. /// </summary> /// <param name="e">The event type to register for</param> /// <param name="del">The event handler to register for this event type</param> /// <exception cref="ArgumentNullException">If one of the parameters is null</exception> public static void AddHandler(RoadEvent e, RoadEventHandler del) { AddHandler(e, del, false); }
/// <summary> /// Registers a single local event handler. /// Local event handlers will only be called if the /// "sender" parameter in the Notify method equals /// the object for which a local event handler was /// registered. /// </summary> /// <remarks> /// Certain events will never have a local event handler. /// This happens if the Notify method is called without /// a sender parameter for example! /// </remarks> /// <param name="obj">The object that needs to be the sender of events</param> /// <param name="e">The event type to register for</param> /// <param name="del">The event handler to register for this event type</param> /// <param name="unique">Flag wether event shall be added unique or not</param> /// <exception cref="ArgumentNullException">If one of the parameters is null</exception> private static void AddHandler(object obj, RoadEvent e, RoadEventHandler del, bool unique) { //Test the parameters if (obj == null) throw new ArgumentNullException("obj", "No object given!"); if (e == null) throw new ArgumentNullException("e", "No event type given!"); if (del == null) throw new ArgumentNullException("del", "No event handler given!"); if (!e.IsValidFor(obj)) throw new ArgumentException("Object is not valid for this event type", "obj"); try { m_lock.AcquireReaderLock(TIMEOUT); try { RoadEventHandlerCollection col = (RoadEventHandlerCollection)m_GameObjectEventCollections[obj]; if (col == null) { col = new RoadEventHandlerCollection(); LockCookie lc = m_lock.UpgradeToWriterLock(TIMEOUT); try { m_GameObjectEventCollections[obj] = col; } finally { m_lock.DowngradeFromWriterLock(ref lc); } } if (unique) col.AddHandlerUnique(e, del); else col.AddHandler(e, del); } finally { m_lock.ReleaseReaderLock(); } } catch (ApplicationException ex) { if (log.IsErrorEnabled) log.Error("Failed to add local event handler!", ex); } }
/// <summary> /// Registers a single global event handler. /// The global event handlers will be called for ALL events, /// so use them wisely, they might incure a big performance /// hit if used unwisely. /// </summary> /// <param name="e">The event type to register for</param> /// <param name="del">The event handler to register for this event type</param> /// <param name="unique">Flag wether event shall be added unique or not</param> /// <exception cref="ArgumentNullException">If one of the parameters is null</exception> private static void AddHandler(RoadEvent e, RoadEventHandler del, bool unique) { if (e == null) throw new ArgumentNullException("e", "No event type given!"); if (del == null) throw new ArgumentNullException("del", "No event handler given!"); if (unique) m_GlobalHandlerCollection.AddHandlerUnique(e, del); else m_GlobalHandlerCollection.AddHandler(e, del); }
/// <summary> /// Removes a single event handler from an object. /// You need to have registered the event before being /// able to remove it. /// </summary> /// <param name="obj">The object that needs to be the sender of events</param> /// <param name="e">The event type from which to deregister</param> /// <param name="del">The event handler to deregister for this event type</param> /// <exception cref="ArgumentNullException">If one of the parameters is null</exception> public static void RemoveHandler(object obj, RoadEvent e, RoadEventHandler del) { //Test the parameters if (obj == null) throw new ArgumentNullException("obj", "No object given!"); if (e == null) throw new ArgumentNullException("e", "No event type given!"); if (del == null) throw new ArgumentNullException("del", "No event handler given!"); try { m_lock.AcquireReaderLock(TIMEOUT); try { RoadEventHandlerCollection col = (RoadEventHandlerCollection)m_GameObjectEventCollections[obj]; if (col != null) col.RemoveHandler(e, del); } finally { m_lock.ReleaseReaderLock(); } } catch (ApplicationException ex) { if (log.IsErrorEnabled) log.Error("Failed to remove local event handler!", ex); } }
/// <summary> /// Removes a global event handler. /// You need to have registered the event before being able to remove it. /// </summary> /// <param name="e">The event type from which to deregister</param> /// <param name="del">The event handler to deregister for this event type</param> /// <exception cref="ArgumentNullException">If one of the parameters is null</exception> public static void RemoveHandler(RoadEvent e, RoadEventHandler del) { //Test the parameters if (e == null) throw new ArgumentNullException("e", "No event type given!"); if (del == null) throw new ArgumentNullException("del", "No event handler given!"); m_GlobalHandlerCollection.RemoveHandler(e, del); }
/// <summary> /// Registers a single local event handler. /// Local event handlers will only be called if the /// "sender" parameter in the Notify method equals /// the object for which a local event handler was /// registered. /// If a equal handler has already been added, nothin will be done /// </summary> /// <remarks> /// Certain events will never have a local event handler. /// This happens if the Notify method is called without /// a sender parameter for example! /// </remarks> /// <param name="obj">The object that needs to be the sender of events</param> /// <param name="e">The event type to register for</param> /// <param name="del">The event handler to register for this event type</param> /// <exception cref="ArgumentNullException">If one of the parameters is null</exception> public static void AddHandlerUnique(object obj, RoadEvent e, RoadEventHandler del) { AddHandler(obj, e, del, true); }
public static void AddHandlerUnique(object obj, RoadEvent e, RoadEventHandler del) { GameEventMgr.AddHandler(obj, e, del, true); }
public static void AddHandler(object obj, RoadEvent e, RoadEventHandler del) { GameEventMgr.AddHandler(obj, e, del, false); }
/// <summary> /// Registers a single local event handler. /// Local event handlers will only be called if the /// "sender" parameter in the Notify method equals /// the object for which a local event handler was /// registered. /// </summary> /// <remarks> /// Certain events will never have a local event handler. /// This happens if the Notify method is called without /// a sender parameter for example! /// </remarks> /// <param name="obj">The object that needs to be the sender of events</param> /// <param name="e">The event type to register for</param> /// <param name="del">The event handler to register for this event type</param> /// <param name="unique">Flag wether event shall be added unique or not</param> /// <exception cref="ArgumentNullException">If one of the parameters is null</exception> private static void AddHandler(object obj, RoadEvent e, RoadEventHandler del, bool unique) { //Test the parameters if (obj == null) { throw new ArgumentNullException("obj", "No object given!"); } if (e == null) { throw new ArgumentNullException("e", "No event type given!"); } if (del == null) { throw new ArgumentNullException("del", "No event handler given!"); } if (!e.IsValidFor(obj)) { throw new ArgumentException("Object is not valid for this event type", "obj"); } try { m_lock.AcquireReaderLock(TIMEOUT); try { RoadEventHandlerCollection col = (RoadEventHandlerCollection)m_GameObjectEventCollections[obj]; if (col == null) { col = new RoadEventHandlerCollection(); LockCookie lc = m_lock.UpgradeToWriterLock(TIMEOUT); try { m_GameObjectEventCollections[obj] = col; } finally { m_lock.DowngradeFromWriterLock(ref lc); } } if (unique) { col.AddHandlerUnique(e, del); } else { col.AddHandler(e, del); } } finally { m_lock.ReleaseReaderLock(); } } catch (ApplicationException ex) { if (log.IsErrorEnabled) { log.Error("Failed to add local event handler!", ex); } } }
/// <summary> /// Removes an event handler from the list /// </summary> /// <param name="e">The event from which to remove the handler</param> /// <param name="del">The callback method to remove</param> public void RemoveHandler(RoadEvent e, RoadEventHandler del) { try { m_lock.AcquireWriterLock(TIMEOUT); try { WeakMulticastDelegate deleg = (WeakMulticastDelegate)m_events[e]; if (deleg != null) { deleg = WeakMulticastDelegate.Remove(deleg, del); if (deleg == null) m_events.Remove(e); else m_events[e] = deleg; } } finally { m_lock.ReleaseWriterLock(); } } catch (ApplicationException ex) { if (log.IsErrorEnabled) log.Error("Failed to remove event handler!", ex); } }