Beispiel #1
0
 public void Register <T>(Event.Handler handler) where T : Event
 {
     System.Type t = typeof(T);
     if (registeredHandlers.ContainsKey(t))
     {
         registeredHandlers[t] += handler;
     }
     else
     {
         registeredHandlers[t] = handler;
     }
 }
Beispiel #2
0
    public void Register <T>(Event.Handler handler) where T : Event
    {
        Type type = typeof(T);

        if (RegisteredHandlers.ContainsKey(type))
        {
            RegisteredHandlers[type] += handler;
        }
        else
        {
            RegisteredHandlers[type] = handler;
        }
    }
Beispiel #3
0
 public void Unregister <T>(Event.Handler handler) where T : Event
 {
     System.Type   type = typeof(Event);
     Event.Handler handlers;
     if (registeredHandlers.TryGetValue(type, out handlers))
     {
         handlers -= handler;
         if (handler == null)
         {
             registeredHandlers.Remove(type);
         }
         else
         {
             registeredHandlers[type] = handlers;
         }
     }
 }
Beispiel #4
0
    public void UnRegister <T>(Event.Handler handler) where T : Event
    {
        Type type = typeof(T);

        Event.Handler handlers;

        if (RegisteredHandlers.TryGetValue(type, out handlers))
        {
            handlers -= handler;
            if (handlers == null)
            {
                RegisteredHandlers.Remove(type);
            }
            else
            {
                RegisteredHandlers[type] = handlers;
            }
        }
    }
Beispiel #5
0
    //Objects call this function to subscribe to events of a given type.
    //handler = The function to be called when the event occurs.
    //T = The type of the event.
    public void Register <T>(Event.Handler handler) where T : Event
    {
        Type type = typeof(T);

        /*
         *
         * If there's already an event of that type, add this handler to the list of handlers for that event.
         * If not, add that event to the dictionary, with this handler as the first item in the list.
         * Note that there's no explicit list; in C# delegates are both references to a function and a list of functions.
         *
         */

        if (registeredHandlers.ContainsKey(type))
        {
            registeredHandlers[type] += handler;
        }
        else
        {
            registeredHandlers[type] = handler;
        }
    }
Beispiel #6
0
 /// <summary>
 /// Add new Managed event
 /// </summary>
 /// <param name="_condition">Condition function, event will fire when condition returns true</param>
 /// <param name="_eventAction">Event Handler Action with target type IEvent</param>
 /// <param name="_id">Optional event ID</param>
 /// <returns>Created event</returns>
 public static IEvent Add(Event.Condition _condition, Event.Handler <IEvent> _eventAction, string _id = null)
 {
     return(EventMgr.Add(_condition, _eventAction, 1, Defaults.EventPriority, DESC_USER_EVENT, _id));
 }
Beispiel #7
0
 public void RegisterRoute(string Path, Event.Handler Handler)
 {
     Handlers.Register(Path, Handler);
 }
Beispiel #8
0
 public void OnConnect(Event.Handler Handler)
 {
     this.ClientConnect = (C) => {
         Event.Invoke(Handler, "Client", C);
     };
 }
Beispiel #9
0
 public void On(string Key, Event.Handler Handler)
 {
     RegisterRoute(Key, Handler);
 }
Beispiel #10
0
 public SystemFunction(string Name, Event.Handler Handler, params string[] ArgNames) : base(Name)
 {
     this.Name      = Name;
     this.Handler   = Handler;
     this.Arguments = ArgNames;
 }
Beispiel #11
0
 public void On(string Name, Event.Handler Func, string ThisName, object This)
 {
     this.AddEvent("On" + Name, Event.Wrapper(Func, "Bot", this, ThisName, This));
 }
Beispiel #12
0
 public void On(string Name, Event.Handler Func)
 {
     this.AddEvent("On" + Name, Event.Wrapper(Func, "Bot", this));
 }