Пример #1
0
 public static void RemoveAllHandlers(RoadEvent e, bool deep)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e", "No event type given!");
     }
     if (deep)
     {
         try
         {
             GameEventMgr.m_lock.AcquireReaderLock(3000);
             try
             {
                 foreach (RoadEventHandlerCollection col in GameEventMgr.m_GameObjectEventCollections.Values)
                 {
                     col.RemoveAllHandlers(e);
                 }
             }
             finally
             {
                 GameEventMgr.m_lock.ReleaseReaderLock();
             }
         }
         catch (ApplicationException ex)
         {
             LogProvider.Default.Error("Failed to add local event handlers!", ex);
         }
     }
     GameEventMgr.m_GlobalHandlerCollection.RemoveAllHandlers(e);
 }
Пример #2
0
 public static void Notify(RoadEvent e, object sender, EventArgs eArgs)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e", "No event type given!");
     }
     if (sender != null)
     {
         try
         {
             RoadEventHandlerCollection roadEventHandlerCollection = null;
             GameEventMgr.m_lock.AcquireReaderLock(3000);
             try
             {
                 roadEventHandlerCollection = (RoadEventHandlerCollection)GameEventMgr.m_GameObjectEventCollections[sender];
             }
             finally
             {
                 GameEventMgr.m_lock.ReleaseReaderLock();
             }
             if (roadEventHandlerCollection != null)
             {
                 roadEventHandlerCollection.Notify(e, sender, eArgs);
             }
         }
         catch (ApplicationException exception)
         {
             if (GameEventMgr.log.IsErrorEnabled)
             {
                 GameEventMgr.log.Error("Failed to notify local event handler!", exception);
             }
         }
     }
     GameEventMgr.m_GlobalHandlerCollection.Notify(e, sender, eArgs);
 }
Пример #3
0
        /// <summary>
        /// Removes all global event handlers for a specific event type
        /// </summary>
        /// <param name="e">The event type from which to deregister all handlers</param>
        /// <param name="deep">Specifies if all local registered event handlers
        /// should be removed as well.</param>
        /// <exception cref="ArgumentNullException">If no event type given</exception>
        public static void RemoveAllHandlers(RoadEvent e, bool deep)
        {
            //Test the parameters
            if (e == null)
            {
                throw new ArgumentNullException("e", "No event type given!");
            }

            if (deep)
            {
                try
                {
                    m_lock.AcquireReaderLock(TIMEOUT);
                    try
                    {
                        foreach (RoadEventHandlerCollection col in m_GameObjectEventCollections.Values)
                        {
                            col.RemoveAllHandlers(e);
                        }
                    }
                    finally
                    {
                        m_lock.ReleaseReaderLock();
                    }
                }
                catch (ApplicationException ex)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("Failed to add local event handlers!", ex);
                    }
                }
            }
            m_GlobalHandlerCollection.RemoveAllHandlers(e);
        }
Пример #4
0
 public static void RemoveAllHandlers(object obj, RoadEvent e)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("obj", "No object given!");
     }
     if (e == null)
     {
         throw new ArgumentNullException("e", "No event type given!");
     }
     try
     {
         GameEventMgr.m_lock.AcquireReaderLock(3000);
         try
         {
             RoadEventHandlerCollection col = (RoadEventHandlerCollection)GameEventMgr.m_GameObjectEventCollections[obj];
             if (col != null)
             {
                 col.RemoveAllHandlers(e);
             }
         }
         finally
         {
             GameEventMgr.m_lock.ReleaseReaderLock();
         }
     }
     catch (ApplicationException ex)
     {
         LogProvider.Default.Error("Failed to remove local event handlers!", 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);
     }
 }
