private void DispatchMsg(MessageData msgdata) { ICommunicationHandler handler; switch (msgdata.TragetPlatform) { case PlatformType.Encrypt: handler = new EncryptCommunicationHandler(); break; case PlatformType.Core: default: handler = new CoreCommunicationHandler(); break; } if (_dispatchMsg != null) { lock (_dispatchMsg) { _dispatchMsg.MsgHandler = handler; _dispatchMsg.OnDispatchMsgAsync(msgdata, msgdata.MessageID); } } else { _dispatchMsg = new MsgDispatchEAP(handler); lock (_dispatchMsg) { _dispatchMsg.DispatchCompleted += new DispatchCompletedEventHandler(DispatchMsg_DispatchCompleted); _dispatchMsg.OnDispatchMsgAsync(msgdata, msgdata.MessageID); } } }
public static MessageData CreateMessageData(Guid msgid, PlatformType platform, string tellerno, string orgno, int msgbiztype, byte[] codemsg) { MessageData msgdata = new MessageData { MessageID = msgid, FirstTime = DateTime.Now, TragetPlatform = platform, TellerNO = tellerno, OrgNO=orgno, MsgBizType=msgbiztype, ReSentTime = 0 }; msgdata.ReqPackageList.Enqueue(new PackageData(1, codemsg)); msgdata.IsMultiPackage = false; return msgdata; }
public void GetResendMessages() { try { String condition = "M_STATE='1'"; TTRD_AIDSYS_MSG_LOG_Manager manager = new TTRD_AIDSYS_MSG_LOG_Manager(); DataTable table = manager.LogQuery(condition); foreach (DataRow row in table.Rows) { try { MessageData data = new MessageData(); data.MessageID = new Guid(row["M_ID"].ToString()); data.BizMsgID = row["M_SERIALNO"].ToString(); data.FirstTime = Convert.ToDateTime(row["M_SENDDATE"].ToString()); data.TragetPlatform = (PlatformType)Convert.ToInt32(row["M_PLATTYPE"].ToString()); data.IsMultiPackage = Convert.ToInt32(row["M_ISSINGLE"]) != 1; data.ReqPackageList.Enqueue(new PackageData(Convert.ToInt16(row["M_SUBID"]), (byte[])row["M_S_CONTENT"])); _msgList.Add(data); } catch (Exception) { continue; } } } catch (Exception ex) { throw ex; } }
public static MessageData PostMessage(MessageData reqmsg, List<byte[]> bytes, out bool hasSent) { if (!Inited) { MQMsgHandlerEntry.Init(); if (!Inited || _handler == null) { throw new AidException(MsgHandlerEntry.MQ_Exception_Title, "初始化MQ连接失败!(MQMsgHandlerEntry.DeliverMessage)", null); } } if (_handler != null) { try { return _handler.GetSyncResult(reqmsg, bytes, out hasSent); } catch (Exception ex) { throw ex; } } else { throw new AidException(MsgHandlerEntry.MQ_Exception_Title, "无法得到MQExternalHandler的singleton实例!(MQMsgHandlerEntry.DeliverMessage)", null); } }
public static MessageData CreateMessageData(Guid msgid, PlatformType platform, string tellerno, string orgno, int msgbiztype, List<byte[]> codemsg) { MessageData msgdata = new MessageData { MessageID = msgid, FirstTime = DateTime.Now, TragetPlatform = platform, TellerNO = tellerno, OrgNO = orgno, MsgBizType = msgbiztype, ReSentTime = 0 }; short index = 0; foreach (var item in codemsg) { msgdata.ReqPackageList.Enqueue(new PackageData(index++, item)); } msgdata.IsMultiPackage = true; return msgdata; }
private void DispatchCompleting(MessageData responsemsg, Exception ex, bool canceled, AsyncOperation asyncOper) { if (!canceled) { lock (_userStateToLifetime.SyncRoot) { _userStateToLifetime.Remove(asyncOper.UserSuppliedState); } } TransmitCompletedEventArgs eventArgs = new TransmitCompletedEventArgs(responsemsg, ex, canceled, asyncOper.UserSuppliedState); asyncOper.PostOperationCompleted(onCompletedDelegate, eventArgs); }
public static MessageData DeliverMessage(MessageData reqmsg, byte[] bytes, out bool hasSent) { if (bytes != null) { List<byte[]> list = new List<byte[]>(); list.Add(bytes); return PostMessage(reqmsg, list, out hasSent); } else { hasSent = false; return null; } }
private void DispatchMsg(MessageData msgdata) { try { ICommunicationHandler handler; switch (msgdata.TragetPlatform) { case PlatformType.Encrypt: handler = new EncryptCommunicationHandler(); break; case PlatformType.Payment: case PlatformType.PaymentDownload: handler = new PayCommunicationHandler(); break; case PlatformType.Core: default: handler = new CoreCommunicationHandler(); break; } if (_dispatchMsg != null) { lock (_dispatchMsg) { _dispatchMsg.MsgHandler = handler; _dispatchMsg.OnDispatchMsgAsync(msgdata, msgdata.MessageID); } } else { _dispatchMsg = new MsgDispatchEAP(handler); lock (_dispatchMsg) { _dispatchMsg.DispatchCompleted += new DispatchCompletedEventHandler(DispatchMsg_DispatchCompleted); _dispatchMsg.OnDispatchMsgAsync(msgdata, msgdata.MessageID); } } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
/// <summary> /// Devlivering to handler which has owned a corresponding Socket /// </summary> /// <param name="msgdata"></param> /// <returns></returns> public static MessageData DeliverMessage(MessageData msgdata) { if (msgdata == null) { return null; } switch (msgdata.TragetPlatform) { case PlatformType.Encrypt: if (_encryptHandler == null) { _encryptHandler = new EncryptCommunicationHandler(); } return _encryptHandler.MessageHandler(msgdata); case PlatformType.Core: if (_coreHandler == null) { _coreHandler = new CoreCommunicationHandler(); } return _coreHandler.MessageHandler(msgdata); case PlatformType.Payment: case PlatformType.PaymentDownload: if (_paymentHandler == null) { _paymentHandler = new PayCommunicationHandler(); } return _paymentHandler.MessageHandler(msgdata); case PlatformType.FingerMarks: if (_fingerMarksHandler == null) { _fingerMarksHandler = new MarkComminicationHandler(); } return _fingerMarksHandler.MessageHandler(msgdata); default: if (_nullableHandler == null) { _nullableHandler = new NullableHandler(); } return _nullableHandler.MessageHandler(msgdata); } }
public virtual void OnDispatchMsgAsync(MessageData message, object taskid) { AsyncOperation asyncOper = AsyncOperationManager.CreateOperation(taskid); // Multiple threads will access the task dictionary, so it must be locked to serialize access. lock (_userStateToLifetime.SyncRoot) { if (_userStateToLifetime.Contains(taskid)) { throw new ArgumentException("Task ID parameter must be unique", "OnDispatchMsgAsync:taskid"); } _userStateToLifetime[taskid] = asyncOper; } // Start the asynchronous operation. DispatchEventHandler disptchHandler = new DispatchEventHandler(OnDispatch); disptchHandler.BeginInvoke(message, asyncOper, null, null); }
public override void MessageAsyncHandler(MessageData reqMsg, MessageHandlerCompleteAsync callbackHandler) { _callbackHandler = callbackHandler; _respMsg = new MessageData { MessageID = reqMsg.MessageID, FirstTime = reqMsg.FirstTime, TragetPlatform = reqMsg.TragetPlatform, ReqPackageList = reqMsg.ReqPackageList}; try { using (SocketClientAsync sca = new SocketClientAsync(Host, Port)) { SocketAsyncEventArgs eventArgs = sca.Init(reqMsg.ReqPackageList); if (eventArgs != null) { SocketCompletedEventHandler transmitComplete = new SocketCompletedEventHandler(TransmitComplete); sca.BeginTransmit(eventArgs, transmitComplete); } } } catch(Exception ex) { //throw ex; _callbackHandler(_respMsg, ex); } }
/// <summary> /// 获取调用接口的结果 /// </summary> /// <param name="msgdata"></param> /// <param name="recBytes"></param> /// <param name="hasSent"></param> /// <returns></returns> public MessageData GetSyncResult(MessageData msgdata, List<byte[]> recBytes, out bool hasSent) { hasSent = false; if (msgdata == null) { return null; } try { if (!_isSyncReceiver) { if (!_receiverManager.InsertSemaphore(msgdata.MessageID, false)) { throw new AidException(MsgHandlerEntry.MQ_Exception_Title, "加入异步等待信号量错误!请重试...", null); } } MessageData data = null; lock (_senderLocker) { data = SendToMQInService(msgdata, recBytes, out hasSent); } //同步接收 if (_isSyncReceiver) { return data; } else { if (_receiverManager.WaitSemaphore(msgdata.MessageID, 1000 * 70)) { xQuant.Log4.LogHelper.Write(xQuant.Log4.LogLevel.Debug, string.Format("<{0}>:已接收MQ返回!", msgdata.MessageID)); return AfterReleaseAsync(msgdata.MessageID); } else { xQuant.Log4.LogHelper.Write(xQuant.Log4.LogLevel.Debug, string.Format("<{0}>:接收MQ返回超时!", msgdata.MessageID)); // 等待接收超时视为“发送成功” ReleaseAsyncTimeout(msgdata.MessageID, "接收MQ返回超时!", MsgLogState.SendSucceed); throw new AidException(MsgHandlerEntry.MQ_Exception_Title, "接收MQ返回超时", null); } } } catch (AidException aidex) { throw aidex; } catch (Exception ex) { throw new AidException(MsgHandlerEntry.MQ_Exception_Title, ex.Message, ex); } finally { CleanUpAsync(msgdata.MessageID); } }
private void buttonRedepo_Click(object sender, EventArgs e) { try { byte[] codemsg = null; Guid messageID = MsgTransferUtility.InterBankAutoRedepo(机构号.Text.Trim(), 柜员号.Text.Trim(), DateTime.Parse(交易日.Text.Trim()), 账号.Text.Trim(), DateTime.Parse(新起息日.Text), DateTime.Parse(新到期日.Text), ref codemsg); MessageData msgdata = new MessageData { MessageID = messageID, FirstTime = DateTime.Now, IsMultiPackage = false, TragetPlatform = PlatformType.Core }; msgdata.ReqPackageList.Enqueue(new PackageData(1, codemsg)); DispatchMsg(msgdata); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void SendToMQ(MessageData msgdata, byte[] recBytes, String definedError) { if (msgdata == null) { return; } if (recBytes == null || recBytes.Length == 0) { definedError = string.IsNullOrEmpty(definedError) ? "MQ发送返回数据为空" : definedError; } MQMessage msg = GetMessage(msgdata.BizMsgID, msgdata.MessageID, msgdata.TragetPlatform, msgdata.IsMultiPackage, msgdata.SourceIP, definedError); int realLen = 0; if (recBytes != null) { realLen = recBytes.Length; if (msgdata.TragetPlatform != PlatformType.Encrypt) { byte end = 0; realLen = Array.IndexOf(recBytes, end); } if (realLen >= 0) { byte[] buffer = new byte[realLen]; Array.Copy(recBytes, buffer, realLen); msg.Byte = buffer; } } try { if (!Inited) { Init(); } lock (typeof(MQHandlerSync)) { _mqSender.SendMessage(msg); } } catch (Exception ex) { if (msg != null) { AidLogHelper.Write(xQuant.Log4.LogLevel.Error, string.Format("_mqSender.SendMessage()发生异常!Exception:{0}!\r\nStackTrace:{1}!",ex.Message, ex.StackTrace)); //try //{ // Close(); // Init(); //} //catch (Exception e) //{ // AidLogHelper.Write(xQuant.Log4.LogLevel.Error, string.Format("重新开始初始化发生异常!Exception:{0}!\r\nStackTrace:{1}!", e.Message, e.StackTrace)); //} } } }
void MessageHandleAsync_Completed(MessageData respData, Exception ex) { if (respData == null) { //CommonHelper.AddEventLog(EventSourceName, "返回数据为空!"); return; } if (ex != null) { //CommonHelper.AddEventLog(EventSourceName, ex.Message); RecordDB(ex.Message, respData); MQMessage exmq = GetMessage(respData.BizMsgID, respData.MessageID, respData.TragetPlatform, !respData.IsMultiPackage, respData.SourceIP, ex.Message); return; } byte[] rebytes = respData.GetRespMessage(); // 发送个MQ(MessageID, buffer) MQMessage msg = GetMessage(respData.BizMsgID, respData.MessageID, respData.TragetPlatform, !respData.IsMultiPackage, respData.SourceIP, ""); int realLen = rebytes.Length; if (respData.TragetPlatform != PlatformType.Encrypt) { byte end = 0; realLen = Array.IndexOf(rebytes, end); } byte[] buffer = new byte[realLen]; Array.Copy(rebytes, buffer, realLen); msg.Byte = buffer; lock (typeof(MQHandlerSync)) { _mqSender.SendMessage(msg); } AidLogHelper.Write(xQuant.Log4.LogLevel.Debug, "socket处理完,MQ发回消息(MQHandlerSync)"); }
private void DispatchMsg(MessageData msgdata) { ICommunicationHandler handler; switch (msgdata.TragetPlatform) { case PlatformType.Encrypt: handler = new EncryptCommunicationHandler(); break; case PlatformType.Payment: case PlatformType.PaymentDownload: handler = new PayCommunicationHandler(); break; case PlatformType.Core: handler = new CoreCommunicationHandler(); break; case PlatformType.FingerMarks: handler = new MarkComminicationHandler(); break; default: handler = new NullableHandler(); break; } AidLogHelper.Write(xQuant.Log4.LogLevel.Debug, "开始分发(MQHandlerSync),GUID=" + msgdata.MessageID); if (_dispatchMsg != null) { lock (_dispatchMsg) { _dispatchMsg.MsgHandler = handler; _dispatchMsg.OnDispatchMsgAsync(msgdata, msgdata.MessageID); } } else { _dispatchMsg = new MsgDispatchEAP(handler); lock (_dispatchMsg) { _dispatchMsg.DispatchCompleted += new DispatchCompletedEventHandler(DispatchMsg_DispatchCompleted); _dispatchMsg.OnDispatchMsgAsync(msgdata, msgdata.MessageID); } } AidLogHelper.Write(xQuant.Log4.LogLevel.Debug, "分发结束(MQHandlerSync),GUID="+ msgdata.MessageID); }
public static MessageData FromMQMessage(MQMessage mqmsg, out string error) { error = ""; if (mqmsg == null) { return null; } MessageData data = new MessageData(); string msgid = FindDefinedParameterValue(mqmsg.HeaderUser.UserDefined, "GUID"); if (!String.IsNullOrEmpty(msgid)) { data.MessageID = new Guid(msgid); } else { return null; } data.BizMsgID = mqmsg.HeaderUser.UserServiceId.Value; bool isSingle = true; string mpkgFlag = FindDefinedParameterValue(mqmsg.HeaderUser.UserDefined, "PKGTYPE"); if (!String.IsNullOrEmpty(mpkgFlag)) { if (bool.TryParse(mpkgFlag, out isSingle)) { data.IsMultiPackage = !isSingle; } else { data.IsMultiPackage = false; } } else { return null; } string platform = FindDefinedParameterValue(mqmsg.HeaderUser.UserDefined, "TARGETSYS"); if (!String.IsNullOrEmpty(platform)) { data.TragetPlatform = (PlatformType)Enum.Parse(typeof(PlatformType), platform); } else { return null; } string sourceIP = FindDefinedParameterValue(mqmsg.HeaderUser.UserDefined, "IP"); if (!String.IsNullOrEmpty(sourceIP)) { data.SourceIP = sourceIP; } data.RespPackageList.Enqueue(new PackageData(1, mqmsg.Byte)); error = FindDefinedParameterValue(mqmsg.HeaderUser.UserDefined, "ERROR"); //if (!String.IsNullOrEmpty(error)) //{ // throw new Exception(string.Format("解析MQ消息,GUID={0};ERROR={1};", data.MessageID, error)); //} return data; }
private void buttonQuery_Click(object sender, EventArgs e) { try { String ouno = textBoxOrgNO.Text.TrimStart(); String tellno = textBoxTellerNO.Text.TrimStart(); DateTime _coreDate = DateTime.Parse(dateTimeCore.Text); DateTime querydate = DateTime.ParseExact(textBoxQueryDate.Text, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture); Guid messageID = MsgTransferUtility.AccountingCheck(tellno, ouno, _coreDate, querydate, textBoxBizFlowNO.Text.Trim(), textBoxQueryOrg.Text.Trim(), ref uLongText); MessageData msgdata = new MessageData { MessageID = messageID, FirstTime = DateTime.Now, TragetPlatform = PlatformType.Core }; msgdata.ReqPackageList.Enqueue(new PackageData(1, uLongText)); msgdata.IsMultiPackage = false; DispatchMsg(msgdata); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonQuery_Click(object sender, EventArgs e) { try { string strDate = textBoxQueryDate.Text; DateTime querydate = DateTime.ParseExact(strDate, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); //List<PayCheckAcct> outlist; //string outmsg; //AidSysClientSyncWrapper.PayCheckAccount(querydate, out outlist, out outmsg); Guid messageID = MsgTransferUtility.PayCheckAccount(querydate, ref uLongText); MessageData msgdata = new MessageData { MessageID = messageID, FirstTime = DateTime.Now, TragetPlatform = PlatformType.PaymentDownload }; msgdata.ReqPackageList.Enqueue(new PackageData(1, uLongText)); msgdata.IsMultiPackage = false; DispatchMsg(msgdata); } catch (Exception ex) { textBoxResult.Text = ex.Message; return; } }
private void AfterReceivedAsync(MessageData data, string error, MsgLogState state) { if (data == null || data.MessageID == Guid.Empty) { return; } string dbexception = ""; // 先更新数据库再释放等待信号量,保证多线程更新数据库前后顺序 MQMsgCommonHelper.UpdateMQLog(data, "", error, state, out dbexception); _receiverManager.InsertAsyncResult(data.MessageID, state == MsgLogState.RecvSucceed? (object)data : (object)error); _receiverManager.ReleaseSemaphore(data.MessageID); }
public static int AddMQLog(MessageData msgdata, byte[] senddata, MsgLogState state, out string exception) { exception = ""; try { TTRD_SET_MSG_LOG log = new TTRD_SET_MSG_LOG(); log.GUID = msgdata.MessageID.ToString(); log.FLOW_NO = msgdata.BizMsgID??""; log.USER_CODE = msgdata.TellerNO; log.INS_ID = msgdata.OrgNO; log.IS_MUL_PKG = msgdata.IsMultiPackage ? "1" : "0"; log.MSGTYPE = msgdata.MsgBizType; log.PLATFORMTYPE = (int)msgdata.TragetPlatform; log.SEND_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); log.SEND_CONTENT = senddata; log.STATE = (int)state; int count = 0; using (TransactionScope trans = new TransactionScope(TransactionScopeOption.RequiresNew)) { TTRD_SET_MSG_LOG_Manager manager = new TTRD_SET_MSG_LOG_Manager(); count = manager.LogInsert(log); trans.Complete(); } return count; } catch(Exception ex) { exception = ex.Message; xQuant.Log4.LogHelper.Write(xQuant.Log4.LogLevel.Error, string.Format("<MQMsgCommonHelper-AddMQLog> Exception:{0}; StatkTrace:{1}.", ex.Message, ex.StackTrace)); return 0; } }
/// <summary> /// 发送处理 /// </summary> /// <param name="msgdata"></param> /// <param name="recBytes"></param> /// <param name="sent"></param> /// <returns></returns> public MessageData SendToMQInService(MessageData msgdata, List<byte[]> recBytes, out bool sent) { string dbexception = ""; sent = false; try { if (!Inited) { Init(); } MQMessage msg = MQMsgCommonHelper.ToMQMessage(msgdata.BizMsgID, msgdata.MessageID, msgdata.TragetPlatform, !msgdata.IsMultiPackage, ""/*USER_CODE*/, ""); if (msgdata.IsMultiPackage) { int realLen = (from item in recBytes select item.Length).Sum(); byte[] buffer = new byte[realLen]; int offset = 0; StringBuilder arrayoffset = new StringBuilder(); foreach (var item in recBytes) { Array.Copy(item, 0, buffer, offset, item.Length); offset += item.Length; arrayoffset.AppendFormat("{0},", offset); } msg.HeaderUser.UserDefined.Add(new MQParameter<string>("ByteOffset", arrayoffset.ToString())); msg.Byte = buffer; } else { if (recBytes.Count > 0) { int realLen = recBytes[0].Length; byte[] buffer = new byte[realLen]; Array.Copy(recBytes[0], buffer, realLen); msg.Byte = buffer; } } using (TransactionScope trans = new TransactionScope(TransactionScopeOption.RequiresNew)) // 独立事务 { if (MQMsgCommonHelper.ExistedByFlowNO(msgdata.BizMsgID) > 0) { MQMsgCommonHelper.UpdateMQLogByFlowNO(msgdata, " ", "再次发送!", MsgLogState.SendSucceed, out dbexception); } else { MQMsgCommonHelper.AddMQLog(msgdata, msg.Byte, MsgLogState.SendSucceed, out dbexception); } _mqSender.SendMessage(msg); trans.Complete(); sent = true; xQuant.Log4.LogHelper.Write(xQuant.Log4.LogLevel.Debug, string.Format("<{0}>:已发送到MQ", msgdata.MessageID)); } if (_isSyncReceiver && sent) { MQMessage recmqMsg = null; bool succeed = false; MessageData resultdata = null; while (!succeed) { recmqMsg = _mqReceiver.ReceiveMessage(60 * 1000 * 1, "IP='" + MQMsgCommonHelper.GetHostIP() + "' "); if (recmqMsg == null) { MQMsgCommonHelper.UpdateMQLog(msgdata, "", "消息队列响应超时!", MsgLogState.SendSucceed, out dbexception); throw new AidException(MsgHandlerEntry.MQ_Exception_Title, "消息队列响应超时!", null); //Exception timeout = new Exception("消息队列响应超时!"); //timeout.Data.Add("MQ_TIMEOUT", "消息队列响应超时"); //throw timeout; } string error = ""; MessageData temp = PerformReceiverSync(recmqMsg, out error); succeed = temp.MessageID == msgdata.MessageID; xQuant.Log4.LogHelper.Write(xQuant.Log4.LogLevel.Debug, string.Format("<{0}>:已接收MQ返回", temp.MessageID)); if (succeed) { if (string.IsNullOrEmpty(error)) { MQMsgCommonHelper.UpdateMQLog(temp, "", "", MsgLogState.RecvSucceed, out dbexception); resultdata = temp; } else { MQMsgCommonHelper.UpdateMQLog(temp, "", error, MsgLogState.RecvFailed, out dbexception); throw new AidException(MsgHandlerEntry.MQ_Exception_Title, error, null); } } else { MQMsgCommonHelper.UpdateMQLog(temp, "", "该消息已过期!", MsgLogState.RecvOverdue, out dbexception); } } resultdata.OrgNO = msgdata.OrgNO; resultdata.MsgBizType = msgdata.MsgBizType; return resultdata; } return null; } catch (AidException aidex) { throw aidex; } catch (Exception ex) { throw new AidException(MsgHandlerEntry.MQ_Exception_Title, ex.Message, ex); } }
/// <summary> /// 把支付交易序号更新为资金流水号,只适用来账销账 /// </summary> /// <param name="msgdata"></param> /// <param name="paysn"></param> /// <param name="hostflow"></param> /// <param name="error"></param> /// <param name="state"></param> /// <param name="exception"></param> /// <returns></returns> public static int UpdateMQLog(MessageData msgdata, string paysn, string hostflow, string error, MsgLogState state, out string exception) { exception = ""; try { TTRD_SET_MSG_LOG log = new TTRD_SET_MSG_LOG(); log.GUID = msgdata.MessageID.ToString(); log.FLOW_NO = paysn; log.USER_CODE = msgdata.TellerNO; log.INS_ID = msgdata.OrgNO; //log.IS_MUL_PKG = msgdata.IsMultiPackage ? "1" : "0"; log.HOSTFLOW_NO = hostflow; log.MSGTYPE = msgdata.MsgBizType; log.PLATFORMTYPE = (int)msgdata.TragetPlatform; log.RESP_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); log.RECV_CONTENT = msgdata.CurrentRespPackage.PackageMessage; log.STATE = (int)state; if (!string.IsNullOrEmpty(error)) { log.ERRINFO = error; } int count = 0; using (TransactionScope trans = new TransactionScope(TransactionScopeOption.RequiresNew)) { TTRD_SET_MSG_LOG_Manager manager = new TTRD_SET_MSG_LOG_Manager(); count = manager.LogUpdate(log); trans.Complete(); } return count; } catch (Exception ex) { exception = ex.Message; xQuant.Log4.LogHelper.Write(xQuant.Log4.LogLevel.Error, string.Format("<MQMsgCommonHelper-UpdateMQLog> Exception:{0}; StatkTrace:{1}.", ex.Message, ex.StackTrace)); return 0; //throw ex; } }
private void buttonSet_Click(object sender, EventArgs e) { byte[] rebytes = null; //Guid messageID = MsgTransferUtility.InterBankInterestSettle("8010001", "801000", DateTime.Now, GetSettleInfo(), ref _byteCollection); Guid messageID = MsgTransferUtility.InterBankInterestSettle("8010001", "801000", DateTime.Now, GetTestSettleInfoFix(), ref rebytes); MessageData msgdata = new MessageData { MessageID = messageID, FirstTime = DateTime.Now, TragetPlatform = PlatformType.Core }; short packageid = 1; foreach (var bytes in _byteCollection) { msgdata.ReqPackageList.Enqueue(new PackageData(packageid++, bytes)); } //msgdata.ReqPackageList.Enqueue(new PackageData(1, uLongText)); msgdata.IsMultiPackage = true; DispatchMsg(msgdata); }
void OnMessageHandleAsync(MessageData msgdata) { CommunicationHandlerAsyncBase handler = null; switch (msgdata.TragetPlatform) { case PlatformType.Encrypt: handler = new EncryptCommunicationHandlerAsync(); break; case PlatformType.Payment: case PlatformType.PaymentDownload: handler = new PayCommunicationHandlerAsync(); break; case PlatformType.Core: handler = new CoreCommunicationHandlerAsync(); break; case PlatformType.FingerMarks: //handler = new MarkComminicationHandler(); break; default: handler = new NullableHandlerAsync(); break; } if (_handlerCompleteAsync != null) { //lock (_handlerCompleteAsync) { handler.MessageAsyncHandler(msgdata, _handlerCompleteAsync); } } else { _handlerCompleteAsync = new MessageHandlerCompleteAsync(MessageHandleAsync_Completed); //lock (_handlerCompleteAsync) { handler.MessageAsyncHandler(msgdata, _handlerCompleteAsync); } } }
private void buttonPrepare_Click(object sender, EventArgs e) { List<InterBankPreparedInfo> list = GetPreparedList(); if (list.Count == 0) { MessageBox.Show("选择要记账的分录!", "记账提示", MessageBoxButtons.OK); list = GetTestPreparedList(); } byte[] buffer = null; Guid messageID = MsgTransferUtility.InterBankAssetsPrepared(柜员号.Text.Trim(), 机构号.Text.Trim(), DateTime.Parse(交易日期.Text), list, ref buffer); MessageData msgdata = new MessageData { MessageID = messageID, FirstTime = DateTime.Now, TragetPlatform = PlatformType.Core }; //short packageid = 1; //foreach (var bytes in _byteCollection) //{ // msgdata.ReqPackageList.Enqueue(new PackageData(packageid++, bytes)); //} msgdata.ReqPackageList.Enqueue(new PackageData(1, buffer)); msgdata.IsMultiPackage = false; DispatchMsg(msgdata); }
private void RecordDB(String result, MessageData msg) { if (msg != null) { TTRD_AIDSYS_MSG_LOG logrow = new TTRD_AIDSYS_MSG_LOG(); logrow.M_ID = msg.MessageID.ToString(); logrow.M_ERROR = result; logrow.M_STATE = "1"; logrow.M_S_CONTENT = msg.CurrentReqPackage.PackageMessage; logrow.M_SUBID = msg.CurrentReqPackage.PackageID; logrow.M_SERIALNO = msg.BizMsgID; logrow.M_ISSINGLE = msg.IsMultiPackage ? "0" : "1"; logrow.M_PLATTYPE = (int)msg.TragetPlatform; logrow.M_SENDDATE = msg.FirstTime.ToString("yyyy-MM-dd HH:mm:ss"); TTRD_AIDSYS_MSG_LOG_Manager manager = new TTRD_AIDSYS_MSG_LOG_Manager(); manager.LogInsert(logrow); } }
private void buttonSettle_Click(object sender, EventArgs e) { byte[] rebytes = null; Guid messageID = MsgTransferUtility.InterBankInterestSettle(柜员号.Text.Trim(), 机构号.Text.Trim(), DateTime.Parse(交易日期.Text), GetTestSettleInfoFix(), ref rebytes); MessageData msgdata = new MessageData { MessageID = messageID, FirstTime = DateTime.Now, TragetPlatform = PlatformType.Core }; msgdata.ReqPackageList.Enqueue(new PackageData(1, rebytes)); DispatchMsg(msgdata); }
private MessageData ConvertMessage(MQMessage mqmsg) { if (mqmsg == null) { return null; } MessageData data = new MessageData(); string msgid = FindDefinedParameterValue(mqmsg.HeaderUser.UserDefined, "GUID"); if (!String.IsNullOrEmpty(msgid)) { data.MessageID = new Guid(msgid); } else { return null; } data.BizMsgID = mqmsg.HeaderUser.UserServiceId.Value; bool isSingle = true; string mpkgFlag = FindDefinedParameterValue(mqmsg.HeaderUser.UserDefined, "PKGTYPE"); if (!String.IsNullOrEmpty(mpkgFlag)) { if (bool.TryParse(mpkgFlag, out isSingle)) { data.IsMultiPackage = !isSingle; } else { data.IsMultiPackage = false; } } else { return null; } string platform = FindDefinedParameterValue(mqmsg.HeaderUser.UserDefined, "TARGETSYS"); if (!String.IsNullOrEmpty(platform)) { data.TragetPlatform = (PlatformType)Enum.Parse(typeof(PlatformType), platform); } else { return null; } string sourceIP = FindDefinedParameterValue(mqmsg.HeaderUser.UserDefined, "IP"); if (!String.IsNullOrEmpty(sourceIP)) { data.SourceIP = sourceIP; } data.ReqPackageList.Enqueue(new PackageData(1, mqmsg.Byte)); return data; }
private void buttonAccounting_Click(object sender, EventArgs e) { List<CoreBillRecord> list = GetAccoutingEntry(); if (list.Count == 0) { MessageBox.Show("选择要记账的分录!", "记账提示", MessageBoxButtons.OK); return; } String ouno = textBoxOrgNO.Text.TrimStart(); String tellno = textBoxTellerNO.Text.TrimStart(); String flowno = textBoxFlowNO.Text.Trim(); Guid messageID = Guid.Empty; string outmsg=""; if (rdoM2M.Checked) { CoreAcctResult acctResult = null; //messageID = MsgTransferUtility.AccountingRecord(tellno, ouno, DateTime.Now, flowno, list, ref uLongText); if (AidSysClientSyncWrapper.CoreAcctRecord(ouno, tellno, DateTime.Now, flowno, list, out acctResult, out outmsg)) { } else { MessageBox.Show(outmsg); } } else if (rdoMultiLend.Checked) { messageID = MsgTransferUtility.AcctRecordMultiLendOneLoan(tellno, ouno, DateTime.Now, flowno, list, ref uLongText); } else { messageID = MsgTransferUtility.AcctRecordMultiLoanOneLend(tellno, ouno, DateTime.Now, flowno, list, ref uLongText); } MessageData msgdata = new MessageData { MessageID = messageID, FirstTime = DateTime.Now, TragetPlatform = PlatformType.Core }; msgdata.ReqPackageList.Enqueue(new PackageData(1, uLongText)); msgdata.IsMultiPackage = false; DispatchMsg(msgdata); }