Example #1
0
        /// <summary>
        ///  撤消信息
        /// </summary>
        /// <param name="infoAction">带信息功能的对象</param>
        /// <returns></returns>
        public static bool RevokeInfo(LocalInfoReceiver infoAction)
        {
            if (infoAction == null)
            {
                return(false);
            }

            //  清理字典
            List <String> keys = _ActionDict.Keys.ToList <String>();

            foreach (String key in keys)
            {
                var item = _ActionDict[key];
                if (item.Exists(o => o == infoAction))
                {
                    item.Remove(infoAction);
                }

                if (item.Count == 0)
                {
                    _ActionDict.Remove(key);
                }
            }
            LogHelper.Info(typeof(LocalInfoHelper).FullName, infoAction.GetType().FullName + "撤消本地信息");

            return(true);
        }
Example #2
0
        /// <summary>
        ///  注册信息
        /// </summary>
        /// <param name="infoAction">带信息功能的对象</param>
        /// <param name="infoCodeList">需要注册的信息列表</param>
        /// <returns></returns>
        public static bool RegisterInfo(LocalInfoReceiver infoAction, List <String> infoCodeList)
        {
            if (infoAction == null || infoCodeList.Count == 0)
            {
                LogHelper.Warn(typeof(LocalInfoHelper).FullName, "注册时对象不能空或没有接受信息代码");
                return(false);
            }

            foreach (String code in infoCodeList)
            {
                if (!_ActionDict.ContainsKey(code))                //  信息代码不存在
                {
                    _ActionDict.Add(code, new List <LocalInfoReceiver>());
                }

                //  是否已经存在,不存在新加入
                List <LocalInfoReceiver> lst = _ActionDict[code];
                if (!lst.Exists(o => o == infoAction))
                {
                    lst.Add(infoAction);
                }
            }
            LogHelper.Info(typeof(LocalInfoHelper).FullName, infoAction.GetType().FullName + "注册本地信息,代码:" + string.Join(",", infoCodeList.ToArray()));

            return(true);
        }
        /// <summary>
        ///  注意:调用前子类必须设置好_infoCodeList。
        /// </summary>
        /// <returns></returns>
        public override bool Init()
        {
            _InfoAction = new LocalInfoReceiver(_InfoCodeList, CallbackInfo);

            return(base.Init());
        }