示例#1
0
        /// <summary>
        /// 发送请求数据包的方法
        /// </summary>
        /// <param name="fun">已经构建好的请求应答包</param>
        /// <param name="defaultTable">对应defaultvalue.xlsx文件,取默认值用的</param>
        private unsafe void SendFastMsgFun(BizFunction fun, DataTable defaultTable)
        {
            LDsdkDefineEx.LDFastMessageAdapter fastmsg = new LDFastMessageAdapter(fun.FunctonId, 0);
            LDRecordAdapter lpRecord = fastmsg.GetBizBodyRecord();
            //获取字段总数量
            int iFieldCount = lpRecord.GetFieldCount();
            int iIndex      = 0;

            for (iIndex = 0; iIndex < iFieldCount; iIndex++)
            {
                //取得字段类型
                int fieldtype = lpRecord.GetFieldType(iIndex);
                //取得字段名称
                string fieldName = lpRecord.GetFieldNamebyIndex(iIndex);

                BizRequestField bizField   = fun.ReqFields.FirstOrDefault(o => o.FieldName.Equals(fieldName));
                String          fieldValue = "";
                if (bizField != null)
                {
                    fieldValue = bizField.FieldValue; //取得入参的值
                }
                if (string.IsNullOrEmpty(fieldValue)) //如果没有手动赋值,则去默认值
                {
                    fieldValue = UtilTool.GetDefaultValue(defaultTable, fieldName);
                }
                if ("func_code".Equals(fieldName))  //如果字段名称是func_code,则把功能号作为值赋给字段
                {
                    fieldValue = fun.FunctonId;
                }
                UtilTool.SetFastMsgValue(fastmsg, fieldtype, fieldValue, iIndex);
            }
            //应答包
            LDFastMessageAdapter outFast = null;
            int nRet = (int)ConnectionManager.Instance.CurConnection.Connect.SendAndReceive(fun.FunctonId, fastmsg, ref outFast, 5000);

            fastmsg.FreeMsg();
            /**********************************开始对应答包进行处理**************************************/
            if (nRet < 0)
            {
                LogHelper.Logger.Error(fun.FunctonId + "发送失败,错误号=" + nRet);
                PrintHelper.Print.AppendLine(fun.FunctonId + "发送失败,错误号=" + nRet);
            }
            if (nRet >= 0 && outFast.Record != null)
            {
                int iErrorNo = outFast.GetInt32(LDSdkTag.LDTAG_ERRORNO);
                if (iErrorNo != 0)
                {
                    LogHelper.Logger.Error("SystemErrorInfo=" + outFast.GetString(LDSdkTag.LDTAG_ERRORINFO));
                }
                else
                {
                    //将回归脚本的应答包信息写入文件
                    //string savePath = Environment.CurrentDirectory + @"\RegressionTestResult.txt";//文件保存路径
                    //LogAnswerPackageInfo.OutPutResult(outFast, savePath);

                    if (fun.AnswerFlag)
                    {
                        //获取应答包包体数据
                        LDRecordAdapter lpOutRecord = outFast.GetBizBodyRecord();
                        //获取应答包字段总数
                        int iAnswerFieldCount = lpOutRecord.GetFieldCount();
                        //遍历获取应答包字段的 出参=值 信息,并塞入到对应的请求应答包里面去 BizFunction fun
                        int iAnswerIndex = 0;
                        for (iAnswerIndex = 0; iAnswerIndex < iAnswerFieldCount; iAnswerIndex++)
                        {
                            //获取出参字段名
                            string fieldName = lpOutRecord.GetFieldNamebyIndex(iAnswerIndex);
                            //获取出参字段类型
                            int fieldType = lpOutRecord.GetFieldType(iAnswerIndex);
                            //只把会用到的字段塞入
                            BizAnswerField bizField = fun.Answer.RspFields.FirstOrDefault(o => o.FieldName.Equals(fieldName));
                            if (bizField != null)
                            {
                                bizField.FieldValue = UtilTool.GetFastMsgValue(outFast, fieldType, iAnswerIndex);
                                bizField.FieldType  = fieldType;
                            }
                        }
                    }
                }
                outFast.FreeMsg();
            }
        }