Пример #6
0
 public static void Notify(RoadEvent e, object sender, EventArgs eArgs)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e", "No event type given!");
     }
     if (sender != null)
     {
         try
         {
             RoadEventHandlerCollection col = null;
             GameEventMgr.m_lock.AcquireReaderLock(3000);
             try
             {
                 col = (RoadEventHandlerCollection)GameEventMgr.m_GameObjectEventCollections[sender];
             }
             finally
             {
                 GameEventMgr.m_lock.ReleaseReaderLock();
             }
             if (col != null)
             {
                 col.Notify(e, sender, eArgs);
             }
         }
         catch (ApplicationException ex)
         {
             LogProvider.Default.Error("Failed to notify local event handler!", ex);
         }
     }
     GameEventMgr.m_GlobalHandlerCollection.Notify(e, sender, eArgs);
 }
Пример #7
0
 /// <summary>
 /// Notifies all registered event handlers of the occurance of an event!
 /// </summary>
 /// <param name="e">The event that occured</param>
 /// <param name="sender">The sender of this event</param>
 /// <param name="eArgs">The event arguments</param>
 /// <remarks>Overwrite the EventArgs class to set own arguments</remarks>
 public void Notify(RoadEvent e, object sender, EventArgs eArgs)
 {
     try
     {
         m_lock.AcquireReaderLock(TIMEOUT);
         WeakMulticastDelegate eventDelegate;
         try
         {
             eventDelegate = (WeakMulticastDelegate)m_events[e];
         }
         finally
         {
             m_lock.ReleaseReaderLock();
         }
         if (eventDelegate == null)
         {
             return;
         }
         eventDelegate.InvokeSafe(new object[] { e, sender, eArgs });
     }
     catch (ApplicationException ex)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Failed to notify event handler!", ex);
         }
     }
 }
Пример #8
0
 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);
     }
 }
Пример #9
0
 /// <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);
         }
     }
 }
Пример #10
0
 public static void OnScriptCompiled(RoadEvent ev, object sender, EventArgs args)
 {
     handles.Clear();
     int count = SearchSpellHandlers(Assembly.GetAssembly(typeof(GameServer)));
     if (log.IsInfoEnabled)
         log.Info("SpellMgr: Loaded " + count + " spell handlers from GameServer Assembly!");
 }
Пример #11
0
 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);
         }
     }
 }
Пример #12
0
 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);
         }
     }
 }
Пример #13
0
 public void Notify(RoadEvent e, object sender, EventArgs eArgs)
 {
     try
     {
         this.m_lock.AcquireReaderLock(3000);
         WeakMulticastDelegate weakMulticastDelegate;
         try
         {
             weakMulticastDelegate = (WeakMulticastDelegate)this.m_events[e];
         }
         finally
         {
             this.m_lock.ReleaseReaderLock();
         }
         if (weakMulticastDelegate != null)
         {
             weakMulticastDelegate.InvokeSafe(new object[]
             {
                 e,
                 sender,
                 eArgs
             });
         }
     }
     catch (ApplicationException exception)
     {
         if (RoadEventHandlerCollection.log.IsErrorEnabled)
         {
             RoadEventHandlerCollection.log.Error("Failed to notify event handler!", exception);
         }
     }
 }
Пример #14
0
 public void Notify(RoadEvent e, object sender, EventArgs eArgs)
 {
     try
     {
         this.m_lock.AcquireReaderLock(3000);
         WeakMulticastDelegate eventDelegate;
         try
         {
             eventDelegate = (WeakMulticastDelegate)this.m_events[e];
         }
         finally
         {
             this.m_lock.ReleaseReaderLock();
         }
         if (eventDelegate != null)
         {
             eventDelegate.InvokeSafe(new object[]
             {
                 e,
                 sender,
                 eArgs
             });
         }
     }
     catch (ApplicationException ex)
     {
         LogProvider.Default.Error("Failed to notify event handler!", ex);
     }
 }
Пример #15
0
 /// <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);
         }
     }
 }
Пример #16
0
 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);
     }
 }
