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

            bool reRegister = 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);
                    reRegister = true;
                }
            }
            LogHelper.Info(typeof(InfoRemoteHelper).FullName, infoAction.GetType().FullName + "撤消远程信息");


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

            bool reRegister = false;      //  标志是否需要重新注册

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

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

            if (reRegister)
            {
                return(Subscribe());
            }
            else
            {
                return(true);
            }
        }