/// <summary> /// 输出应答数据的结果 /// </summary> /// <param name="lpFastMsg">应答数据包</param> /// <param name="savePath">文件保存路径</param> public static unsafe void OutPutResult(LDFastMessageAdapter lpFastMsg, string savePath) { StringBuilder outPutInfo = new StringBuilder(); outPutInfo.Append("\r\n**************************************************************"); try { if (lpFastMsg.Record != null) { int errorNo = lpFastMsg.GetInt32(LDBizTag.LDBIZ_ERROR_NO_INT); if (errorNo != 0) { return; } //打印包头信息 LDRecordAdapter headRecord = lpFastMsg.GetHeadRecord(); if (headRecord.Record != null) { string tempHeadRecord = ShowRecord(headRecord); outPutInfo.Append(tempHeadRecord); } //打印包体信息 LDGroupAdapter lpGroup = lpFastMsg.GetGroup(1000); if (lpGroup.ld == null) //非结果集 { LDRecordAdapter record = lpFastMsg.GetBizBodyRecord(); if (record.Record != null) { string tempInfo = ShowRecord(record); outPutInfo.Append(tempInfo); } } else //结果集 { int recordCount = lpGroup.GetRecordCount(); outPutInfo.AppendLine($"\r\nrow_count : {recordCount}"); for (int i = 0; i < recordCount; i++) { LDRecordAdapter record = lpGroup.GetRecord(i); if (record.Record != null) { string tempInfo = ShowRecord(record); outPutInfo.Append(tempInfo); } } } CSVFileHelper.AppendSaveScript(savePath, outPutInfo.ToString()); } } catch (Exception error) { outPutInfo.Append($"{error.Message}\r\n{error.StackTrace}"); CSVFileHelper.AppendSaveScript(savePath, outPutInfo.ToString()); } }
/// <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(); } }
/// <summary> /// 加载案例数据 /// </summary> /// <param name="filePath"></param> /// <param name="funList"></param> /// <returns></returns> public CaseFileData LoadCaseData(String filePath, List <CaseFunction> funList) { CaseFileData datas = new CaseFileData(); try { if (!File.Exists(filePath)) { return(datas); } datas.FilePath = @filePath; XElement rootXML = XDocument.Load(filePath).Element("bizmsgs"); var funsXml = rootXML.Elements("function"); foreach (var item in funsXml) { string functionid = item.Attribute("functionid").Value; string packettype = item.Attribute("packettype").Value; var CheckFun = funList.FirstOrDefault(o => o.Check == 1 && o.FunID == functionid); if (packettype.Equals("0") && CheckFun != null) { string functionname = item.Attribute("functionname").Value; CaseFunction fun = new CaseFunction() { FunID = functionid, FunType = 0, Check = 1, FunName = functionname }; //发送次数 if (item.Attribute("times") != null) { string sendTimes = item.Attribute("times").Value; int nSendTimes = 1; int.TryParse(sendTimes, out nSendTimes); fun.SendTimes = nSendTimes; } datas.Functions.Add(fun); var filedsXml = item.Elements("field"); LDsdkDefineEx.LDFastMessageAdapter fastmsg = new LDFastMessageAdapter(functionid, 0); LDRecordAdapter lpRecord = fastmsg.GetBizBodyRecord(); int iIndex = 0; foreach (var filedItem in filedsXml) { string fieldid = filedItem.Attribute("fieldid").Value; string fieldname = filedItem.Attribute("fieldname").Value; int filedtype = lpRecord.GetFieldType(iIndex); PARAMTYPE paramtype = PARAMTYPE.emFile; string value = ""; if (filedItem.Attribute("value") != null) { value = filedItem.Attribute("value").Value; } if (filedItem.Attribute("paramtype") != null) { string strparamtype = filedItem.Attribute("paramtype").Value; if ("file".Equals(strparamtype)) { paramtype = PARAMTYPE.emFile; } } CaseFiled filed = new CaseFiled() { FiledTag = int.Parse(fieldid), FiledName = fieldname, FiledValue = value, FiledType = filedtype, FiledIndex = iIndex, ParamType = paramtype }; var fileElemt = filedItem.Element("file"); if (fileElemt != null && paramtype == PARAMTYPE.emFile) { filed.ColumnName = fieldname; if (fileElemt.Attribute("columnname") != null) { filed.ColumnName = fileElemt.Attribute("columnname").Value; } if (fileElemt.Attribute("filename") != null) { filed.FileName = fileElemt.Attribute("filename").Value; CSVFile csvFile = null; if (File.Exists(filed.FileName) && !fun.AllCsvFile.TryGetValue(filed.FileName, out csvFile)) { var data = CSVFileHelper.OpenCSV(filed.FileName); if (data != null) { csvFile = new CSVFile(); csvFile.FileName = filed.FiledName; csvFile.Table = data; fun.AllCsvFile.Add(filed.FileName, csvFile); } } if (csvFile != null && string.IsNullOrWhiteSpace(csvFile.DefaultFieldName)) { csvFile.DefaultFieldName = fieldname; } } filed.SelectRow = VALUETYPE.emSameLine; if (fileElemt.Attribute("selectrow") != null) { try { string SelectRow = fileElemt.Attribute("selectrow").Value; if ("sequence".Equals(SelectRow)) { filed.SelectRow = VALUETYPE.emSequence; } else if (new Regex("same_line").Match(SelectRow).Success) { filed.SameLineColumn = SelectRow.Split('[')[1].Split(']')[0]; filed.SelectRow = VALUETYPE.emSameLine; } else if ("random".Equals(SelectRow)) { //默认("random".Equals(SelectRow)) filed.SelectRow = VALUETYPE.emRandom; } } catch (Exception) { //throw; } } } fun.Fileds.Add(filed); iIndex++; } fastmsg.FreeMsg(); } } return(datas); } catch (Exception error) { this.Dispatcher.Invoke(() => { MessageBox.Show($"{error.Message} \r\n {error.StackTrace}"); }); return(datas); } }