Пример #17
0
        /// <summary>
        /// Registers some global events that are specified by attributes
        /// </summary>
        /// <param name="asm">The assembly to search through</param>
        /// <param name="attribute">The custom attribute to search for</param>
        /// <param name="e">The event to register in case the custom attribute is found</param>
        /// <exception cref="ArgumentNullException">If one of the parameters is null</exception>
        public static void RegisterGlobalEvents(Assembly asm, Type attribute, RoadEvent e)
        {
            if (asm == null)
                throw new ArgumentNullException("asm", "No assembly given to search for global event handlers!");
            if (attribute == null)
                throw new ArgumentNullException("attribute", "No attribute given!");
            if (e == null)
                throw new ArgumentNullException("e", "No event type given!");


            foreach (Type type in asm.GetTypes())
            {
                if (!type.IsClass) continue;
                foreach (MethodInfo mInfo in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
                {
                    object[] myAttribs = mInfo.GetCustomAttributes(attribute, false);
                    if (myAttribs.Length != 0)
                    {
                        try
                        {
                            m_GlobalHandlerCollection.AddHandler(e, (RoadEventHandler)Delegate.CreateDelegate(typeof(RoadEventHandler), mInfo));
                        }
                        catch (Exception ex)
                        {
                            if (log.IsErrorEnabled)
                                log.Error("Error registering global event. Method: " + type.FullName + "." + mInfo.Name, ex);
                        }
                    }
                }
            }
        }
Пример #18
0
 public static void RemoveAllHandlers(object obj, RoadEvent e)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("obj", "No object given!");
     }
     if (e == null)
     {
         throw new ArgumentNullException("e", "No event type given!");
     }
     try
     {
         GameEventMgr.m_lock.AcquireReaderLock(3000);
         try
         {
             RoadEventHandlerCollection roadEventHandlerCollection = (RoadEventHandlerCollection)GameEventMgr.m_GameObjectEventCollections[obj];
             if (roadEventHandlerCollection != null)
             {
                 roadEventHandlerCollection.RemoveAllHandlers(e);
             }
         }
         finally
         {
             GameEventMgr.m_lock.ReleaseReaderLock();
         }
     }
     catch (ApplicationException exception)
     {
         if (GameEventMgr.log.IsErrorEnabled)
         {
             GameEventMgr.log.Error("Failed to remove local event handlers!", exception);
         }
     }
 }
Пример #19
0
 public static void OnScriptCompiled(RoadEvent ev, object sender, EventArgs args)
 {
     Array.Clear(m_packetHandlers, 0, m_packetHandlers.Length);
     int count = SearchPacketHandlers("v168", Assembly.GetAssembly(typeof(GameServer)));
     if (log.IsInfoEnabled)
         log.Info("PacketProcessor: Loaded " + count + " handlers from GameServer Assembly!");
 }
Пример #20
0
 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);
         }
     }
 }
Пример #21
0
        public static void OnScriptCompiled(RoadEvent ev, object sender, EventArgs args)
        {
            Array.Clear(_gameProcessors, 0, _gameProcessors.Length);

            int count = SearchGameProcessors(typeof(GameServer).Assembly);

            if (log.IsInfoEnabled)
                log.Info(string.Format("GameProcessor: Loaded {0} processors!",count));
        }
Пример #22
0
 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);
 }
Пример #23
0
 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);
 }
Пример #24
0
 public void RemoveAllHandlers(RoadEvent e)
 {
     try
     {
         this.m_lock.AcquireWriterLock(3000);
         try
         {
             this.m_events.Remove(e);
         }
         finally
         {
             this.m_lock.ReleaseWriterLock();
         }
     }
     catch (ApplicationException ex)
     {
         LogProvider.Default.Error("Failed to remove event handlers!", ex);
     }
 }
