Esempio n. 1
0
 /// <summary>
 ///     Registers the EventHandlers
 /// </summary>
 /// <param name="eventname">Eventname we are registering too</param>
 /// <param name="handler">Handler to call on an event</param>
 /// <param name="log"></param>
 public static void Register(string eventname, LuaEventHandlerDelegate handler, bool log = true)
 {
     try
     {
         List <LuaEventHandlerDelegate> handlers;
         if (!EventHandlers.TryGetValue(eventname, out handlers))
         {
             EventHandlers.Add(eventname, new List <LuaEventHandlerDelegate> {
                 handler
             });
             Lua.Events.AttachEvent(eventname, handler);
             if (log)
             {
                 Logger.NormalLog("LuaEventHandler: Attaching {0} to {1}", handler.GetMethodInfo().Name, eventname);
             }
         }
         else
         {
             handlers.Add(handler);
             Lua.Events.AttachEvent(eventname, handler);
             if (log)
             {
                 Logger.NormalLog("LuaEventHandler: Attaching {0} to {1}", handler.GetMethodInfo().Name, eventname);
             }
         }
     }
     // ReSharper disable once EmptyGeneralCatchClause
     catch
     {
         // Root.HandleException(ex);
     }
 }
Esempio n. 2
0
        /// <summary>
        ///     unregistered the EventHandlers
        /// </summary>
        /// <param name="eventname">Eventname we are detaching from</param>
        /// <param name="handler">Handler to remove from event</param>
        /// <param name="log"></param>
        /// &gt;
        public static void UnRegister(string eventname, LuaEventHandlerDelegate handler, bool log = true)
        {
            List <LuaEventHandlerDelegate> handlers;

            if (!EventHandlers.TryGetValue(eventname, out handlers))
            {
                return;
            }

            // Remove
            try
            {
                EventHandlers[eventname].Remove(handler);
                Lua.Events.DetachEvent(eventname, handler);
                if (log)
                {
                    Logger.NormalLog("LuaEventHandler: Detaching {0} from {1}", handler.GetMethodInfo().Name, eventname);
                }
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // Root.HandleException(ex);
            }
        }
Esempio n. 3
0
 /// <summary>
 ///     Registers the EventHandlers
 /// </summary>
 /// <param name="eventname">Eventname we are registering too</param>
 /// <param name="handler">Handler to call on an event</param>
 /// <param name="log"></param>
 public static void Register(string eventname, LuaEventHandlerDelegate handler, bool log = true)
 {
     try
     {
         List<LuaEventHandlerDelegate> handlers;
         if (!EventHandlers.TryGetValue(eventname, out handlers))
         {
             EventHandlers.Add(eventname, new List<LuaEventHandlerDelegate> { handler });
             Lua.Events.AttachEvent(eventname, handler);
             if (log) Logger.NormalLog("LuaEventHandler: Attaching {0} to {1}", handler.GetMethodInfo().Name, eventname);
         }
         else
         {
             handlers.Add(handler);
             Lua.Events.AttachEvent(eventname, handler);
             if (log) Logger.NormalLog("LuaEventHandler: Attaching {0} to {1}", handler.GetMethodInfo().Name, eventname);
         }
     }
         // ReSharper disable once EmptyGeneralCatchClause
     catch
     {
         // Root.HandleException(ex);
     }
 }
Esempio n. 4
0
        /// <summary>
        ///     unregistered the EventHandlers
        /// </summary>
        /// <param name="eventname">Eventname we are detaching from</param>
        /// <param name="handler">Handler to remove from event</param>
        /// <param name="log"></param>
        /// &gt;
        public static void UnRegister(string eventname, LuaEventHandlerDelegate handler, bool log = true)
        {
            List<LuaEventHandlerDelegate> handlers;

            if (!EventHandlers.TryGetValue(eventname, out handlers)) return;

            // Remove
            try
            {
                EventHandlers[eventname].Remove(handler);
                Lua.Events.DetachEvent(eventname, handler);
                if (log) Logger.NormalLog("LuaEventHandler: Detaching {0} from {1}", handler.GetMethodInfo().Name, eventname);
            }
                // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // Root.HandleException(ex);
            }
        }