public new static MyMySqlExecutionContent GetRunContent(XmlNode yourContentNode) { MyMySqlExecutionContent myRunContent = new MyMySqlExecutionContent(); if (yourContentNode != null) { if (yourContentNode.Attributes["protocol"] != null && yourContentNode.Attributes["actuator"] != null) { //Content try { myRunContent.caseProtocol = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), yourContentNode.Attributes["protocol"].Value); } catch { myRunContent.errorMessage = "Error :error protocol in Content"; return(myRunContent); } myRunContent.caseActuator = yourContentNode.Attributes["actuator"].Value; XmlNode nowSqlNode = yourContentNode["SqlCmd"]; if (nowSqlNode != null) { if (nowSqlNode.Attributes["row"] != null && nowSqlNode.Attributes["column"] != null) { myRunContent.isPosition = true; if (!(int.TryParse(nowSqlNode.Attributes["row"].Value, out myRunContent.rowIndex) && int.TryParse(nowSqlNode.Attributes["column"].Value, out myRunContent.columnIndex))) { myRunContent.errorMessage = "Error :yourContentNode is error wirh [row] or [column] attribute"; } else { if (myRunContent.rowIndex < 0 || myRunContent.columnIndex < 0) { myRunContent.errorMessage = "Error :yourContentNode is error wirh [row] or [column] attribute"; } } } myRunContent.sqlContent = CaseTool.GetXmlParametContent(nowSqlNode); } else { myRunContent.errorMessage = "Error :can not find any SqlCmd "; } } else { myRunContent.errorMessage = "Error :can not find protocol or actuator in Content "; } } else { myRunContent.errorMessage = "Error :yourContentNode is null"; } return(myRunContent); }
public new static MySshExecutionContent GetRunContent(XmlNode yourContentNode) { MySshExecutionContent myRunContent = new MySshExecutionContent(); if (yourContentNode != null) { if (yourContentNode.Attributes["protocol"] != null && yourContentNode.Attributes["actuator"] != null) { //Content try { myRunContent.caseProtocol = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), yourContentNode.Attributes["protocol"].Value); } catch { myRunContent.errorMessage = "Error :error protocol in Content"; return(myRunContent); } myRunContent.caseActuator = yourContentNode.Attributes["actuator"].Value; XmlNode nowSshNode = yourContentNode["SshCmd"]; if (nowSshNode != null) { myRunContent.sshContent = CaseTool.GetXmlParametContent(nowSshNode); } else { myRunContent.errorMessage = "Error :can not find any SshCmd "; } } else { myRunContent.errorMessage = "Error :can not find protocol or actuator in Content "; } } else { myRunContent.errorMessage = "Error :yourContentNode is null"; } return(myRunContent); }
private bool AnalysisXmlCase(string myCasePath, CaseActionActuator caseActuator, Hashtable checkDataHt, bool isWithSouseXml, out string errorMessage, out List <string> loadErrorList) { bool tempIsScriptRunTimeDeal = false; errorMessage = null; loadErrorList = new List <string>(); CaseFileXmlAnalysis xmlAnalysis = new CaseFileXmlAnalysis(); if (caseActuator == null) { return(false); } if (caseActuator.Runstate != CaseActuatorState.Stop) { errorMessage = "The TestCase not stop"; return(false); } if (!File.Exists(myCasePath)) { errorMessage = "用例文件不存在,请重新选择"; return(false); } if (!xmlAnalysis.LoadFile(myCasePath)) { errorMessage = "该脚本数据格式错误,请修正错误。详情请查看错误日志"; return(false); } XmlNodeList myCaseProject = xmlAnalysis.xml.ChildNodes[1].ChildNodes; #region check case data if (checkDataHt != null) { foreach (DictionaryEntry de in checkDataHt) { string tempStr = CaseTool.CheckCase(xmlAnalysis.xml.ChildNodes[1], (string)de.Key, (string[])de.Value); if (tempStr != "") { errorMessage = tempStr; return(false); } } } #endregion Dictionary <int, Dictionary <int, CaseCell> > myProjectCaseDictionary = new Dictionary <int, Dictionary <int, CaseCell> >(); caseActuator.DisconnectExecutionDevice(); caseActuator.Dispose(); ProjctCollection myProjctCollection = new ProjctCollection(); try { #region Project analyze foreach (XmlNode tempNode in myCaseProject) { myCaseLaodInfo tempProjectLoadInfo = MyCaseScriptAnalysisEngine.GetCaseLoadInfo(tempNode); string thisErrorTitle = "Project ID:" + tempProjectLoadInfo.id; if (tempProjectLoadInfo.ErrorMessage != "") { loadErrorList.Add(string.Format("【{1}】:{0}", tempProjectLoadInfo.ErrorMessage, thisErrorTitle)); } if (tempProjectLoadInfo.caseType == CaseType.ScriptRunTime) { //deal with ScriptRunTime if (!tempIsScriptRunTimeDeal) { caseActuator.LoadScriptRunTime(tempNode); tempIsScriptRunTimeDeal = true; } else { thisErrorTitle = "ScriptRunTime"; loadErrorList.Add(string.Format("【{1}】:{0}", "find another ScriptRunTime ,ScriptRunTime is unique so it will be skip", thisErrorTitle)); } continue; } if (tempProjectLoadInfo.caseType != CaseType.Project) { loadErrorList.Add(string.Format("【{1}】:{0}", "not legal Project ,it will be skip", "legal")); continue; } #region deal this Project CaseCell tempProjctCell = new CaseCell(tempProjectLoadInfo.caseType, tempNode, null); myProjctCollection.Add(tempProjctCell); Dictionary <int, CaseCell> tempCaseDictionary = new Dictionary <int, CaseCell>(); if (myProjectCaseDictionary.ContainsKey(tempProjectLoadInfo.id)) { loadErrorList.Add(string.Format("【{1}】:{0}", "find the same project id in this file ,it will make [Goto] abnormal", thisErrorTitle)); } else { myProjectCaseDictionary.Add(tempProjectLoadInfo.id, tempCaseDictionary); } //myTargetCaseList 将包含当前project或repeat集合元素 List <KeyValuePair <CaseCell, XmlNode> > myTargetCaseList = new List <KeyValuePair <CaseCell, XmlNode> >(); myTargetCaseList.Add(new KeyValuePair <CaseCell, XmlNode>(tempProjctCell, tempNode)); while (myTargetCaseList.Count > 0) { //Case analyze foreach (XmlNode tempChildNode in myTargetCaseList[0].Value) { //load Show Info myCaseLaodInfo tempCaseLoadInfo = MyCaseScriptAnalysisEngine.GetCaseLoadInfo(tempChildNode); thisErrorTitle = "Case ID:" + tempCaseLoadInfo.id; if (tempCaseLoadInfo.ErrorMessage != "") { loadErrorList.Add(string.Format("【{1}】:{0}", tempCaseLoadInfo.ErrorMessage, thisErrorTitle)); loadErrorList.Add(string.Format("【{1}】:{0}", "this error can not be repair so drop it", thisErrorTitle)); } else { if (tempCaseLoadInfo.caseType == CaseType.Case) { //load Run Data var tempCaseRunData = MyCaseScriptAnalysisEngine.GetCaseRunData(tempChildNode); if (tempCaseRunData.errorMessages != null) { foreach (string tempErrorMes in tempCaseRunData.errorMessages) { loadErrorList.Add(string.Format("【{1}】:{0}", tempErrorMes, thisErrorTitle)); } } CaseCell tempChildCell = new CaseCell(tempCaseLoadInfo.caseType, tempChildNode, tempCaseRunData); if (tempCaseDictionary.ContainsKey(tempCaseLoadInfo.id)) { loadErrorList.Add(string.Format("【{1}】:{0}", "find the same case id in this project ,it will make [Goto] abnormal", thisErrorTitle)); } else { tempCaseDictionary.Add(tempCaseLoadInfo.id, tempChildCell); } myTargetCaseList[0].Key.Add(tempChildCell); } else if (tempCaseLoadInfo.caseType == CaseType.Repeat) { CaseCell tempChildCell = new CaseCell(tempCaseLoadInfo.caseType, tempChildNode, null); myTargetCaseList[0].Key.Add(tempChildCell); myTargetCaseList.Add(new KeyValuePair <CaseCell, XmlNode>(tempChildCell, tempChildNode)); } else { //it will cant be project and if it is unknow i will not show it loadErrorList.Add(string.Format("【{1}】:{0}", "find unkown case so drop it", thisErrorTitle)); } } } myTargetCaseList.Remove(myTargetCaseList[0]); } #endregion } #endregion if (!tempIsScriptRunTimeDeal) { loadErrorList.Add(string.Format("【{1}】:{0}", "ScriptRunTime is not find ", "ScriptRunTime")); errorMessage = "ScriptRunTime is not find ,the case will cannot run"; return(false); } else { caseActuator.SetCaseRunTime(myProjectCaseDictionary, myProjctCollection); //启动数据呈现 return(true); } } //严重错误 catch (Exception ex) { ErrorLog.PutInLog(ex); errorMessage = ex.Message; caseActuator.DisconnectExecutionDevice(); caseActuator.Dispose(); return(false); } }
public new static MyBasicHttpExecutionContent GetRunContent(XmlNode yourContentNode) { MyBasicHttpExecutionContent myRunContent = new MyBasicHttpExecutionContent(); if (yourContentNode != null) { if (yourContentNode.Attributes["protocol"] != null && yourContentNode.Attributes["actuator"] != null) { //Content try { myRunContent.caseProtocol = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), yourContentNode.Attributes["protocol"].Value); } catch { myRunContent.errorMessage = "Error :error protocol in Content"; return(myRunContent); } myRunContent.caseActuator = yourContentNode.Attributes["actuator"].Value; //Uri XmlNode tempUriDataNode = yourContentNode["Uri"]; if (tempUriDataNode != null) { if (tempUriDataNode.Attributes["httpMethod"] != null) { myRunContent.httpMethod = tempUriDataNode.Attributes["httpMethod"].Value; } else { myRunContent.httpMethod = "GET"; } myRunContent.httpUri = CaseTool.GetXmlParametContent(tempUriDataNode); } else { myRunContent.errorMessage = "Error :http uri (this element is necessary)"; return(myRunContent); } //HttpHeads XmlNode tempHttpHeadsDataNode = yourContentNode["Heads"]; if (tempHttpHeadsDataNode != null) { if (tempHttpHeadsDataNode.HasChildNodes) { foreach (XmlNode headNode in tempHttpHeadsDataNode.ChildNodes) { if (headNode.Attributes["name"] != null) { myRunContent.httpHeads.Add(new KeyValuePair <string, caseParameterizationContent>(headNode.Attributes["name"].Value, CaseTool.GetXmlParametContent(headNode))); } else { myRunContent.errorMessage = "Error :can not find http Head name in heads"; } } } } //HttpBody XmlNode tempHttpBodyDataNode = yourContentNode["Body"]; if (tempHttpHeadsDataNode != null) { myRunContent.httpBody = CaseTool.GetXmlParametContent(tempHttpBodyDataNode); } //AisleConfig if (yourContentNode["AisleConfig"] != null) { myRunContent.myHttpAisleConfig.httpDataDown = CaseTool.GetXmlParametContent(yourContentNode["AisleConfig"], "HttpDataDown"); } //HttpMultipart XmlNode tempHttpMultipartNode = yourContentNode["HttpMultipart"]; if (tempHttpMultipartNode != null) { if (tempHttpMultipartNode.HasChildNodes) { foreach (XmlNode multipartNode in tempHttpMultipartNode.ChildNodes) { HttpMultipart hmp = new HttpMultipart(); if (multipartNode.Name == "MultipartData") { hmp.isFile = false; hmp.fileData = multipartNode.InnerText; } else if (multipartNode.Name == "MultipartFile") { hmp.isFile = true; hmp.fileData = CaseTool.GetFullPath(multipartNode.InnerText, MyConfiguration.CaseFilePath); } else { continue; } hmp.name = CaseTool.GetXmlAttributeVauleEx(multipartNode, "name", null); hmp.fileName = CaseTool.GetXmlAttributeVauleEx(multipartNode, "filename", null); myRunContent.myMultipartList.Add(hmp); } } } } else { myRunContent.errorMessage = "Error :can not find protocol or actuator in Content "; } } else { myRunContent.errorMessage = "Error :yourContentNode is null"; } return(myRunContent); }
public MyExecutionDeviceResult ExecutionDeviceRun(ICaseExecutionContent yourExecutionContent, CaseActionActuator.delegateGetExecutiveData yourExecutiveDelegate, string sender, ActuatorStaticDataCollection yourActuatorStaticDataCollection, int caseId) { MyExecutionDeviceResult myResult = new MyExecutionDeviceResult(); myResult.staticDataResultCollection = new System.Collections.Specialized.NameValueCollection(); if (yourExecutionContent.MyCaseProtocol == CaseProtocol.http) { //在调用该函数前保证nowExecutionContent.ErrorMessage为空,且as一定成功 MyBasicHttpExecutionContent nowExecutionContent = yourExecutionContent as MyBasicHttpExecutionContent; myResult.caseProtocol = CaseProtocol.http; myResult.caseTarget = nowExecutionContent.MyExecutionTarget; string tempError; string httpUri; string httpBody = null; List <KeyValuePair <string, string> > httpHeads = null; httpUri = nowExecutionContent.httpUri.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); if (httpUri.StartsWith("@")) { httpUri = myExecutionDeviceInfo.default_url + httpUri.Remove(0, 1); } if (nowExecutionContent.httpBody.IsFilled()) { httpBody = nowExecutionContent.httpBody.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); } if (nowExecutionContent.httpHeads.Count > 0) { httpHeads = new List <KeyValuePair <string, string> >(); foreach (var tempHead in nowExecutionContent.httpHeads) { httpHeads.Add(new KeyValuePair <string, string>(tempHead.Key, tempHead.Value.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError))); } } //report Executive Data if (yourExecutiveDelegate != null) { if (httpBody != null) { yourExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("【ID:{0}】[http]Executive···\r\n{1}\r\n{2}", caseId, httpUri, httpBody)); } else { yourExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("【ID:{0}】[http]Executive···\r\n{1}", caseId, httpUri)); } } //Start Http if (nowExecutionContent.myMultipartList.Count > 0) { List <MyCommonHelper.NetHelper.MyWebTool.HttpMultipartDate> myMultiparts = new List <MyCommonHelper.NetHelper.MyWebTool.HttpMultipartDate>(); foreach (HttpMultipart tempPt in nowExecutionContent.myMultipartList) { if (tempPt.IsFilled()) { myMultiparts.Add(new MyCommonHelper.NetHelper.MyWebTool.HttpMultipartDate(tempPt.name, tempPt.fileName, null, tempPt.isFile, tempPt.fileData)); } } httpClient.HttpPostData(httpUri, httpHeads, httpBody, myMultiparts, null, MyConfiguration.PostFileTimeOut, null, myResult); } else if (nowExecutionContent.myHttpAisleConfig.httpDataDown.IsFilled()) { httpClient.SendData(httpUri, httpBody, nowExecutionContent.httpMethod, httpHeads, myResult, CaseTool.GetFullPath(nowExecutionContent.myHttpAisleConfig.httpDataDown.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError), MyConfiguration.CaseFilePath)); } else { httpClient.SendData(httpUri, httpBody, nowExecutionContent.httpMethod, httpHeads, myResult); } if (tempError != null) { myResult.additionalError = ("error:" + tempError); } } else { myResult.additionalError = ("error:your CaseProtocol is not Matching RunTimeActuator"); myResult.backContent = "error:your CaseProtocol is not Matching RunTimeActuator"; } return(myResult); }
public new static MyConsoleExecutionContent GetRunContent(XmlNode yourContentNode) { MyConsoleExecutionContent myRunContent = new MyConsoleExecutionContent(); if (yourContentNode != null) { if (yourContentNode.Attributes["protocol"] != null && yourContentNode.Attributes["actuator"] != null) { //Content try { myRunContent.caseProtocol = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), yourContentNode.Attributes["protocol"].Value); } catch { myRunContent.errorMessage = "Error :error protocol in Content"; return(myRunContent); } myRunContent.caseActuator = yourContentNode.Attributes["actuator"].Value; //Show XmlNode tempShowDataNode = yourContentNode["Show"]; if (tempShowDataNode != null) { myRunContent.showContent = CaseTool.GetXmlParametContent(tempShowDataNode); } else { myRunContent.errorMessage = "Error :can not find [Show] node (this element is necessary)"; return(myRunContent); } //ConsoleTask #region ConsoleTask XmlNode tempConsoleTaskDataNode = yourContentNode["ConsoleTask"]; if (tempConsoleTaskDataNode != null) { if (tempConsoleTaskDataNode.HasChildNodes) { foreach (XmlNode taskNode in tempConsoleTaskDataNode.ChildNodes) { if (taskNode.Name == "Set") { if (taskNode.Attributes["name"] != null) { myRunContent.staticDataSetList.Add(new KeyValuePair <string, caseParameterizationContent>(taskNode.Attributes["name"].Value, CaseTool.GetXmlParametContent(taskNode))); } else { myRunContent.errorMessage = "Error :can not find name in [Set] node"; return(myRunContent); } } else if (taskNode.Name == "Add") { if (taskNode.Attributes["name"] != null && taskNode.Attributes["type"] != null) { CaseStaticDataType nowType; if (Enum.TryParse <CaseStaticDataType>("caseStaticData_" + taskNode.Attributes["type"].Value, out nowType)) { myRunContent.staticDataAddList.Add(new MyConsoleExecutionContent.StaticDataAdd(nowType, taskNode.Attributes["name"].Value, CaseTool.GetXmlParametContent(taskNode))); } else { myRunContent.errorMessage = string.Format("Error : find the unkonw type in [ConsoleTask] with {0} when Add", taskNode.Attributes["type"].Value); return(myRunContent); } } else { myRunContent.errorMessage = "Error :can not find name or type in [Add] node"; return(myRunContent); } } else if (taskNode.Name == "Del") { bool isRegex = false; if (taskNode.Attributes["isRegex"] != null) { if (taskNode.Attributes["isRegex"].Value == "true") { isRegex = true; } } myRunContent.staticDataDelList.Add(new KeyValuePair <bool, caseParameterizationContent>(isRegex, CaseTool.GetXmlParametContent(taskNode))); } else { myRunContent.errorMessage = "find unknow node in [ConsoleTask]"; return(myRunContent); } } } } #endregion } else { myRunContent.errorMessage = "Error :can not find protocol or actuator in Content "; } } else { myRunContent.errorMessage = "Error :yourContentNode is null"; } return(myRunContent); }
/// <summary> /// 获取运算后的值,掉用此法的该版本的重载将会改变涉及到的staticData数据的游标 /// </summary> /// <param name="yourActuatorStaticDataCollection">可用staticData集合</param> /// <param name="yourDataResultCollection">返回对所有staticData数据运算后的结果列表</param> /// <param name="errorMessage">错误消息(如果没有错误则为null)</param> /// <returns>运算结果</returns> public string getTargetContentData(ActuatorStaticDataCollection yourActuatorStaticDataCollection, NameValueCollection yourDataResultCollection, out string errorMessage) { string myTargetContentData = contentData; errorMessage = null; if (hasParameter) { myTargetContentData = CaseTool.GetCurrentParametersData(contentData, MyConfiguration.ParametersDataSplitStr, yourActuatorStaticDataCollection, yourDataResultCollection, out errorMessage); } if (encodetype != ParameterizationContentEncodingType.encode_default) { switch (encodetype) { //base64 case ParameterizationContentEncodingType.encode_base64: myTargetContentData = Convert.ToBase64String(Encoding.UTF8.GetBytes(myTargetContentData)); break; case ParameterizationContentEncodingType.decode_base64: try { myTargetContentData = Encoding.UTF8.GetString(Convert.FromBase64String(myTargetContentData)); } catch (Exception ex) { myTargetContentData = "ContentEncoding Error:" + ex.Message; } break; //hex 16 case ParameterizationContentEncodingType.encode_hex16: myTargetContentData = MyCommonHelper.MyEncryption.StringToHexString(myTargetContentData); break; case ParameterizationContentEncodingType.decode_hex16: try { byte[] nowBytes = MyCommonHelper.MyEncryption.HexStringToByte(myTargetContentData, MyEncryption.HexaDecimal.hex16, MyEncryption.ShowHexMode.space); myTargetContentData = Encoding.UTF8.GetString(nowBytes); } catch (Exception ex) { myTargetContentData = "ContentEncoding Error:" + ex.Message; } break; //hex 2 case ParameterizationContentEncodingType.encode_hex2: myTargetContentData = MyCommonHelper.MyEncryption.StringToHexString(myTargetContentData, Encoding.UTF8, MyEncryption.HexaDecimal.hex2, MyEncryption.ShowHexMode.space); break; case ParameterizationContentEncodingType.decode_hex2: try { byte[] nowBytes = MyCommonHelper.MyEncryption.HexStringToByte(myTargetContentData, MyEncryption.HexaDecimal.hex2, MyEncryption.ShowHexMode.space); myTargetContentData = Encoding.UTF8.GetString(nowBytes); } catch (Exception ex) { myTargetContentData = "ContentEncoding Error:" + ex.Message; } break; default: errorMessage = "[getTargetContentData] unknow or not supported this encodetype"; break; } } return(myTargetContentData); }
/// <summary> /// i will get a myRunCaseData that will give caseActionActuator from XmlNode /// </summary> /// <param name="yourRunNode">your XmlNode</param> /// <returns>myRunCaseData you want</returns> public static MyRunCaseData <ICaseExecutionContent> GetCaseRunData(XmlNode sourceNode) { MyRunCaseData <ICaseExecutionContent> myCaseData = new MyRunCaseData <ICaseExecutionContent>(); CaseProtocol contentProtocol = CaseProtocol.unknownProtocol; if (sourceNode == null) { myCaseData.AddErrorMessage("Error :source data is null"); } else { if (sourceNode.Name == "Case") { #region Basic information if (sourceNode.Attributes["id"] == null) { myCaseData.AddErrorMessage("Error :not find the ID"); } else { try { myCaseData.id = int.Parse(sourceNode.Attributes["id"].Value); } catch (Exception) { myCaseData.AddErrorMessage("Error :find the error ID"); } } myCaseData.name = CaseTool.GetXmlAttributeVauleEx(sourceNode, "remark", "NULL"); #endregion #region Content //XmlNode tempCaseContent = sourceNode.SelectSingleNode("Content"); //sourceNode["Content"] 具有同样的功能 XmlNode tempCaseContent = sourceNode["Content"]; if (tempCaseContent == null) { myCaseData.AddErrorMessage("Error :can not find Content"); } else { if (tempCaseContent.Attributes["protocol"] != null && tempCaseContent.Attributes["actuator"] != null) { try { contentProtocol = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), tempCaseContent.Attributes["protocol"].Value); myCaseData.contentProtocol = contentProtocol; } catch { myCaseData.AddErrorMessage("Error :error protocol in Content"); } switch (contentProtocol) { case CaseProtocol.console: myCaseData.testContent = CaseProtocolExecutionForConsole.GetRunContent(tempCaseContent); break; case CaseProtocol.activeMQ: myCaseData.testContent = CaseProtocolExecutionForActiveMQ.GetRunContent(tempCaseContent); break; case CaseProtocol.mysql: myCaseData.testContent = CaseProtocolExecutionForMysql.GetRunContent(tempCaseContent); break; case CaseProtocol.ssh: myCaseData.testContent = CaseProtocolExecutionForSsh.GetRunContent(tempCaseContent); break; case CaseProtocol.vanelife_http: myCaseData.testContent = CaseProtocolExecutionForVanelife_http.GetRunContent(tempCaseContent); break; case CaseProtocol.http: myCaseData.testContent = CaseProtocolExecutionForHttp.GetRunContent(tempCaseContent); break; case CaseProtocol.tcp: myCaseData.testContent = CaseProtocolExecutionForTcp.GetRunContent(tempCaseContent); break; case CaseProtocol.telnet: myCaseData.testContent = CaseProtocolExecutionForTelnet.GetRunContent(tempCaseContent); break; case CaseProtocol.com: myCaseData.testContent = CaseProtocolExecutionForCom.GetRunContent(tempCaseContent); break; case CaseProtocol.vanelife_comm: myCaseData.AddErrorMessage("Error :this protocol not supported for now"); break; case CaseProtocol.vanelife_tcp: myCaseData.AddErrorMessage("Error :this protocol not supported for now"); break; case CaseProtocol.vanelife_telnet: myCaseData.AddErrorMessage("Error :this protocol not supported for now"); break; case CaseProtocol.defaultProtocol: myCaseData.AddErrorMessage("Error :this protocol not supported for now"); break; default: myCaseData.AddErrorMessage("Error :this protocol not supported for now"); break; } if (myCaseData.testContent != null) { if (myCaseData.testContent.MyErrorMessage != null) //将testContent错误移入MyRunCaseData,执行case时会检查MyRunCaseData中的错误 { myCaseData.AddErrorMessage("Error :the Content not analyticaled Because:" + myCaseData.testContent.MyErrorMessage); //return myCaseData; } } } else { myCaseData.AddErrorMessage("Error :can not find protocol or actuator in Content"); } } #endregion #region Expect XmlNode tempCaseExpect = sourceNode["Expect"]; if (tempCaseExpect == null) { myCaseData.caseExpectInfo.myExpectType = CaseExpectType.judge_default; } else { if (tempCaseExpect.Attributes["method"] != null) { try { myCaseData.caseExpectInfo.myExpectType = (CaseExpectType)Enum.Parse(typeof(CaseExpectType), "judge_" + tempCaseExpect.Attributes["method"].Value); } catch { myCaseData.AddErrorMessage("Error :find error CaseExpectType in Expect"); myCaseData.caseExpectInfo.myExpectType = CaseExpectType.judge_default; } } else { myCaseData.caseExpectInfo.myExpectType = CaseExpectType.judge_is; } myCaseData.caseExpectInfo.myExpectContent = CaseTool.GetXmlParametContent(tempCaseExpect); } #endregion #region Action XmlNode tempCaseAction = sourceNode["Action"]; if (tempCaseAction != null) { if (tempCaseAction.HasChildNodes) { foreach (XmlNode tempNode in tempCaseAction.ChildNodes) { CaseResult tempResult = CaseResult.Unknow; CaseAction tempAction = CaseAction.action_unknow; try { tempResult = (CaseResult)Enum.Parse(typeof(CaseResult), tempNode.Name); } catch { myCaseData.AddErrorMessage(string.Format("Error :find error CaseAction in Action with [{0}] in [{1}]", tempNode.InnerXml, tempNode.Name)); continue; } try { tempAction = (CaseAction)Enum.Parse(typeof(CaseAction), "action_" + CaseTool.GetXmlAttributeVauleWithEmpty(tempNode, "action")); } catch { myCaseData.AddErrorMessage(string.Format("Error :find error CaseAction in Action with [{0}] in [{1}]", tempNode.InnerXml, CaseTool.GetXmlAttributeVauleWithEmpty(tempNode, "action"))); continue; } if (tempNode.InnerText != "") { myCaseData.AddCaseAction(tempResult, new CaseActionDescription(tempAction, tempNode.InnerText)); } else { myCaseData.AddCaseAction(tempResult, new CaseActionDescription(tempAction, null)); } } } } #endregion #region Attribute XmlNode tempCaseAttribute = sourceNode["Attribute"]; if (tempCaseAttribute != null) { if (tempCaseAttribute.HasChildNodes) { if (tempCaseAttribute["Delay"] != null) { try { myCaseData.caseAttribute.attributeDelay = int.Parse(tempCaseAttribute["Delay"].InnerText); } catch { myCaseData.AddErrorMessage("Error :find error Delay data in Attribute"); } } if (tempCaseAttribute["Level"] != null) { try { myCaseData.caseAttribute.attributeLevel = int.Parse(tempCaseAttribute["Level"].InnerText); } catch { myCaseData.AddErrorMessage("Error :find error Level data in Attribute"); } } if (tempCaseAttribute["ParameterSave"] != null) { if (tempCaseAttribute["ParameterSave"].HasChildNodes) { foreach (XmlNode tempNode in tempCaseAttribute["ParameterSave"].ChildNodes) { if (tempNode.Name == "NewParameter") { string tempParameterName = CaseTool.GetXmlAttributeVaule(tempNode, "name"); string tempParameterMode = CaseTool.GetXmlAttributeVaule(tempNode, "mode"); string tempParameterAdditional = CaseTool.GetXmlAttributeVaule(tempNode, "additional"); string tempFindVaule = tempNode.InnerText; PickOutFunction tempPickOutFunction = PickOutFunction.pick_str; if (tempParameterName == null) { myCaseData.AddErrorMessage("Error :can not find name data in NewParameter in Attribute"); continue; } if (tempParameterName == "") { myCaseData.AddErrorMessage("Error :the name data in NewParameter is empty in Attribute"); continue; } if (tempParameterMode == null) { myCaseData.AddErrorMessage("Error :can not find mode data in NewParameter in Attribute"); continue; } if (tempFindVaule == "") { myCaseData.AddErrorMessage("Error :the NewParameter vaule is empty in Attribute"); continue; } try { tempPickOutFunction = (PickOutFunction)Enum.Parse(typeof(PickOutFunction), "pick_" + tempParameterMode); } catch { myCaseData.AddErrorMessage("Error :find error ParameterSave mode in Attribute"); continue; } myCaseData.caseAttribute.addParameterSave(tempParameterName, tempFindVaule, tempPickOutFunction, tempParameterAdditional); } } } } } } #endregion } else { myCaseData.AddErrorMessage("Error :source data is error"); } } return(myCaseData); }
/// <summary> /// i will get the csae info that you need to show in your Tree (对于CASE 的content 仅供参考) /// </summary> /// <param name="sourceNode">source Node</param> /// <returns>the info with myCaseLaodInfo</returns> public static myCaseLaodInfo GetCaseLoadInfo(XmlNode sourceNode) { myCaseLaodInfo myInfo = new myCaseLaodInfo("NULL"); switch (sourceNode.Name) { #region Project show info case "Project": //Type myInfo.caseType = CaseType.Project; //name if (sourceNode.Attributes["name"] == null) { myInfo.name = "not find"; } else { myInfo.name = sourceNode.Attributes["name"].Value; } //remark if (sourceNode.Attributes["remark"] == null) { myInfo.remark = "not find"; } else { myInfo.remark = sourceNode.Attributes["remark"].Value; } //id if (sourceNode.Attributes["id"] == null) { myInfo.ErrorMessage = "not find the ID"; } else { try { myInfo.id = int.Parse(sourceNode.Attributes["id"].Value); } catch (Exception ex) { myInfo.ErrorMessage = ex.Message; } } break; #endregion #region Case show info case "Case": //Type myInfo.caseType = CaseType.Case; //remark if (sourceNode.Attributes["remark"] == null) { myInfo.remark = "not find"; } else { myInfo.remark = sourceNode.Attributes["remark"].Value; } //id if (sourceNode.Attributes["id"] == null) { myInfo.ErrorMessage = "not find the ID"; } else { try { myInfo.id = int.Parse(sourceNode.Attributes["id"].Value); } catch (Exception ex) { myInfo.ErrorMessage = "Analytical ID Fial" + ex.Message; } } //case cantent and caseProtocol XmlNode tempCaseContent = sourceNode.SelectSingleNode("Content"); if (tempCaseContent == null) { myInfo.ErrorMessage = "can not find Content"; } else { try { myInfo.caseProtocol = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), tempCaseContent.Attributes["protocol"].Value); } catch { myInfo.caseProtocol = CaseProtocol.unknownProtocol; myInfo.ErrorMessage = ""; } if (tempCaseContent.HasChildNodes) { string tempTarget = CaseTool.GetXmlAttributeVauleEx(tempCaseContent.ChildNodes[0], "target", null); if (tempTarget == null) { myInfo.content = " > " + tempCaseContent.ChildNodes[0].InnerText; } else { myInfo.content = " > " + tempTarget + MyConfiguration.CaseShowTargetAndContent + tempCaseContent.ChildNodes[0].InnerText; } } else { myInfo.ErrorMessage = "can not find [ContentData] TestData"; } } //case action XmlNode tempCaseAction = sourceNode.SelectSingleNode("Action"); if (tempCaseAction != null) { if (tempCaseAction.SelectSingleNode("Pass") != null) { /* * if (tempCaseAction.SelectSingleNode("Pass").Attributes["action"].Value != null) * { * switch (tempCaseAction.SelectSingleNode("Pass").Attributes["action"].Value) * { * * } * } */ CaseAction tempAction; try { tempAction = (CaseAction)Enum.Parse(typeof(CaseAction), "action_" + tempCaseAction.SelectSingleNode("Pass").Attributes["action"].Value); } catch { tempAction = CaseAction.action_unknow; } myInfo.actions.Add(CaseResult.Pass, tempAction); } if (tempCaseAction.SelectSingleNode("Fail") != null) { CaseAction tempAction; try { tempAction = (CaseAction)Enum.Parse(typeof(CaseAction), "action_" + tempCaseAction.SelectSingleNode("Pass").Attributes["action"].Value); } catch { tempAction = CaseAction.action_unknow; } myInfo.actions.Add(CaseResult.Fail, tempAction); } } break; #endregion #region Repeat show info case "Repeat": //Type myInfo.caseType = CaseType.Repeat; //remark if (sourceNode.Attributes["remark"] == null) { myInfo.remark = "not find"; } else { myInfo.remark = sourceNode.Attributes["remark"].Value; } //times if (sourceNode.Attributes["times"] == null) { myInfo.ErrorMessage = "not find the Times"; } else { try { myInfo.times = int.Parse(sourceNode.Attributes["times"].Value); } catch (Exception ex) { myInfo.ErrorMessage = "Analytical Repeat Times Fial" + ex.Message; } } break; #endregion case "ScriptRunTime": myInfo.caseType = CaseType.ScriptRunTime; break; default: //unkonw CASE; break; } return(myInfo); }
public new static MyActiveMQExecutionContent GetRunContent(XmlNode yourContentNode) { MyActiveMQExecutionContent myRunContent = new MyActiveMQExecutionContent(); if (yourContentNode != null) { if (yourContentNode.Attributes["protocol"] != null && yourContentNode.Attributes["actuator"] != null) { //Content try { myRunContent.caseProtocol = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), yourContentNode.Attributes["protocol"].Value); } catch { myRunContent.errorMessage = "Error :error protocol in Content"; return(myRunContent); } myRunContent.caseActuator = yourContentNode.Attributes["actuator"].Value; //Subscribe List #region Subscribe List <string[]> tempSubscribeRawList = CaseTool.GetXmlInnerMetaDataList(yourContentNode, "Subscribe", new string[] { "type", "durable" }); foreach (string[] tempOneSubscribeRaw in tempSubscribeRawList) { if (tempOneSubscribeRaw[1] != null && tempOneSubscribeRaw[0] != "") { myRunContent.consumerSubscribeList.Add(new MyActiveMQExecutionContent.ConsumerData(tempOneSubscribeRaw[0], tempOneSubscribeRaw[1], tempOneSubscribeRaw[2])); } else { myRunContent.errorMessage = string.Format("Error :error data in Subscribe List with [{0}]", tempOneSubscribeRaw[0]); return(myRunContent); } } #endregion //UnSubscribe List #region UnSubscribe List <string[]> tempUnSubscribeRawList = CaseTool.GetXmlInnerMetaDataList(yourContentNode, "UnSubscribe", new string[] { "type" }); foreach (string[] tempOneUnSubscribeRaw in tempUnSubscribeRawList) { if (tempOneUnSubscribeRaw[1] != null && tempOneUnSubscribeRaw[0] != "") { myRunContent.unConsumerSubscribeList.Add(new MyActiveMQExecutionContent.ConsumerData(tempOneUnSubscribeRaw[0], tempOneUnSubscribeRaw[1], null)); } else { myRunContent.errorMessage = string.Format("Error :error data in UnSubscribe List with [{0}]", tempOneUnSubscribeRaw[0]); return(myRunContent); } } #endregion //Message Send List #region Message Send List <KeyValuePair <XmlNode, string[]> > tempMessageSendList = CaseTool.GetXmlInnerMetaDataListEx(yourContentNode, "Send", new string[] { "name", "type", "isHaveParameters" }); foreach (KeyValuePair <XmlNode, string[]> tempOneMessageSendRaw in tempMessageSendList) { if (!string.IsNullOrEmpty(tempOneMessageSendRaw.Value[1]) && tempOneMessageSendRaw.Value[2] != null && tempOneMessageSendRaw.Value[0] != "") { MyActiveMQExecutionContent.ProducerData tempProducerData = new MyActiveMQExecutionContent.ProducerData(tempOneMessageSendRaw.Value[1], tempOneMessageSendRaw.Value[2], "TextMessage"); caseParameterizationContent tempProducerMessage = CaseTool.GetXmlParametContent(tempOneMessageSendRaw.Key); myRunContent.producerDataSendList.Add(new KeyValuePair <MyActiveMQExecutionContent.ProducerData, caseParameterizationContent>(tempProducerData, tempProducerMessage)); } else { myRunContent.errorMessage = string.Format("Error :error data in Send List with [{0}]", tempOneMessageSendRaw.Value[0]); return(myRunContent); } } #endregion //Receive #region Receive List <string[]> tempConsumerReceiveList = CaseTool.GetXmlInnerMetaDataList(yourContentNode, "Receive", new string[] { "type" }); foreach (string[] tempOneConsumerReceiveRaw in tempConsumerReceiveList) { if (tempOneConsumerReceiveRaw[0] == "") { myRunContent.consumerMessageReceiveList.Add(new MyActiveMQExecutionContent.ConsumerData(null, null, null)); } else { if (tempOneConsumerReceiveRaw[1] != null) { myRunContent.consumerMessageReceiveList.Add(new MyActiveMQExecutionContent.ConsumerData(tempOneConsumerReceiveRaw[0], tempOneConsumerReceiveRaw[1], null)); } else { myRunContent.errorMessage = string.Format("Error :error data in Receive List with [{0}]", tempOneConsumerReceiveRaw[0]); return(myRunContent); } } } #endregion } else { myRunContent.errorMessage = "Error :can not find protocol or actuator in Content "; } } else { myRunContent.errorMessage = "Error :yourContentNode is null"; } return(myRunContent); }
private static int LogStep(ref Step[,] canvasMatrix, Step step, int curRow, int threadCol, int indentLevel, out string log, out string functions) { int nextRow = curRow; log = ""; functions = ""; string indentString = new string(' ', indentLevel * 4); if (step.Description.Length > 0) { log = "\r\n\r\n" + indentString + "/*" + step.Description + "*/";// + ((log.Length > 0) ? ("\r\n" + log) : ("")); } else { log = "";//"\r\n";// +log; } switch (step.ToolName) { case "NullTool": { log = ""; return(nextRow); } case "NoOpTool": { if (step.Enabled == false) { log += "\r\n" + indentString + "// " + "/*" + step.StepName.Replace("_x0020_", "_") + "*/"; } else { log += "\r\n" + indentString + "/*NOP: " + step.StepName.Replace("_x0020_", "_") + "*/"; } return(nextRow); } case "CaseTool": { int width = step.StepWidth; int height = step.StepHeight; log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; string caselog; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); Step[,] caseMatrix = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, curRow, threadCol, Math.Min(curRow + height - 1, canvasMatrix.GetLength(0) - 1), canvasMatrix.GetLength(1) - 1); CaseTool.CaseToTxt(ref caseMatrix, 0, indentLevel + ((eh.Length > 0) ? 1 : 0), height, width, out caselog, out functions); nextRow = curRow + height; if (step.Enabled == false) { log += "\r\n" + indentString + "// " + caselog.Replace("\r\n", "\r\n// "); } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + caselog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + caselog; } } return(nextRow); } case "VariableTool": { string varlog, varfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); VariableTool.SetVariableToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out varlog, out varfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + varlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + varlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + varlog; } } if (varfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + varfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + varfunction; } } return(nextRow); } case "PaWTestTool": case "MethodTool": case "TestTool": case "Mouse": case "Keyboard": case "Inspect": { string testlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); TestTool.TestToTxt(step.StepXmlNode, indentLevel + ((eh.Length > 0) ? 1 : 0), out testlog, out dummy); if (step.ToolName == "TestTool" || step.ToolName == "PaWTestTool") { XmlNode path = step.StepXmlNode.SelectSingleNode(".//*[@Key='ResourceFullName']"); if (path != null) { string p; if (path.Attributes["Value"] != null) { p = path.Attributes["Value"].Value; } else { p = path.SelectSingleNode(".//*[@Key='Value']/@Value").Value; } log += "\r\n" + indentString + "/*" + "Path: " + p.Replace(".tsdrv", "") + " */"; } } if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + testlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + testlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + testlog; } } return(nextRow); } case "AttributeTool": { string alog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); AttributeTool.AttributeToTxt(step.StepXmlNode, indentLevel + ((eh.Length > 0) ? 1 : 0), out alog, out dummy); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + alog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + alog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + alog; } } return(nextRow); } case "CaptureImageTool": { string cilog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); CaptureImageTool.CaptureImageToTxt(step.StepXmlNode, indentLevel + ((eh.Length > 0) ? 1 : 0), out cilog, out dummy); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + cilog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + cilog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + cilog; } } return(nextRow); } case "CriteriaTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); CriteriaTool.CriteriaToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "ScripterTool": case "PaWScripterTool": { string slog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); ScripterTool.ScripterToTxt(step.StepXmlNode, indentLevel + ((eh.Length > 0) ? 1 : 0), out slog, out dummy); XmlNode path = step.StepXmlNode.SelectSingleNode(".//*[@Key='ResourceFullName']"); if (path != null) { string p; if (path.Attributes["Value"] != null) { p = path.Attributes["Value"].Value; } else { p = path.SelectSingleNode(".//*[@Key='Value']/@Value").Value; } log += "\r\n" + indentString + "/* " + "Path: " + p.Replace(".tsscript", "") + " */"; } if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + slog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + slog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + slog; } } return(nextRow); } case "CommandTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); CommandTool.CommandToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "TerminalCommandTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); TerminalCommandTool.CommandToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "WriteTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); WriteTool.WriteToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "ReadTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); ReadTool.ReadToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "MessageTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); MessageTool.MessageToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "TransformationTool": { string tlog, tfunctions; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); TransformTool.TransformToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out tlog, out tfunctions); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + tlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + tlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + tlog; } } if (tfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + tfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + tfunctions; } } return(nextRow); } case "SetSessionTool": { string sessionlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); SetSessionTool.SessionToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out sessionlog, out dummy); log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + sessionlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + sessionlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + sessionlog; } } return(nextRow); } case "DelayTool": { string dlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); DelayTool.DelayToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out dlog, out dummy); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + dlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } } return(nextRow); } case "SetEventTool": { string dlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); SetEventTool.SetEventToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out dlog, out dummy); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + dlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } } return(nextRow); } case "WaitForEventTool": { string dlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); WaitForEventTool.WaitForEventToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out dlog, out dummy); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + dlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } } return(nextRow); } case "PassFailTool": { string dlog, dfunc; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); PassFailTool.PassFailToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out dlog, out dfunc); string tooltype = step.StepXmlNode.SelectSingleNode(".//*[@Key='NotificationType']/@Value").Value; string toolname = "PassFailTool"; switch (tooltype) { case "0": toolname = "Pass"; break; case "1": toolname = "Fail"; break; case "2": toolname = "Text To Report"; break; default: break; } log += "\r\n" + indentString + "/*" + toolname + ": " + step.StepName + "*/"; if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + dlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } } if (dfunc.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + dfunc.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + dfunc; } } return(nextRow); } case "ErrorTool": { string dlog, dummy; ErrorTool.ErrorToTxt(step, indentLevel, out dlog, out dummy); log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; if (step.Enabled == false) { log += "\r\n" + indentString + "// throw" + step.StepName.Replace("_x0020_", "_") + dlog; } else { log += "\r\n" + indentString + "throw " + step.StepName.Replace("_x0020_", "_") + dlog; } return(nextRow); } case "EndSessionTool": { string dlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); EndSessionTool.EndSessionToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out dlog, out dummy); log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + dlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } } return(nextRow); } case "EndTool": { string dlog, dummy; EndTool.EndToTxt(step, indentLevel, out dlog, out dummy); log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } return(nextRow); } case "CodeTool": { string dummy, codefunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); CodeTool.CodeToTxt(step, indentLevel + ((eh.Length > 0)?1:0), out dummy, out codefunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + "()"; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + "()"; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + "()"; } } if (codefunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + codefunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + codefunction; } } return(nextRow); } case "LoopTool": case "ParaLoopTool": { int width = step.StepWidth; int height = step.StepHeight; log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; string looplog, loopfunctions; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); Step[,] loopMatrix = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, curRow, threadCol, Math.Min(curRow + height - 1, canvasMatrix.GetLength(0) - 1), canvasMatrix.GetLength(1) - 1); LoopTool.LoopToTxt(ref loopMatrix, 0, indentLevel + ((eh.Length > 0) ? 1 : 0), height, width, out looplog, out loopfunctions); nextRow = curRow + height; if (step.Enabled == false) { log += "\r\n" + indentString + "// " + looplog.Replace("\r\n", "\r\n// "); } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + looplog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + looplog; } } if (loopfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + loopfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + loopfunctions; } } return(nextRow); } case "WhileTool": { int width = step.StepWidth; int height = step.StepHeight; log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; string wlog, wfunctions; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); Step[,] whileMatrix = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, curRow, threadCol, Math.Min(curRow + height - 1, canvasMatrix.GetLength(0) - 1), canvasMatrix.GetLength(1) - 1); WhileTool.WhileToTxt(ref whileMatrix, 0, indentLevel + ((eh.Length > 0) ? 1 : 0), height, width, out wlog, out wfunctions); nextRow = curRow + height; if (step.Enabled == false) { log += "\r\n" + indentString + "// " + wlog.Replace("\r\n", "\r\n// "); } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + wlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + wlog; } } if (wfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + wfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + wfunctions; } } return(nextRow); } case "LockTool": { int width = step.StepWidth; int height = step.StepHeight; log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; string llog, lfunctions; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); Step[,] lockMatrix = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, curRow, threadCol, Math.Min(curRow + height - 1, canvasMatrix.GetLength(0) - 1), canvasMatrix.GetLength(1) - 1); LockTool.LockToTxt(ref lockMatrix, 0, indentLevel + ((eh.Length > 0) ? 1 : 0), height, width, out llog, out lfunctions); nextRow = curRow + height; if (step.Enabled == false) { log += "\r\n" + indentString + "// " + llog.Replace("\r\n", "\r\n// "); } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + llog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + llog; } } if (lfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + lfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + lfunctions; } } return(nextRow); } case "ParallelTool": { int width = step.StepWidth; int height = step.StepHeight; log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; string plog, pfunctions; Step[,] pMatrix = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, curRow, 0, Math.Min(curRow + height - 1, canvasMatrix.GetLength(0) - 1), canvasMatrix.GetLength(1) - 1); ParallelTool.ParallelToTxt(ref pMatrix, threadCol, indentLevel, height, width, out plog, out pfunctions); nextRow = curRow + height; if (step.Enabled == false) { log += "\r\n" + indentString + "// " + plog.Replace("\r\n", "\r\n// "); } else { log += "\r\n" + indentString + plog; } if (pfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + pfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + pfunctions; } } return(nextRow); } case "GroupTool": case "PaWDllTool": case "DllTool": case "CommandShellTool": case "SequenceTool": case "TerminalTool": case "WebServiceTool": case "NetworkClientTool": { string glog, gfunctions; if (step.ToolName == "DllTool" || step.ToolName == "PaWDllTool" || step.ToolName == "WebServiceTool") { XmlNode path = step.StepXmlNode.SelectSingleNode(".//*[@Key='ResourceFullName']"); if (path != null) { string p; if (path.Attributes["Value"] != null) { p = path.Attributes["Value"].Value; } else { p = path.SelectSingleNode(".//*[@Key='Value']/@Value").Value; } log += "\r\n" + indentString + "/*" + "Path: " + p.Replace(".tsdll", "") + " */"; } log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; } else if (step.ToolName == "SequenceTool") { XmlNode path = step.StepXmlNode.SelectSingleNode(".//*[@Key='LibraryFullName']"); if (path != null) { string p; if (path.Attributes["Value"] != null) { p = path.Attributes["Value"].Value; } else { p = path.SelectSingleNode(".//*[@Key='Value']/@Value").Value; } log += "\r\n" + indentString + "/*" + "Path: " + p.Replace(".tslib", "") + " */"; } log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; } else { log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; } XmlNode groupSteps = step.StepXmlNode.SelectSingleNode(".//List[@Key='Steps']"); XmlNode eh = step.StepXmlNode.SelectSingleNode(".//ErrorHandlingBehavior"); CanvasAnalyzer.StepsListToTxt(groupSteps.ChildNodes, true, indentLevel, eh, out glog, out gfunctions); if (step.Enabled == false) { log += "\r\n" + indentString + "// " + glog.Replace("\r\n", "\r\n// "); } else { log += "\r\n" + indentString + glog; } if (gfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + gfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + gfunctions; } } return(nextRow); } case "AnalyzableCompositeTool": { string aclog, acfunctions; XmlNodeList acTools = step.StepXmlNode.SelectNodes(".//Array[@Key='ChildTools']/*"); foreach (XmlNode tool in acTools) { Step curstep = new Step(tool); curstep.Enabled = step.Enabled; LogStep(ref canvasMatrix, curstep, curRow, threadCol, indentLevel, out aclog, out acfunctions); if (step.Enabled == false) { log += "\r\n" + indentString + "// " + aclog.Replace("\r\n", "\r\n// "); } else { log += "\r\n" + indentString + aclog; } if (acfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + acfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + acfunctions; } } } return(nextRow + acTools.Count - 1); } } if (step.Enabled == false) { log += "\r\n" + indentString + "//"; } else { log += "\r\n" + indentString; } log += step.StepName.Replace("_x0020_", "_") + " // (" + step.ToolName + ")"; return(nextRow); }
public new static MyComExecutionContent GetRunContent(XmlNode yourContentNode) { MyComExecutionContent myRunContent = new MyComExecutionContent(); if (yourContentNode != null) { if (yourContentNode.Attributes["protocol"] != null && yourContentNode.Attributes["actuator"] != null) { //Content try { myRunContent.caseProtocol = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), yourContentNode.Attributes["protocol"].Value); } catch { myRunContent.errorMessage = "Error :error protocol in Content"; return(myRunContent); } myRunContent.caseActuator = yourContentNode.Attributes["actuator"].Value; #region send XmlNode nowComNode = yourContentNode["Send"]; if (nowComNode != null) { myRunContent.comSendEncoding = null; if (nowComNode.Attributes["encoding"] == null) { myRunContent.comSendEncoding = Encoding.UTF8; } else { if (nowComNode.Attributes["encoding"].Value != "raw") { try { myRunContent.comSendEncoding = Encoding.GetEncoding(nowComNode.Attributes["encoding"].Value); } catch { myRunContent.comSendEncoding = null; } } } myRunContent.comContentToSend = CaseTool.GetXmlParametContent(nowComNode); myRunContent.isSend = true; } #endregion #region receive nowComNode = yourContentNode["Receive"]; if (nowComNode != null) { myRunContent.comReceiveEncoding = null; if (nowComNode.Attributes["encoding"] == null) { myRunContent.comReceiveEncoding = Encoding.UTF8; } else { if (nowComNode.Attributes["encoding"].Value != "raw") { try { myRunContent.comReceiveEncoding = Encoding.GetEncoding(nowComNode.Attributes["encoding"].Value); } catch { myRunContent.comReceiveEncoding = null; } } } if (nowComNode.InnerText != "") { if (!int.TryParse(nowComNode.InnerText, out myRunContent.comSleepTime)) { myRunContent.comSleepTime = -1; } } else { myRunContent.comSleepTime = -1; } myRunContent.isReceive = true; } #endregion if (!(myRunContent.isReceive || myRunContent.isSend)) { myRunContent.errorMessage = "Error :can not find any send or receive node in Content "; } } else { myRunContent.errorMessage = "Error :can not find protocol or actuator in Content "; } } else { myRunContent.errorMessage = "Error :yourContentNode is null"; } return(myRunContent); }
/// <summary> /// here i can get the data your need in the XmlNode the for the 【ICaseExecutionDevice】 /// </summary> /// <param name="yourContentNode">souce XmlNode</param> /// <returns>the data your need</returns> public new static MyVaneHttpExecutionContent GetRunContent(XmlNode yourContentNode) { MyVaneHttpExecutionContent myRunContent = new MyVaneHttpExecutionContent(); if (yourContentNode != null) { if (yourContentNode.Attributes["protocol"] != null && yourContentNode.Attributes["actuator"] != null) { //Content try { myRunContent.caseProtocol = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), yourContentNode.Attributes["protocol"].Value); } catch { myRunContent.errorMessage = "Error :error protocol in Content"; return(myRunContent); } myRunContent.caseActuator = yourContentNode.Attributes["actuator"].Value; //ContentData XmlNode tempContentDataNode = yourContentNode["ContentData"]; if (tempContentDataNode != null) { if (tempContentDataNode.Attributes["target"] != null) { myRunContent.httpTarget = tempContentDataNode.Attributes["target"].Value; } else { myRunContent.httpTarget = ""; } if (tempContentDataNode.Attributes["isHaveParameters"] != null) { if (tempContentDataNode.Attributes["isHaveParameters"].Value == "true") { myRunContent.caseExecutionContent.hasParameter = true;//hasParameter默认为false,其他情况无需设置该值 } } myRunContent.caseExecutionContent.contentData = tempContentDataNode.InnerText; } else { myRunContent.errorMessage = "Error :can not find ContentData , it is necessary in [vanelife_http]"; return(myRunContent); } //HttpConfig XmlNode tempHttpConfigDataNode = yourContentNode["HttpConfig"]; if (tempHttpConfigDataNode != null) { if (tempHttpConfigDataNode.Attributes["httpMethod"] != null) { myRunContent.httpMethod = tempHttpConfigDataNode.Attributes["httpMethod"].Value; } else { myRunContent.httpMethod = "POST"; } if (tempHttpConfigDataNode["AisleConfig"] != null) { myRunContent.myHttpAisleConfig.httpAddress = CaseTool.GetXmlParametContent(tempHttpConfigDataNode["AisleConfig"], "HttpAddress"); myRunContent.myHttpAisleConfig.httpDataDown = CaseTool.GetXmlParametContent(tempHttpConfigDataNode["AisleConfig"], "HttpDataDown"); } if (tempHttpConfigDataNode["HttpMultipart"] != null) { if (tempHttpConfigDataNode["HttpMultipart"]["MultipartData"] != null) { myRunContent.myHttpMultipart.isFile = false; myRunContent.myHttpMultipart.name = CaseTool.GetXmlAttributeVauleWithEmpty(tempHttpConfigDataNode["HttpMultipart"]["MultipartData"], "name"); myRunContent.myHttpMultipart.fileName = CaseTool.GetXmlAttributeVauleWithEmpty(tempHttpConfigDataNode["HttpMultipart"]["MultipartData"], "filename"); myRunContent.myHttpMultipart.fileData = tempHttpConfigDataNode["HttpMultipart"]["MultipartData"].InnerText; } else if (tempHttpConfigDataNode["HttpMultipart"]["MultipartFile"] != null) { myRunContent.myHttpMultipart.isFile = true; myRunContent.myHttpMultipart.name = CaseTool.GetXmlAttributeVauleWithEmpty(tempHttpConfigDataNode["HttpMultipart"]["MultipartFile"], "name"); myRunContent.myHttpMultipart.fileName = CaseTool.GetXmlAttributeVauleWithEmpty(tempHttpConfigDataNode["HttpMultipart"]["MultipartFile"], "filename"); myRunContent.myHttpMultipart.fileData = CaseTool.GetFullPath(tempHttpConfigDataNode["HttpMultipart"]["MultipartFile"].InnerText, MyConfiguration.CaseFilePath); } } } else { myRunContent.httpMethod = "POST"; } } else { myRunContent.errorMessage = "Error :can not find protocol or actuator in Content "; } } else { myRunContent.errorMessage = "Error :yourContentNode is null"; } return(myRunContent); }
public MyExecutionDeviceResult ExecutionDeviceRun(ICaseExecutionContent yourExecutionContent, CaseActionActuator.delegateGetExecutiveData yourExecutiveDelegate, string sender, ActuatorStaticDataCollection yourActuatorStaticDataCollection, int caseId) { MyExecutionDeviceResult myResult = new MyExecutionDeviceResult(); myResult.staticDataResultCollection = new System.Collections.Specialized.NameValueCollection();//默认该值为null,不会输出参数数据结果(如果不需要输出可以保持该字段为null) if (yourExecutionContent.MyCaseProtocol == CaseProtocol.vanelife_http) { //在调用该函数前保证nowExecutionContent.ErrorMessage为空,且as一定成功 MyVaneHttpExecutionContent nowExecutionContent = yourExecutionContent as MyVaneHttpExecutionContent; myResult.caseProtocol = CaseProtocol.vanelife_http; myResult.caseTarget = nowExecutionContent.MyExecutionTarget; string tempError; string tempUrlAddress; string vanelifeData = CreatVanelifeSendData(nowExecutionContent.caseExecutionContent.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError)); if (nowExecutionContent.myHttpAisleConfig.httpAddress.IsFilled()) { tempUrlAddress = nowExecutionContent.myHttpAisleConfig.httpAddress.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError) + nowExecutionContent.httpTarget; } else { tempUrlAddress = myExecutionDeviceInfo.default_url + nowExecutionContent.httpTarget; } //report Executive Data if (yourExecutiveDelegate != null) { yourExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("【ID:{0}】[vanelife_http]Executive···\r\n{1}\r\n{2}", caseId, tempUrlAddress, vanelifeData)); } //Start Http if (nowExecutionContent.myHttpAisleConfig.httpDataDown.IsFilled()) { httpClient.SendData(tempUrlAddress, vanelifeData, nowExecutionContent.httpMethod, myResult, CaseTool.GetFullPath(nowExecutionContent.myHttpAisleConfig.httpDataDown.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError), MyConfiguration.CaseFilePath)); } else { if (nowExecutionContent.myHttpMultipart.IsFilled()) { //由于vanelife协议要求在Multipart把业务数据全部放在了url中 httpClient.HttpPostData(tempUrlAddress + "?" + vanelifeData, 30000, nowExecutionContent.myHttpMultipart.name, nowExecutionContent.myHttpMultipart.fileName, nowExecutionContent.myHttpMultipart.isFile, nowExecutionContent.myHttpMultipart.fileData, null, myResult); } else { httpClient.SendData(tempUrlAddress, vanelifeData, nowExecutionContent.httpMethod, myResult); } } if (tempError != null) { myResult.additionalError = ("error:" + tempError); } } else { myResult.backContent = "error:your CaseProtocol is not Matching RunTimeActuator"; myResult.additionalError = ("error:your CaseProtocol is not Matching RunTimeActuator"); } return(myResult); }