Пример #25
0
 public static void RegisterGlobalEvents(Assembly asm, Type attribute, RoadEvent e)
 {
     if (asm == null)
     {
         throw new ArgumentNullException("asm", "No assembly given to search for global event handlers!");
     }
     if (attribute == null)
     {
         throw new ArgumentNullException("attribute", "No attribute given!");
     }
     if (e == null)
     {
         throw new ArgumentNullException("e", "No event type given!");
     }
     Type[] types = asm.GetTypes();
     for (int i = 0; i < types.Length; i++)
     {
         Type type = types[i];
         if (type.IsClass)
         {
             MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public);
             for (int j = 0; j < methods.Length; j++)
             {
                 MethodInfo methodInfo       = methods[j];
                 object[]   customAttributes = methodInfo.GetCustomAttributes(attribute, false);
                 if (customAttributes.Length != 0)
                 {
                     try
                     {
                         GameEventMgr.m_GlobalHandlerCollection.AddHandler(e, (RoadEventHandler)Delegate.CreateDelegate(typeof(RoadEventHandler), methodInfo));
                     }
                     catch (Exception exception)
                     {
                         if (GameEventMgr.log.IsErrorEnabled)
                         {
                             GameEventMgr.log.Error("Error registering global event. Method: " + type.FullName + "." + methodInfo.Name, exception);
                         }
                     }
                 }
             }
         }
     }
 }
Пример #26
0
        /// <summary>
        /// Registers some global events that are specified by attributes
        /// </summary>
        /// <param name="asm">The assembly to search through</param>
        /// <param name="attribute">The custom attribute to search for</param>
        /// <param name="e">The event to register in case the custom attribute is found</param>
        /// <exception cref="ArgumentNullException">If one of the parameters is null</exception>
        public static void RegisterGlobalEvents(Assembly asm, Type attribute, RoadEvent e)
        {
            if (asm == null)
            {
                throw new ArgumentNullException("asm", "No assembly given to search for global event handlers!");
            }
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute", "No attribute given!");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e", "No event type given!");
            }


            foreach (Type type in asm.GetTypes())
            {
                if (!type.IsClass)
                {
                    continue;
                }
                foreach (MethodInfo mInfo in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
                {
                    object[] myAttribs = mInfo.GetCustomAttributes(attribute, false);
                    if (myAttribs.Length != 0)
                    {
                        try
                        {
                            m_GlobalHandlerCollection.AddHandler(e, (RoadEventHandler)Delegate.CreateDelegate(typeof(RoadEventHandler), mInfo));
                        }
                        catch (Exception ex)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("Error registering global event. Method: " + type.FullName + "." + mInfo.Name, ex);
                            }
                        }
                    }
                }
            }
        }
Пример #27
0
        /// <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);
                }
            }
        }
Пример #28
0
 public void RemoveAllHandlers(RoadEvent e)
 {
     try
     {
         this.m_lock.AcquireWriterLock(3000);
         try
         {
             this.m_events.Remove(e);
         }
         finally
         {
             this.m_lock.ReleaseWriterLock();
         }
     }
     catch (ApplicationException exception)
     {
         if (RoadEventHandlerCollection.log.IsErrorEnabled)
         {
             RoadEventHandlerCollection.log.Error("Failed to remove event handlers!", exception);
         }
     }
 }
Пример #29
0
        /// <summary>
        /// Notifies all global and local event handlers of the occurance
        /// of a specific event type with some event arguments!
        /// </summary>
        /// <param name="e">The event type that occured</param>
        /// <param name="sender">The sender of this event</param>
        /// <param name="eArgs">The event arguments</param>
        /// <exception cref="ArgumentNullException">If no event type given</exception>
        /// <remarks>Overwrite the EventArgs class to set own arguments</remarks>
        public static void Notify(RoadEvent e, object sender, EventArgs eArgs)
        {
            //Test the parameters
            if (e == null)
            {
                throw new ArgumentNullException("e", "No event type given!");
            }

            //Notify the local event handlers first
            if (sender != null)
            {
                try
                {
                    RoadEventHandlerCollection col = null;
                    m_lock.AcquireReaderLock(TIMEOUT);
                    try
                    {
                        col = (RoadEventHandlerCollection)m_GameObjectEventCollections[sender];
                    }
                    finally
                    {
                        m_lock.ReleaseReaderLock();
                    }
                    if (col != null)
                    {
                        col.Notify(e, sender, eArgs);
                    }
                }
                catch (ApplicationException ex)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("Failed to notify local event handler!", ex);
                    }
                }
            }
            //Notify the global ones later
            m_GlobalHandlerCollection.Notify(e, sender, eArgs);
        }
