Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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!");
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
                        }
                    }
                }
            }
        }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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!");
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 37
0
 public static void OnScriptCompiled(RoadEvent ev, object sender, EventArgs args)
 {
     LoadCommands();
 }
Exemplo n.º 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);
 }
Exemplo n.º 39
0
 public static void Notify(RoadEvent e, EventArgs args)
 {
     GameEventMgr.Notify(e, null, args);
 }
Exemplo n.º 40
0
 public static void Notify(RoadEvent e, object sender)
 {
     GameEventMgr.Notify(e, sender, null);
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 49
0
 public static void AddHandler(object obj, RoadEvent e, RoadEventHandler del)
 {
     GameEventMgr.AddHandler(obj, e, del, false);
 }
Exemplo n.º 50
0
 public static void OnScriptCompiled(RoadEvent ev, object sender, EventArgs args)
 {
     handles.Clear();
     SearchCommandHandlers(Assembly.GetAssembly(typeof(BaseGame)));
 }
Exemplo n.º 51
0
 public static void AddHandlerUnique(object obj, RoadEvent e, RoadEventHandler del)
 {
     GameEventMgr.AddHandler(obj, e, del, true);
 }
Exemplo n.º 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);
     }
 }