/// <summary> /// If the event exists,invoke the event when server return messge. /// </summary> /// <param name="eventName"></param> /// <param name="value"></param> /// <returns></returns> /// public void InvokeOnEvent(ERequestTypes id, ICommand msg) { if (!this.eventMap.ContainsKey(id)) { return; } List <Action <ICommand> > list = eventMap[id]; foreach (Action <ICommand> action in list) { action.Invoke(msg); } }
//Adds the event to eventMap by name. public void AddOnEvent(ERequestTypes eventName, Action <ICommand> callback) { List <Action <ICommand> > list = null; if (this.eventMap.TryGetValue(eventName, out list)) { list.Add(callback); } else { list = new List <Action <ICommand> >(); list.Add(callback); this.eventMap.Add(eventName, list); } }
// 注册指定服务器推送消息 public void Register(ERequestTypes eventId, Action <ICommand> action) { mEventManager.AddOnEvent(eventId, action); }
public void AddOnEvent <T>(Action <T> handler) where T : ICommand { ERequestTypes eventId = (ERequestTypes)Enum.Parse(typeof(ERequestTypes), "E" + typeof(T).Name); AddOnEvent(eventId, delegate(ICommand cmd) { handler((T)cmd); }); }
// 注册指定服务器推送消息 public void Register(ERequestTypes eventId, Action <ICommand> action) { mClient.Register(eventId, action); }