Пример #30
0
 /// <summary>
 /// Removes all callback handlers for a given event
 /// </summary>
 /// <param name="e">The event from which to remove all handlers</param>
 public void RemoveAllHandlers(RoadEvent e)
 {
     try
     {
         m_lock.AcquireWriterLock(TIMEOUT);
         try
         {
             m_events.Remove(e);
         }
         finally
         {
             m_lock.ReleaseWriterLock();
         }
     }
     catch (ApplicationException ex)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Failed to remove event handlers!", ex);
         }
     }
 }
Пример #31
0
 /// <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);
 }
Пример #32
0
        /// <summary>
        /// Removes all global event handlers for a specific event type
        /// </summary>
        /// <param name="e">The event type from which to deregister all handlers</param>
        /// <param name="deep">Specifies if all local registered event handlers
        /// should be removed as well.</param>
        /// <exception cref="ArgumentNullException">If no event type given</exception>
        public static void RemoveAllHandlers(RoadEvent e, bool deep)
        {
            //Test the parameters
            if (e == null)
                throw new ArgumentNullException("e", "No event type given!");

            if (deep)
            {
                try
                {
                    m_lock.AcquireReaderLock(TIMEOUT);
                    try
                    {
                        foreach (RoadEventHandlerCollection col in m_GameObjectEventCollections.Values)
                            col.RemoveAllHandlers(e);
                    }
                    finally
                    {
                        m_lock.ReleaseReaderLock();
                    }
                }
                catch (ApplicationException ex)
                {
                    if (log.IsErrorEnabled)
                        log.Error("Failed to add local event handlers!", ex);
                }
            }
            m_GlobalHandlerCollection.RemoveAllHandlers(e);
        }
Пример #33
0
        /// <summary>
        /// Notifies all global and local event handlers of the occurance 
        /// of a specific event type with some event arguments!
        /// </summary>
        /// <param name="e">The event type that occured</param>
        /// <param name="sender">The sender of this event</param>
        /// <param name="eArgs">The event arguments</param>
        /// <exception cref="ArgumentNullException">If no event type given</exception>
        /// <remarks>Overwrite the EventArgs class to set own arguments</remarks>
        public static void Notify(RoadEvent e, object sender, EventArgs eArgs)
        {
            //Test the parameters
            if (e == null)
                throw new ArgumentNullException("e", "No event type given!");

            //Notify the local event handlers first
            if (sender != null)
            {
                try
                {
                    RoadEventHandlerCollection col = null;
                    m_lock.AcquireReaderLock(TIMEOUT);
                    try
                    {
                        col = (RoadEventHandlerCollection)m_GameObjectEventCollections[sender];
                    }
                    finally
                    {
                        m_lock.ReleaseReaderLock();
                    }
                    if (col != null)
                        col.Notify(e, sender, eArgs);
                }
                catch (ApplicationException ex)
                {
                    if (log.IsErrorEnabled)
                        log.Error("Failed to notify local event handler!", ex);
                }
            }
            //Notify the global ones later
            m_GlobalHandlerCollection.Notify(e, sender, eArgs);
        }
Пример #34
0
 /// <summary>
 /// Notifies all global event handlers of the occurance
 /// of a specific event type with some event arguments.
 /// </summary>
 /// <param name="e">The event type that occured</param>
 /// <param name="args">The event arguments</param>
 /// <exception cref="ArgumentNullException">If no event type given</exception>
 public static void Notify(RoadEvent e, EventArgs args)
 {
     Notify(e, null, args);
 }
