Exemplo n.º 1
0
        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);
        }
        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);
        }