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); }
public MyExecutionDeviceResult ExecutionDeviceRun(ICaseExecutionContent yourExecutionContent, CaseActuator.CaseActionActuator.delegateGetExecutiveData yourExecutiveDelegate, string sender, ActuatorStaticDataCollection yourActuatorStaticDataCollection, int caseId) { List <string> errorList = new List <string>(); string tempError = null; MyExecutionDeviceResult myResult = new MyExecutionDeviceResult(); myResult.staticDataResultCollection = new System.Collections.Specialized.NameValueCollection(); Action <string, CaseActuatorOutPutType, string> ExecutiveDelegate = (innerSender, outType, yourContent) => { if (yourExecutiveDelegate != null) { yourExecutiveDelegate(innerSender, outType, yourContent); } }; Func <string, bool> DealNowError = (errerData) => { if (errerData != null) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, errerData); errorList.Add(errerData); return(true); } return(false); }; Func <string, string, string, bool> DealNowResultError = (errerData, actionType, keyName) => { if (DealNowError(errerData)) { ExecutiveDelegate(string.Format("[CaseProtocolExecutionForConsole][ExecutionDeviceRun][{0}]", actionType), CaseActuatorOutPutType.ExecutiveError, string.Format("static data {0} error with the key :{1} ", actionType, keyName)); return(true); } else { return(false); } }; if (yourExecutionContent.MyCaseProtocol == CaseProtocol.console) { //在调用该函数前保证nowExecutionContent.ErrorMessage为空,且as一定成功 MyConsoleExecutionContent nowExecutionContent = yourExecutionContent as MyConsoleExecutionContent; myResult.caseProtocol = CaseProtocol.console; myResult.caseTarget = nowExecutionContent.MyExecutionTarget; myResult.startTime = DateTime.Now.ToString("HH:mm:ss"); System.Diagnostics.Stopwatch myWatch = new System.Diagnostics.Stopwatch(); myWatch.Start(); #region Show myResult.backContent = nowExecutionContent.showContent.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); DealNowError(tempError); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("【ID:{0}】Executive···\r\n【Console】\r\n{1}", caseId, myResult.backContent)); #endregion #region Add if (nowExecutionContent.staticDataAddList.Count > 0) { foreach (var addInfo in nowExecutionContent.staticDataAddList) { switch (CaseRunTimeDataTypeEngine.dictionaryStaticDataTypeClass[addInfo.StaticDataType]) { //caseStaticDataKey case CaseStaticDataClass.caseStaticDataKey: string tempRunTimeDataKey; if (addInfo.StaticDataType == CaseStaticDataType.caseStaticData_vaule) { tempRunTimeDataKey = addInfo.ConfigureData.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); } else { ExecutiveDelegate("[CaseProtocolExecutionForConsole][ExecutionDeviceRun][Add]", CaseActuatorOutPutType.ExecutiveError, string.Format("find nonsupport Protocol")); break; } //如果使用提供的方式进行添加是不会出现错误的(遇到重复会覆盖,只有发现多个同名Key才会返回错误), 不过getTargetContentData需要处理用户数据可能出现错误。 if (!DealNowResultError(tempError, "Add", addInfo.Name)) { yourActuatorStaticDataCollection.AddStaticDataKey(addInfo.Name, tempRunTimeDataKey); ExecutiveDelegate("[CaseProtocolExecutionForConsole][ExecutionDeviceRun][Add]", CaseActuatorOutPutType.ExecutiveInfo, string.Format("static data add success with the key :{0} ", addInfo.Name)); } break; //caseStaticDataParameter case CaseStaticDataClass.caseStaticDataParameter: IRunTimeStaticData tempRunTimeStaticData; string tempTypeError; if (CaseRunTimeDataTypeEngine.dictionaryStaticDataParameterAction[addInfo.StaticDataType](out tempRunTimeStaticData, out tempTypeError, addInfo.ConfigureData.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError))) { if (!DealNowResultError(tempError, "Add", addInfo.Name)) { yourActuatorStaticDataCollection.AddStaticDataParameter(addInfo.Name, tempRunTimeStaticData); ExecutiveDelegate("[CaseProtocolExecutionForConsole][ExecutionDeviceRun][Add]", CaseActuatorOutPutType.ExecutiveInfo, string.Format("static data add success with the key :{0} ", addInfo.Name)); } } else { DealNowResultError("[yourActuatorStaticDataCollection][caseStaticDataParameter][GetStaticDataAction] error", "Add", addInfo.Name); } break; //caseStaticDataSource case CaseStaticDataClass.caseStaticDataSource: IRunTimeDataSource tempRunTimeDataSource; if (CaseRunTimeDataTypeEngine.dictionaryStaticDataSourceAction[addInfo.StaticDataType](out tempRunTimeDataSource, out tempTypeError, addInfo.ConfigureData.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError))) { if (!DealNowResultError(tempError, "Add", addInfo.Name)) { yourActuatorStaticDataCollection.AddStaticDataSouce(addInfo.Name, tempRunTimeDataSource); ExecutiveDelegate("[CaseProtocolExecutionForConsole][ExecutionDeviceRun][Add]", CaseActuatorOutPutType.ExecutiveInfo, string.Format("static data add success with the key :{0} ", addInfo.Name)); } } else { DealNowResultError("[yourActuatorStaticDataCollection][caseStaticDataSource][GetStaticDataAction] error", "Add", addInfo.Name); } break; default: DealNowError("[CaseProtocolExecutionForConsole][ExecutionDeviceRun][Add] find nonsupport Protocol"); break; } } } #endregion #region Set if (nowExecutionContent.staticDataSetList.Count > 0) { foreach (var addInfo in nowExecutionContent.staticDataSetList) { string tempSetVauleStr = addInfo.Value.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); if (!DealNowResultError(tempError, "Set", addInfo.Key)) { if (yourActuatorStaticDataCollection.SetStaticDataValue(addInfo.Key, tempSetVauleStr)) { ExecutiveDelegate("[CaseProtocolExecutionForConsole][ExecutionDeviceRun][Set]", CaseActuatorOutPutType.ExecutiveInfo, string.Format("static data set success with the key :{0} ", addInfo.Key)); } else { DealNowResultError("[yourActuatorStaticDataCollection.SetStaticData] error", "Set", addInfo.Key); } } } } #endregion #region Del if (nowExecutionContent.staticDataDelList.Count > 0) { foreach (var delInfo in nowExecutionContent.staticDataDelList) { string tempDelVauleStr = delInfo.Value.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); if (!DealNowResultError(tempError, "Del", delInfo.Value.GetTargetContentData())) { if (yourActuatorStaticDataCollection.RemoveStaticData(tempDelVauleStr, delInfo.Key)) { ExecutiveDelegate("[CaseProtocolExecutionForConsole][ExecutionDeviceRun][Del]", CaseActuatorOutPutType.ExecutiveInfo, string.Format("static data del success with the key :{0} ", tempDelVauleStr)); } else { DealNowResultError("[yourActuatorStaticDataCollection.RemoveStaticData] error", "Del", delInfo.Value.GetTargetContentData()); } } } } #endregion myWatch.Stop(); myResult.spanTime = myResult.requestTime = myWatch.ElapsedMilliseconds.ToString(); } else { myResult.backContent = "error:your CaseProtocol is not Matching RunTimeActuator"; DealNowError(myResult.backContent); } if (errorList.Count > 0) { myResult.additionalError = errorList.MyToString("\r\n"); } return(myResult); }
public MyExecutionDeviceResult ExecutionDeviceRun(ICaseExecutionContent yourExecutionContent, CaseActionActuator.delegateGetExecutiveData yourExecutiveDelegate, string sender, ActuatorStaticDataCollection yourActuatorStaticDataCollection, int caseId) { List <string> errorList = new List <string>(); string tempError = null; MyExecutionDeviceResult myResult = new MyExecutionDeviceResult(); myResult.staticDataResultCollection = new System.Collections.Specialized.NameValueCollection(); Action <string, CaseActuatorOutPutType, string> ExecutiveDelegate = (innerSender, outType, yourContent) => { if (yourExecutiveDelegate != null) { yourExecutiveDelegate(innerSender, outType, yourContent); } }; Action <string> DealExecutiveError = (errerData) => { if (errerData != null) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, errerData); errorList.Add(errerData); } }; if (yourExecutionContent.MyCaseProtocol == CaseProtocol.activeMQ) { //在调用该函数前保证nowExecutionContent.ErrorMessage为空,且as一定成功 MyActiveMQExecutionContent nowExecutionContent = yourExecutionContent as MyActiveMQExecutionContent; myResult.caseProtocol = CaseProtocol.activeMQ; myResult.caseTarget = nowExecutionContent.MyExecutionTarget; myResult.startTime = DateTime.Now.ToString("HH:mm:ss"); StringBuilder tempCaseOutContent = new StringBuilder(); System.Diagnostics.Stopwatch myWatch = new System.Diagnostics.Stopwatch(); myWatch.Start(); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("【ID:{0}】[activeMQ]Executive···", caseId)); #region Subscribe foreach (var tempConsumer in nowExecutionContent.consumerSubscribeList) { if (tempConsumer.ConsumerType == "queue" || tempConsumer.ConsumerType == "topic") { if (activeMQ.SubscribeConsumer(tempConsumer.ConsumerName, tempConsumer.ConsumerType == "queue", tempConsumer.ConsumerTopicDurable)) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("{0}://{1} subscribe success", tempConsumer.ConsumerType, tempConsumer.ConsumerName)); } else { DealExecutiveError(string.Format("{0}://{1} subscribe fail", tempConsumer.ConsumerType, tempConsumer.ConsumerName)); } } else { DealExecutiveError(string.Format("{0}://{1} subscribe fail [not support this consumer type]", tempConsumer.ConsumerType, tempConsumer.ConsumerName)); } } #endregion #region UnSubscribe foreach (var tempConsumer in nowExecutionContent.unConsumerSubscribeList) { if (tempConsumer.ConsumerType == "queue" || tempConsumer.ConsumerType == "topic") { if (activeMQ.UnSubscribeConsumer(string.Format("{0}://{1}", tempConsumer.ConsumerType, tempConsumer.ConsumerName)) > 0) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("{0}://{1} unsubscribe success", tempConsumer.ConsumerType, tempConsumer.ConsumerName)); } else { DealExecutiveError(string.Format("{0}://{1} unsubscribe fail", tempConsumer.ConsumerType, tempConsumer.ConsumerName)); } } else { DealExecutiveError(string.Format("{0}://{1} unsubscribe fail [not support this consumer type]", tempConsumer.ConsumerType, tempConsumer.ConsumerName)); } } #endregion #region Send foreach (var tempOneSender in nowExecutionContent.producerDataSendList) { if (tempOneSender.Key.ProducerType == "queue" || tempOneSender.Key.ProducerType == "topic") { string tempMessageSend = tempOneSender.Value.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); if (tempError != null) { DealExecutiveError(string.Format("this case get static data errer with [{0}]", tempOneSender.Value.GetTargetContentData())); tempCaseOutContent.AppendLine(string.Format("{0}://{1} send message fail [get static data errer]", tempOneSender.Key.ProducerType, tempOneSender.Key.ProducerName)); } else { MessageType tempMessageType; if (Enum.TryParse <MessageType>(tempOneSender.Key.MessageType, out tempMessageType)) { if (activeMQ.PublishMessage(tempOneSender.Key.ProducerName, tempMessageSend, tempOneSender.Key.ProducerType == "topic", tempMessageType)) { string tempReportStr = string.Format("{0}://{1} send message success", tempOneSender.Key.ProducerType, tempOneSender.Key.ProducerName); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, tempReportStr); tempCaseOutContent.AppendLine(tempReportStr); } else { string tempReportStr = string.Format("{0}://{1} send message fail [{2}]", tempOneSender.Key.ProducerType, tempOneSender.Key.ProducerName, activeMQ.NowErrorMes); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, tempReportStr); tempCaseOutContent.AppendLine(tempReportStr); } } else { DealExecutiveError(string.Format("get MessageType errer with [{0}]", tempOneSender.Key.MessageType)); tempCaseOutContent.AppendLine(string.Format("{0}://{1} send message fail [get MessageType errer]", tempOneSender.Key.ProducerType, tempOneSender.Key.ProducerName)); } } } else { tempCaseOutContent.Append(string.Format("{0}://{1} send message fail [not support this producer type]", tempOneSender.Key.ProducerType, tempOneSender.Key.ProducerName)); } } #endregion #region Receive if (nowExecutionContent.consumerMessageReceiveList.Count > 0) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, "Receive your activeMQ messages"); } foreach (var tempConsumer in nowExecutionContent.consumerMessageReceiveList) { if (tempConsumer.ConsumerName != null) { if (tempConsumer.ConsumerType == "queue" || tempConsumer.ConsumerType == "topic") { List <KeyValuePair <string, string> > oneMessageReceive = activeMQ.ReadConsumerMessage(string.Format("{0}://{1}", tempConsumer.ConsumerType, tempConsumer.ConsumerName)); foreach (KeyValuePair <string, string> tempMessage in oneMessageReceive) { string tempNowReceviceData = string.Format("{0} Receive {1}", tempMessage.Key, tempMessage.Value); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, tempNowReceviceData); tempCaseOutContent.AppendLine(tempNowReceviceData); } } else { DealExecutiveError(string.Format("{0}://{1} receive fail [not support this consumer type]", tempConsumer.ConsumerType, tempConsumer.ConsumerName)); tempCaseOutContent.AppendLine(string.Format("{0}://{1} receive fail ", tempConsumer.ConsumerType, tempConsumer.ConsumerName)); } } else { List <KeyValuePair <string, string> > oneMessageReceive = activeMQ.ReadConsumerMessage(); foreach (KeyValuePair <string, string> tempMessage in oneMessageReceive) { string tempNowReceviceData = string.Format("{0} Receive {1}", tempMessage.Key, tempMessage.Value); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, tempNowReceviceData); tempCaseOutContent.AppendLine(tempNowReceviceData); } } } #endregion myWatch.Stop(); myResult.spanTime = myResult.requestTime = myWatch.ElapsedMilliseconds.ToString(); myResult.backContent = tempCaseOutContent.ToString(); } else { myResult.backContent = "error:your CaseProtocol is not Matching RunTimeActuator"; DealExecutiveError(myResult.backContent); } if (errorList.Count > 0) { myResult.additionalError = errorList.MyToString("\r\n"); } return(myResult); }
public MyExecutionDeviceResult ExecutionDeviceRun(ICaseExecutionContent yourExecutionContent, CaseActionActuator.delegateGetExecutiveData yourExecutiveDelegate, string sender, ActuatorStaticDataCollection yourActuatorStaticDataCollection, int caseId) { List <string> errorList = new List <string>(); string tempError = null; MyExecutionDeviceResult myResult = new MyExecutionDeviceResult(); myResult.staticDataResultCollection = new System.Collections.Specialized.NameValueCollection(); //向UI推送执行过程信息 Action <string, CaseActuatorOutPutType, string> ExecutiveDelegate = (innerSender, outType, yourContent) => { if (yourExecutiveDelegate != null) { yourExecutiveDelegate(innerSender, outType, yourContent); } }; //处理执行错误(执行器无法执行的错误) Action <string> DealExecutiveError = (errerData) => { if (errerData != null) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, errerData); errorList.Add(errerData); } }; if (yourExecutionContent.MyCaseProtocol == CaseProtocol.ssh) { //在调用该函数前保证nowExecutionContent.ErrorMessage为空,且as一定成功 MySshExecutionContent nowExecutionContent = yourExecutionContent as MySshExecutionContent; myResult.caseProtocol = CaseProtocol.ssh; myResult.caseTarget = nowExecutionContent.MyExecutionTarget; myResult.startTime = DateTime.Now.ToString("HH:mm:ss"); StringBuilder tempCaseOutContent = new StringBuilder(); System.Diagnostics.Stopwatch myWatch = new System.Diagnostics.Stopwatch(); myWatch.Start(); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("【ID:{0}】[ssh]Executive···", caseId)); string nowSshCmd = nowExecutionContent.sshContent.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); if (tempError != null) { DealExecutiveError(string.Format("this case get static data errer with [{0}]", nowExecutionContent.sshContent.GetTargetContentData())); tempCaseOutContent.AppendLine("error with static data"); } else { try { sshShell.WriteLine(nowSshCmd); string tempResult = sshShell.Expect(); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, tempResult); tempCaseOutContent.AppendLine(tempResult); } catch (Exception ex) { DealExecutiveError(ex.Message); tempCaseOutContent.AppendLine(ex.Message); } } myWatch.Stop(); myResult.spanTime = myResult.requestTime = myWatch.ElapsedMilliseconds.ToString(); myResult.backContent = tempCaseOutContent.ToString(); } else { myResult.backContent = "error:your CaseProtocol is not Matching RunTimeActuator"; DealExecutiveError(myResult.backContent); } if (errorList.Count > 0) { myResult.additionalError = errorList.MyToString("\r\n"); } return(myResult); }
public MyExecutionDeviceResult ExecutionDeviceRun(ICaseExecutionContent yourExecutionContent, CaseActionActuator.delegateGetExecutiveData yourExecutiveDelegate, string sender, ActuatorStaticDataCollection yourActuatorStaticDataCollection, int caseId) { List <string> errorList = new List <string>(); string tempError = null; MyExecutionDeviceResult myResult = new MyExecutionDeviceResult(); myResult.staticDataResultCollection = new System.Collections.Specialized.NameValueCollection(); //向UI推送执行过程信息 Action <string, CaseActuatorOutPutType, string> ExecutiveDelegate = (innerSender, outType, yourContent) => { if (yourExecutiveDelegate != null) { yourExecutiveDelegate(innerSender, outType, yourContent); } }; //处理执行错误(执行器无法执行的错误) Action <string> DealExecutiveError = (errerData) => { if (errerData != null) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, errerData); errorList.Add(errerData); } }; if (yourExecutionContent.MyCaseProtocol == CaseProtocol.com) { //在调用该函数前保证nowExecutionContent.ErrorMessage为空,且as一定成功 MyComExecutionContent nowExecutionContent = yourExecutionContent as MyComExecutionContent; myResult.caseProtocol = CaseProtocol.com; myResult.caseTarget = nowExecutionContent.MyExecutionTarget; myResult.startTime = DateTime.Now.ToString("HH:mm:ss"); StringBuilder tempCaseOutContent = new StringBuilder(); System.Diagnostics.Stopwatch myWatch = new System.Diagnostics.Stopwatch(); myWatch.Start(); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("【ID:{0}】[com]Executive···", caseId)); #region Send if (nowExecutionContent.isSend) { string nowComData = nowExecutionContent.comContentToSend.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); if (tempError != null) { DealExecutiveError(string.Format("this case get static data errer with [{0}]", nowExecutionContent.comContentToSend.GetTargetContentData())); tempCaseOutContent.AppendLine("error with static data"); } else { byte[] nowSendBytes; if (nowExecutionContent.comSendEncoding == null) { try { nowSendBytes = MyBytes.HexStringToByte(nowComData, HexaDecimal.hex16, ShowHexMode.space); } catch { nowSendBytes = null; } } else { try { nowSendBytes = nowExecutionContent.comSendEncoding.GetBytes(nowComData); } catch { nowSendBytes = null; } } if (nowSendBytes == null) { DealExecutiveError(string.Format("can not change data to bytes with [{0}]", nowExecutionContent.comContentToSend.GetTargetContentData())); tempCaseOutContent.AppendLine("error with com data"); } else { if (mySerialPort.Send(nowSendBytes)) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, "send sucess"); tempCaseOutContent.AppendLine("send sucess"); } else { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, mySerialPort.ErroerMessage); tempCaseOutContent.AppendLine(mySerialPort.ErroerMessage); } } } } #endregion #region receive if (nowExecutionContent.isReceive) { if (nowExecutionContent.comSleepTime > 0) { System.Threading.Thread.Sleep(nowExecutionContent.comSleepTime); } byte[] recweiveBytes = mySerialPort.ReadAllBytes(); if (recweiveBytes != null) { string receiveStr; if (nowExecutionContent.comReceiveEncoding == null) { receiveStr = MyBytes.ByteToHexString(recweiveBytes, HexaDecimal.hex16, ShowHexMode.space); } else { try { receiveStr = nowExecutionContent.comReceiveEncoding.GetString(recweiveBytes); } catch { receiveStr = null; } } if (receiveStr != null) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, receiveStr); tempCaseOutContent.AppendLine(receiveStr); } else { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, string.Format("can not Encoding your data with {0}", MyBytes.ByteToHexString(recweiveBytes, HexaDecimal.hex16, ShowHexMode.space))); tempCaseOutContent.AppendLine("[error]receive data error can not encoding receive data"); } } } #endregion myWatch.Stop(); myResult.spanTime = myResult.requestTime = myWatch.ElapsedMilliseconds.ToString(); myResult.backContent = tempCaseOutContent.ToString(); } else { myResult.backContent = "error:your CaseProtocol is not Matching RunTimeActuator"; DealExecutiveError(myResult.backContent); } if (errorList.Count > 0) { myResult.additionalError = errorList.MyToString("\r\n"); } return(myResult); }
public MyExecutionDeviceResult ExecutionDeviceRun(ICaseExecutionContent yourExecutionContent, CaseActionActuator.delegateGetExecutiveData yourExecutiveDelegate, string sender, ActuatorStaticDataCollection yourActuatorStaticDataCollection, int caseId) { List <string> errorList = new List <string>(); string tempError = null; MyExecutionDeviceResult myResult = new MyExecutionDeviceResult(); myResult.staticDataResultCollection = new System.Collections.Specialized.NameValueCollection(); //向UI推送执行过程信息 Action <string, CaseActuatorOutPutType, string> ExecutiveDelegate = (innerSender, outType, yourContent) => { if (yourExecutiveDelegate != null) { yourExecutiveDelegate(innerSender, outType, yourContent); } }; //处理执行错误(执行器无法执行的错误) Action <string> DealExecutiveError = (errerData) => { if (errerData != null) { ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, errerData); errorList.Add(errerData); } }; if (yourExecutionContent.MyCaseProtocol == CaseProtocol.mysql) { //在调用该函数前保证nowExecutionContent.ErrorMessage为空,且as一定成功 MyMySqlExecutionContent nowExecutionContent = yourExecutionContent as MyMySqlExecutionContent; myResult.caseProtocol = CaseProtocol.mysql; myResult.caseTarget = nowExecutionContent.MyExecutionTarget; myResult.startTime = DateTime.Now.ToString("HH:mm:ss"); StringBuilder tempCaseOutContent = new StringBuilder(); System.Diagnostics.Stopwatch myWatch = new System.Diagnostics.Stopwatch(); myWatch.Start(); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("【ID:{0}】[mysql]Executive···", caseId)); string nowSqlCmd = nowExecutionContent.sqlContent.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError); if (tempError != null) { DealExecutiveError(string.Format("this case get static data errer with [{0}]", nowExecutionContent.sqlContent.GetTargetContentData())); tempCaseOutContent.AppendLine("error with static data"); } else { if (nowExecutionContent.isPosition) { string sqlResult = mySqlDrive.ExecuteQuery(nowSqlCmd, nowExecutionContent.rowIndex, nowExecutionContent.columnIndex); if (sqlResult == null) { tempCaseOutContent.AppendLine(string.Format("error in [ExecuteQuery] :{0}", mySqlDrive.NowError)); DealExecutiveError(mySqlDrive.NowError); } else { tempCaseOutContent.AppendLine(sqlResult); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, sqlResult); } } else { System.Data.DataTable sqlResult = mySqlDrive.ExecuteQuery(nowSqlCmd); if (sqlResult == null) { tempCaseOutContent.AppendLine(string.Format("error in [ExecuteQuery] :{0}", mySqlDrive.NowError)); DealExecutiveError(mySqlDrive.NowError); } else { string json = Newtonsoft.Json.JsonConvert.SerializeObject(sqlResult, Newtonsoft.Json.Formatting.Indented); ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, json); tempCaseOutContent.AppendLine(json); } } } myWatch.Stop(); myResult.spanTime = myResult.requestTime = myWatch.ElapsedMilliseconds.ToString(); myResult.backContent = tempCaseOutContent.ToString(); } else { myResult.backContent = "error:your CaseProtocol is not Matching RunTimeActuator"; DealExecutiveError(myResult.backContent); } if (errorList.Count > 0) { myResult.additionalError = errorList.MyToString("\r\n"); } return(myResult); }