Example #1
0
 /// <summary>
 /// (批量)注册消息
 /// </summary>
 /// <param name="mono">注册消息的对象</param>
 /// <param name="msgs">注册的消息token列表</param>
 public void RegistMsg(INotifiedObject notifiedObject, params string[] msgs)
 {
     foreach (string msg in msgs)
     {
         RegistMsg(notifiedObject, msg);
     }
 }
Example #2
0
        /// <summary>
        /// 注册一个消息
        /// </summary>
        /// <param name="id">消息的token</param>
        /// <param name="node">代理对象</param>
        public void RegistMsg(INotifiedObject notifiedObject, string msg)
        {
            NotifiedObjectProxy node = new NotifiedObjectProxy(notifiedObject);

            if (!sendList.ContainsKey(msg))
            {
                sendList.Add(msg, node);
            }
            else
            {
                NotifiedObjectProxy tmp = sendList[msg];
                tmp.AddNode(notifiedObject);
            }
        }
Example #3
0
        public void Initialization(IInitializedObject initializedObject)
        {
            INotifiedObject notifiedObject = initializedObject as INotifiedObject;

            notifiedObject.MsgHandlers = new Dictionary <string, IMsgHandler>();
            foreach (MethodInfo method in notifiedObject.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(p => p.IsDefined(typeof(MsgBindingAttribute), true)))
            {
                MsgBindingAttribute attribute = method.GetCustomAttribute(typeof(MsgBindingAttribute)) as MsgBindingAttribute;
                if (!notifiedObject.MsgHandlers.ContainsKey(attribute.TargetHandler))
                {
                    notifiedObject.MsgHandlers.Add(attribute.TargetHandler, Basic.Instence.GetInstence <IMsgHandler>("", attribute.TargetHandler));
                }
                notifiedObject.MsgHandlers[attribute.TargetHandler].MsgEventHandlers.Add(attribute.MsgToken, Delegate.CreateDelegate(typeof(MsgEventHandler), method) as MsgEventHandler);
                Basic.Instence.GetSingleton <MsgManager>(AppConst.RootLevel, notifiedObject.MsgStstem).RegistMsg(notifiedObject, attribute.MsgToken);
            }
        }
        public void Initialization(object initializedObject)
        {
            INotifiedObject notifiedObject = initializedObject as INotifiedObject;
            IMsgComponent   component      = FrameManager.CreateInstence <IMsgComponent>();

            component.notifiedObject = notifiedObject;
            component.MsgHandlers    = new Dictionary <string, IMsgHandler>();

            notifiedObject.SendMsg     = (msg, handler, parameters) => { component.SendMsg(msg, handler, parameters); };
            notifiedObject.RegistMsg   = (msg, handlerEvent, handler) => { component.RegistMsg(msg, handlerEvent, handler); };
            notifiedObject.UnRegistMsg = (msg) => { component.UnRegistMsg(msg); };

            foreach (MethodInfo method in notifiedObject.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(p => p.IsDefined(typeof(MsgBindingAttribute), true)))
            {
                MsgBindingAttribute attribute = method.GetCustomAttribute(typeof(MsgBindingAttribute)) as MsgBindingAttribute;
                component.RegistMsg(attribute.MsgToken, Delegate.CreateDelegate(typeof(MsgEventHandler), initializedObject, method) as MsgEventHandler, attribute.TargetHandler);
            }
        }