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); }