Example #1
0
        private String GetParamValue(CaseFunction funitem, CaseFiled filed)
        {
            String Value = filed.FiledValue;

            try
            {
                if (filed.ParamType == PARAMTYPE.emFile)
                {
                    if (File.Exists(filed.FileName))
                    {
                        CSVFile csfFile = null;
                        if (funitem.AllCsvFile.TryGetValue(filed.FileName, out csfFile))
                        {
                            DataTable data = csfFile.Table;
                            if (filed.SelectRow == VALUETYPE.emRandom && data != null && data.Rows.Count > 0)
                            {
                                long   tick = DateTime.Now.Ticks;
                                Random ran  = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
                                csfFile.CurrFileRowIndex = ran.Next(data.Rows.Count);
                                Value = data.Rows[csfFile.CurrFileRowIndex][filed.ColumnName].ToString().Replace("\"", "");
                            }
                            else if (filed.SelectRow == VALUETYPE.emSequence && data.Rows.Count > 0)
                            {
                                if (data.Rows.Count > csfFile.CurrFileRowIndex + 1)
                                {
                                    csfFile.CurrFileRowIndex++;
                                    Value = data.Rows[csfFile.CurrFileRowIndex][filed.ColumnName].ToString().Replace("\"", "");
                                }
                                else
                                {
                                    csfFile.CurrFileRowIndex = 0;;
                                    Value = data.Rows[csfFile.CurrFileRowIndex][filed.ColumnName].ToString().Replace("\"", "");
                                }
                            }
                            else if (filed.SelectRow == VALUETYPE.emSameLine && csfFile.CurrFileRowIndex >= 0 && data.Rows.Count > 0)
                            {
                                Value = data.Rows[csfFile.CurrFileRowIndex][filed.ColumnName].ToString().Replace("\"", "");
                            }
                        }
                    }
                }
                if (filed.FiledTag == 1674)
                {
                    Value = funitem.FunID;
                }
                return(Value);
            }
            catch (Exception error)
            {
                this.Dispatcher.Invoke(() => { MessageBox.Show($"{error.Message} \r\n {error.StackTrace}"); });
                return("error");
            }
        }
Example #2
0
        /// <summary>
        /// 加载案例详细脚本信息
        /// </summary>
        /// <param name="filePath">案例脚本保存路径</param>
        /// <returns></returns>
        private List <CaseFunction> LoadCaseFunction(String filePath)
        {
            List <CaseFunction> list = new List <CaseFunction>();

            try
            {
                if (!File.Exists(filePath))
                {
                    return(list);
                }
                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;
                    if (packettype.Equals("0"))
                    {
                        string       functionname = item.Attribute("functionname").Value;
                        CaseFunction fun          = new CaseFunction()
                        {
                            FunID   = functionid,
                            FunType = 0,
                            Check   = 1,
                            FunName = functionname
                        };

                        list.Add(fun);
                    }
                }
                return(list);
            }
            catch (Exception error)
            {
                this.Dispatcher.Invoke(() => { MessageBox.Show(error.Message + "\r\n" + error.StackTrace, "络町"); });
                return(list);
            }
        }
Example #3
0
        /// <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);
            }
        }