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

            //  清理字典
            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);
                    if (_Connected)     // 重新订阅
                    {
                        remoteInfo.Unsubscribe(key);
                    }
                }
            }
            LogHelper.Info(typeof(RemoteInfoHelper).FullName, infoAction.GetType().FullName + "撤消远程信息");


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

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

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

            return(true);
        }