/// <summary> /// 接收MainController发来的消息,存贮到消息队列中 /// </summary> /// <param name="mt"></param> /// <param name="mb"></param> public static void MessageDelegate_For_MainController(MessageType mt, MessageBody mb) { int count = 0; Xml_codec.StaticOutputLog(LogInfoType.INFO, "AppContr收到Main侧消息。", "APPContr", LogCategory.R); Xml_codec.StaticOutputLog(LogInfoType.DEBG, string.Format("消息内容:\n{0}", mb.bJson), "APPContr", LogCategory.R); lock (mutex_Main2App_Msg) { rMain2AppMsgQueue.Enqueue(mb.bJson); if (recvMain2AppContrMsgNum == System.UInt32.MaxValue) { recvMain2AppContrMsgNum = 0; } else { recvMain2AppContrMsgNum++; } count = rMain2AppMsgQueue.Count; } string outStr = string.Format("ApContr共收到设备消息条数:{0},当前队列消息条数:{1}!", recvMain2AppContrMsgNum, count); Xml_codec.StaticOutputLog(LogInfoType.INFO, outStr, "APContr", LogCategory.R); }
private void CheckMsgBuff() { while (true) { try { HashSet <AsyncUserToken> RemoveList = new HashSet <AsyncUserToken>(); lock (locker1) { foreach (AsyncUserToken x in connList) { TimeSpan timeSpan = DateTime.Now - x.EndMsgTime; if (x.Buffer.Count > 0 && timeSpan.TotalSeconds > 10) //大于10秒认为设备不会再回消息了 { RemoveList.Add(x); } } foreach (AsyncUserToken x in RemoveList) { byte[] rev = x.Buffer.GetRange(0, x.Buffer.Count).ToArray(); string da = System.Text.Encoding.Default.GetString(rev).Trim(); if (!string.IsNullOrEmpty(da)) { Xml_codec.StaticOutputLog(LogInfoType.EROR, string.Format("清除设备[{0}:{1}]缓存消息。", x.IPAddress.ToString(), x.Port), "DeviceList"); Xml_codec.StaticOutputLog(LogInfoType.DEBG, string.Format("清除消息内容:\n{0}", da), "DeviceList"); } rev = null; da = null; x.Buffer.Clear(); x.Buffer.TrimExcess(); } connList.TrimExcess(); RemoveList.Clear(); RemoveList.TrimExcess(); } Thread.Sleep(10000); } catch (Exception e) { Xml_codec.StaticOutputLog(LogInfoType.EROR, string.Format("线程[CheckMsgBuff]出错。错误码:{0}", e.Message), "DeviceList"); } } }
static private void CheckImsiList() { HashSet <string> RemovList = new HashSet <string>(); while (true) { try { //去重功能关闭 if (DataController.RemoveDupMode != 1) { Thread.Sleep(3000); continue; } lock (locker1) { foreach (KeyValuePair <string, DateTime> kvp in dic) { //Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); TimeSpan timeSpan = DateTime.Now - kvp.Value; if (timeSpan.TotalMinutes > DataController.RemoveDupTimeLength) { RemovList.Add(kvp.Key); } } } //删除超时的imsi foreach (string x in RemovList) { del(x); } //Console.WriteLine("\n\n当前缓存Imsi数量: {0}", GetCount()); RemovList.Clear(); RemovList.TrimExcess(); Thread.Sleep(3000); } catch (Exception e) { Xml_codec.StaticOutputLog(LogInfoType.EROR, string.Format("线程[CheckImsiList]出错。错误码:{0}", e.Message), "ImsiRemoverDup"); } } }
private void CheckMsgId() { while (true) { try { lock (locker1) { foreach (AsyncUserToken x in connList) { HashSet <MsgId2App> RemoveList = new HashSet <MsgId2App>(); foreach (MsgId2App y in x.msgId2App) { TimeSpan timeSpan = DateTime.Now - y.AddTime; if (timeSpan.TotalSeconds > 30) //大于30秒认为设备不会再回消息了 { RemoveList.Add(y); } } foreach (MsgId2App y in RemoveList) { x.msgId2App.Remove(y); } x.msgId2App.TrimExcess(); RemoveList.Clear(); RemoveList.TrimExcess(); } } Thread.Sleep(10000); } catch (Exception e) { Xml_codec.StaticOutputLog(LogInfoType.EROR, string.Format("线程[CheckMsgId]出错。错误码:{0}", e.Message), "DeviceList"); } } }
/// <summary> /// 根据apinfo查询apToKen信息。首先通过ip+Prot查询,若查不到,再通过fullname查询 /// </summary> /// <param name="ApInfo">apinfo信息</param> /// <returns>apToKen信息,若未找到,返回null</returns> public AsyncUserToken FindByApInfo(Ap_Info_Struct ApInfo) { AsyncUserToken apToKen = this.FindByIpPort(ApInfo.IP, ApInfo.Port); if (apToKen == null) { Xml_codec.StaticOutputLog(LogInfoType.DEBG, string.Format("在线AP列表中找不到Ap[{0}:{1}]设备,通过FullName重新查询设备!", ApInfo.IP, ApInfo.Port.ToString()), "DeviceList"); apToKen = this.FindByFullname(ApInfo.Fullname); } if (apToKen == null) { Xml_codec.StaticOutputLog(LogInfoType.WARN, string.Format("在线AP列表中找不到Ap[{0}:{1}],FullName:{2}。无法向AP发送消息!", ApInfo.IP, ApInfo.Port.ToString(), ApInfo.Fullname), "DeviceList"); } return(apToKen); }