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

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

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

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  撤消信息
        /// </summary>
        /// <param name="infoAction">带信息功能的对象</param>
        /// <returns></returns>
        public static bool RevokeInfo(InfoLocalAction 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(InfoLocalHelper).FullName, infoAction.GetType().FullName + "撤消本地信息");

            return(true);
        }