public void AddMsgIntoOutBuffer(MsgRecord msgRecord) { if (clientModels.ContainsKey(msgRecord.MsgRecipientObjectID)) { //if (clientModels[msgRecord.MsgRecipientObjectID].LatestTime.CompareTo(msgRecord.SendTime) < 0) //{ // clientModels[msgRecord.MsgRecipientObjectID].LatestTime = msgRecord.SendTime; //} MsgRecordModel msgRecordModel = ModelTransfor(msgRecord); msgRecordModel.Client_IP = clientModels[msgRecord.MsgRecipientObjectID].Client_IP; msgRecordModel.Client_Port = clientModels[msgRecord.MsgRecipientObjectID].Client_Port; GetUsingMsgRecordBufferToUA.Add(msgRecordModel); } }
private void MainHandErrorMsgThread() { try { while (IsRunning) { IList <ClientModel> tempclientModels = clientModels.Values.Where(t => t.LatestTime.CompareTo(DateTime.Now.AddSeconds(-10) .ToString(CommonFlag.F_DateTimeFormat)) < 0).ToList(); if (tempclientModels != null && tempclientModels.Count > 0) { foreach (ClientModel clientModel in tempclientModels) { clientModels.Remove(clientModel.ObjectID); } } #region UA msg if (ExeingMsgRecordForUA.Count > 0) { //reTryCount >reTryCount IList <MsgRecordModel> needdelete1 = ExeingMsgRecordForUA.Values.Where(t => t.reTryCount >= reTryCount).ToList(); if (needdelete1 != null && needdelete1.Count > 0) { foreach (MsgRecordModel tempmodel in needdelete1) { ExeingMsgRecordForUA.Remove(tempmodel.MsgID); } } //exist in tempclientModels IList <MsgRecordModel> needdelete2 = (from aa in ExeingMsgRecordForUA.Values join bb in tempclientModels on aa.MsgRecipientObjectID equals bb.ObjectID select aa).ToList(); if (needdelete2 != null && needdelete2.Count > 0) { foreach (MsgRecordModel tempmodel in needdelete2) { ExeingMsgRecordForUA.Remove(tempmodel.MsgID); } } //retry needdelete2 = ExeingMsgRecordForUA.Values.Where(t => t.ExeSendTime.CompareTo(DateTime.Now.AddSeconds(0 - reTrySec) .ToString(CommonFlag.F_DateTimeFormat)) < 0 && t.reTryCount < reTryCount).ToList(); if (needdelete2 != null && needdelete2.Count > 0) { foreach (MsgRecordModel tempmodel in needdelete2) { ExeingMsgRecordForUA.Remove(tempmodel.MsgID); if (clientModels.ContainsKey(tempmodel.MsgRecipientObjectID)) { tempmodel.Client_IP = clientModels[tempmodel.MsgRecipientObjectID].Client_IP; tempmodel.Client_Port = clientModels[tempmodel.MsgRecipientObjectID].Client_Port; } GetUsingMsgRecordBufferToUA.Add(tempmodel); } } } #endregion #region MDS msg if (ExeingMsgRecordForMDS.Count > 0) { ////reTryCount >reTryCount IList <MsgRecordModel> needdelete1 = ExeingMsgRecordForMDS.Values.Where(t => t.reTryCount >= reTryCount).ToList(); if (needdelete1 != null && needdelete1.Count > 0) { foreach (MsgRecordModel tempmodel in needdelete1) { ExeingMsgRecordForMDS.Remove(tempmodel.MsgID); } } IList <MsgRecordModel> needdelete2 = ExeingMsgRecordForMDS.Values.Where(t => t.ExeSendTime.CompareTo(DateTime.Now.AddSeconds(0 - reTrySec) .ToString(CommonFlag.F_DateTimeFormat)) < 0 && t.reTryCount < reTryCount).ToList(); //retry if (needdelete2 != null && needdelete2.Count > 0) { foreach (MsgRecordModel tempmodel in needdelete2) { ExeingMsgRecordForMDS.Remove(tempmodel.MsgID); GetUsingMsgRecordBufferToMDS.Add(tempmodel); } } } #endregion Thread.Sleep(_handlerError); } } catch (Exception ex) { CommonVariables.LogTool.Log(ex.Message + ex.StackTrace); } }