示例#1
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);
        }
示例#2
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;
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="code"></param>
        public virtual void Init(string code)
        {
            //  加入远程信息接收处理
            List <string> infoRemoteCodeList = new List <string>();

            infoRemoteCodeList.Add(code);
            infoRemoteAction = new RemoteInfoReceiver(infoRemoteCodeList, SynCallbackInfo);

            //  加入定时信息获取
            if (timer_interval > 0)
            {
                timer1            = new Timer();
                timer1.Interval   = timer_interval;
                this.timer1.Tick += (ts, te) =>
                {
                    this.QueryInfo();
                };
                this.timer1.Start();
            }
        }
示例#4
0
        /// <summary>
        ///  注意:调用前子类必须设置好_infoCodeList。
        /// </summary>
        /// <returns></returns>
        public override bool Init()
        {
            _InfoAction = new RemoteInfoReceiver(_InfoCodeList, SynCallbackInfo);

            return(base.Init());
        }