示例#2
0
        /// <summary>
        /// 死循环处理队列里的应答包
        /// </summary>
        private void DealRespPackage()
        {
            Task.Run(
                () =>
            {
                while (true)
                {
                    RespDataPackageModel RDP = new RespDataPackageModel();
                    if (RespDataPackageModel.DataQueue.TryDequeue(out RDP))
                    {
                        Task.Run(
                            () =>
                        {
                            int hSend = RDP.hSend;
                            LDFastMessageAdapter lpFastMsg = RDP.lpFastMsg;

                            DateTime timeStamp = DateTime.Now;
                            ReqDTO req         = null;
                            lock (ReqLock)
                            {
                                req = ReqAllList.FirstOrDefault(o => o.SendID == hSend);
                                ReqAllList.Remove(req);
                            }
                            if (req != null && lpFastMsg != null)
                            {
                                Interlocked.Increment(ref req.CaseData.RecCount);        //递增应答数量
                                if (req.CaseData.SendCount - req.CaseData.RecCount <= req.CaseData.DownStage)
                                {
                                    req.CaseData.ResetEvent.Set();
                                }
                                //功能号
                                string strFunCode = lpFastMsg.GetString(LDSdkTag.LDTAG_FUNCID);
                                /***********************************郑建翔新加部分,用于计算应答频率***************************************/
                                lock (lockFlag)
                                {
                                    //如果集合中不存这个功能号则添加
                                    if (ReplyRateInfos.Count(i => i.functionId == strFunCode) == 0)
                                    {
                                        DateTime startTime = DateTime.Now;
                                        this.Dispatcher.Invoke(() => ReplyRateInfos.Add(new ReplyRateModel(strFunCode, startTime)));
                                        /*****************************接收到每个功能号的第一条应答时,保存应答信息**************************/
                                        //文件保存路径
                                        string savePath = Environment.CurrentDirectory + @"\ScriptOutPut.txt";
                                        LogAnswerPackageInfo.OutPutResult(lpFastMsg, savePath);
                                    }
                                    else
                                    {
                                        //如果集合中已经存在这个功能号,开始更新并计算数据
                                        ReplyRateModel replyInfo = ReplyRateInfos.FirstOrDefault(i => i.functionId == strFunCode);
                                        replyInfo.timeStamp      = timeStamp;
                                        replyInfo.replyCount++;
                                    }
                                }
                                /*******************************************修改结束*********************************************************/


                                int iErrorNo = lpFastMsg.GetInt32(LDSdkTag.LDTAG_ERRORNO);
                                // LogHelper.Logger.Info("系统错误号:" + iErrorNo);
                                if (iErrorNo != 0)
                                {
                                    //如果是中间件返回的错误
                                    // Interlocked.Increment(ref req.CaseData.RecFailCount);//递增应答失败数量
                                }
                                else
                                {
                                    string strErrorCode = lpFastMsg.GetString(LDBizTag.LDBIZ_ERROR_CODE_STR);
                                    //LogHelper.Logger.Info("业务错误号:" + strErrorCode);
                                    Interlocked.Increment(ref req.CaseData.RecOkCount);        //递增应答成功数量
                                    if (!"0".Equals(strErrorCode))
                                    {
                                        Interlocked.Increment(ref req.CaseData.RecFailCount);        //递增应答失败数量

                                        string strErrorInfo   = lpFastMsg.GetString(LDBizTag.LDBIZ_ERROR_INFO_STR);
                                        string strErrorPrompt = lpFastMsg.GetString(LDBizTag.LDBIZ_ERROR_PROMPT_STR);
                                        string logInfo        = string.Format("功能号[{0}],errorCode[{1}],errorinfo[{2}],errorprompt[{3}]", strFunCode, strErrorCode, strErrorInfo, strErrorPrompt);
                                        LogHelper.Logger.Error(logInfo);
                                    }
                                    //else
                                    //{
                                    //    Interlocked.Increment(ref req.CaseData.RecOkCount);//递增应答成功数量
                                    //}
                                }
                            }
                            if (lpFastMsg != null)
                            {
                                lpFastMsg.FreeMsg();
                            }
                        }
                            );
                    }
                    //else
                    //{
                    //    pauseFlag.WaitOne(10);
                    //}
                }
            }
                );
        }