Пример #35
0
 /// <summary>
 /// Notifies all global and local event handlers of the occurance
 /// of a specific event type.
 /// </summary>
 /// <param name="e">The event type that occured</param>
 /// <param name="sender">The sender of this event</param>
 /// <exception cref="ArgumentNullException">If no event type given</exception>
 public static void Notify(RoadEvent e, object sender)
 {
     Notify(e, sender, null);
 }
Пример #36
0
        /// <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);
            }
        }
Пример #37
0
 public static void OnScriptCompiled(RoadEvent ev, object sender, EventArgs args)
 {
     LoadCommands();
 }
Пример #38
0
 /// <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);
 }
Пример #39
0
 public static void Notify(RoadEvent e, EventArgs args)
 {
     GameEventMgr.Notify(e, null, args);
 }
Пример #40
0
 public static void Notify(RoadEvent e, object sender)
 {
     GameEventMgr.Notify(e, sender, null);
 }
Пример #41
0
 public static void Notify(RoadEvent e)
 {
     GameEventMgr.Notify(e, null, null);
 }
 /// <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);
     }
 }
Пример #43
0
        /// <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);
            }
        }
Пример #44
0
        /// <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 all callback handlers for a given event
 /// </summary>
 /// <param name="e">The event from which to remove all handlers</param>
 public void RemoveAllHandlers(RoadEvent e)
 {
     try
     {
         m_lock.AcquireWriterLock(TIMEOUT);
         try
         {
             m_events.Remove(e);
         }
         finally
         {
             m_lock.ReleaseWriterLock();
         }
     }
     catch (ApplicationException ex)
     {
         if (log.IsErrorEnabled)
             log.Error("Failed to remove event handlers!", ex);
     }
 }
Пример #46
0
 /// <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);
 }
Пример #47
0
 /// <summary>
 /// Notifies all global event handlers of the occurance of a specific
 /// event type.
 /// </summary>
 /// <param name="e">The event type that occured</param>
 /// <exception cref="ArgumentNullException">If no event type given</exception>
 public static void Notify(RoadEvent e)
 {
     Notify(e, null, null);
 }
Пример #48
0
 /// <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);
 }
Пример #49
0
 public static void AddHandler(object obj, RoadEvent e, RoadEventHandler del)
 {
     GameEventMgr.AddHandler(obj, e, del, false);
 }
Пример #50
0
 public static void OnScriptCompiled(RoadEvent ev, object sender, EventArgs args)
 {
     handles.Clear();
     SearchCommandHandlers(Assembly.GetAssembly(typeof(BaseGame)));
 }
Пример #51
0
 public static void AddHandlerUnique(object obj, RoadEvent e, RoadEventHandler del)
 {
     GameEventMgr.AddHandler(obj, e, del, true);
 }
Пример #52
0
 /// <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);
 }
 /// <summary>
 /// Notifies all registered event handlers of the occurance of an event!
 /// </summary>
 /// <param name="e">The event that occured</param>
 /// <param name="sender">The sender of this event</param>
 /// <param name="eArgs">The event arguments</param>
 /// <remarks>Overwrite the EventArgs class to set own arguments</remarks>
 public void Notify(RoadEvent e, object sender, EventArgs eArgs)
 {
     try
     {
         m_lock.AcquireReaderLock(TIMEOUT);
         WeakMulticastDelegate eventDelegate;
         try
         {
             eventDelegate = (WeakMulticastDelegate)m_events[e];
         }
         finally
         {
             m_lock.ReleaseReaderLock();
         }
         if (eventDelegate == null) return;
         eventDelegate.InvokeSafe(new object[] { e, sender, eArgs });
     }
     catch (ApplicationException ex)
     {
         if (log.IsErrorEnabled)
             log.Error("Failed to notify event handler!", ex);
     }
 }