Browse Source

完善说明;

scbc.sat2 5 năm trước cách đây
mục cha
commit
6477425988
3 tập tin đã thay đổi với 73 bổ sung61 xóa
  1. 62 41
      SATHTTP/SATHTTP/SATHTTP.cpp
  2. 8 20
      SATHTTP/SATHTTP/SATHTTP.h
  3. 3 0
      SATHTTP/SATHTTP/SATHTTP.vcproj

+ 62 - 41
SATHTTP/SATHTTP/SATHTTP.cpp

@@ -9,6 +9,22 @@
 #define new DEBUG_NEW
 #endif
 
+__if_not_exists(NotifyJobStart)
+{
+	int NotifyJobStart(std::string url, const SATParameters::STNotifyJobStartReq &stNotifyJobStartReq, SATParameters::STNotifyJobStartResp &stNotifyJobStartResp) throw()
+	{
+		return SetResult(url, stNotifyJobStartReq, stNotifyJobStartResp);
+	}
+}
+
+__if_not_exists(ProcessJob)
+{
+	int ProcessJob(std::string url, const SATParameters::STJobProcessReq &stJobProcessReq, SATParameters::STJobProcessResp &stJobProcessResp) throw()
+	{
+		return SetResultList(url, stJobProcessReq, stJobProcessResp);
+	}
+}
+
 #ifdef __CONSOLE__
 
 // 唯一的应用程序对象
@@ -82,46 +98,48 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 			stLoginResp.strStr.c_str(),
 			stLoginResp.nPortCount,
 			stLoginResp.nCompanyId,
-			stLoginResp.strRunnerToken.c_str());
-
-		// ##########################更新设备信息##############################;
-		SATParameters::STUpdateDeviceReq stUpdateDeviceReq;
-		SATParameters::STUpdateDeviceResp stUpdateDeviceResp;
-		__if_not_exists(url)
-		{			
-			std::string url = host + "/btc_execute_se/ajaxInteractiveManage!updateDeviceMessage.action";
-		}
-		__if_exists(url)
-		{
-			url = host + "/btc_execute_se/ajaxInteractiveManage!updateDeviceMessage.action";
-		}
-
-		stUpdateDeviceReq.strStatus = "0";
-		stUpdateDeviceReq.strUserName = "superAdmin";		
-		stUpdateDeviceReq.strIP = "10.118.158.175";
-		stUpdateDeviceReq.strStorage = "228092536KB";
-		stUpdateDeviceReq.strRunnerName = "SAT-Admin";
-		stUpdateDeviceReq.strMAC = "40:16:7e:23:10:53";
-		stUpdateDeviceReq.strReportType = "1";
-		stUpdateDeviceReq.strStartTime = "2019-12-16 19:15:30";
-		stUpdateDeviceReq.strMemory = "8938544KB";
-		stUpdateDeviceReq.strEndTime = "";
-		stUpdateDeviceReq.strCPU = "24.7%";
-		stUpdateDeviceReq.devicelist.push_back(stDevice);
-		if ( UpdateDeviceMessage(url, stUpdateDeviceReq, stUpdateDeviceResp) )
-		{
-			printf("更新设备信息成功:code=%s, msg=%s, str=%s\n",
-				stLoginResp.strCode.c_str(),
-				stLoginResp.strMessage.c_str(),
-				stLoginResp.strStr.c_str());
-		}
-		else
-		{
-			printf("更新设备信息失败!\n");
-		}
+			stLoginResp.strRunnerToken.c_str()
+			);		
 
 		while(true)
 		{
+			// ##########################更新设备信息##############################;
+			SATParameters::STUpdateDeviceReq stUpdateDeviceReq;
+			SATParameters::STUpdateDeviceResp stUpdateDeviceResp;
+			__if_not_exists(url)
+			{			
+				std::string url = host + "/btc_execute_se/ajaxInteractiveManage!updateDeviceMessage.action";
+			}
+			__if_exists(url)
+			{
+				url = host + "/btc_execute_se/ajaxInteractiveManage!updateDeviceMessage.action";
+			}
+
+			stUpdateDeviceReq.strStatus = "0";
+			stUpdateDeviceReq.strUserName = "superAdmin";		
+			stUpdateDeviceReq.strIP = "10.118.158.175";
+			stUpdateDeviceReq.strStorage = "228092536KB";
+			stUpdateDeviceReq.strRunnerName = "SAT-Admin";
+			stUpdateDeviceReq.strMAC = "40:16:7e:23:10:53";
+			stUpdateDeviceReq.strReportType = "1";
+			stUpdateDeviceReq.strStartTime = "2019-12-16 19:15:30";
+			stUpdateDeviceReq.strMemory = "8938544KB";
+			stUpdateDeviceReq.strEndTime = "";
+			stUpdateDeviceReq.strCPU = "24.7%";
+			stUpdateDeviceReq.devicelist.push_back(stDevice);
+
+			if ( UpdateDeviceMessage(url, stUpdateDeviceReq, stUpdateDeviceResp) )
+			{
+				printf("更新设备信息成功:code=%s, msg=%s, str=%s\n",
+					stLoginResp.strCode.c_str(),
+					stLoginResp.strMessage.c_str(),
+					stLoginResp.strStr.c_str());
+			}
+			else
+			{
+				printf("更新设备信息失败!\n");
+			}
+
 			// ##########################心跳包机制##############################;
 			SATParameters::STHeartbeatReq stHeartbeatReq;
 			SATParameters::STHeartbeatResp stHeartbeatResp;
@@ -135,8 +153,8 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 			}
 
 			// 示例值;
-			stDevice.strStatus = "0";
-			stDevice.strDeviceSerial = "192.168.1.119:5555";
+			//stDevice.strStatus = "0";
+			//stDevice.strDeviceSerial = "192.168.1.119:5555";
 
 			stHeartbeatReq.strUserName = "superAdmin";
 			stHeartbeatReq.strRunnerMac = "40:16:7e:23:10:53";
@@ -184,6 +202,9 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 					// 查询任务是否已在SAT上存在;
 					if ( NotifyJobStart(url, stNotifyJobStartReq, stNotifyJobStartResp) )
 					{
+						// 更新设备为忙碌状态;
+						//stDevice.strStatus =  "2"; // 忙碌状态,此时请求Heartbeat将不会查询任务;
+						stDevice.strStatus = "2";
 						printf("NotifyJobStart 成功\n");
 					}
 					else
@@ -205,7 +226,7 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 					}
 
 					{
-						stJobProcessReq.strResultState = "";
+						stJobProcessReq.strResultState = "1";
 						stJobProcessReq.strCaseScene = "";
 						stJobProcessReq.strCaseStep = "0";
 						stJobProcessReq.strApkMD5 = "";
@@ -255,7 +276,7 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 						stJobProcessReq.strOperationStep = "";
 					}
 
-					// 向SAT上报:任务开始,请SAT变更任务状态;
+					// 
 					if ( ProcessJob(url, stJobProcessReq, stJobProcessResp) )
 					{
 						// 开始下载脚本;

+ 8 - 20
SATHTTP/SATHTTP/SATHTTP.h

@@ -11,7 +11,9 @@
 #endif
 
 // 此类是从 SATHTTP.dll 导出的
-class SATHTTP_API CSATHTTP {
+class SATHTTP_API CSATHTTP 
+{
+	std::string url;
 public:
 	CSATHTTP(void);
 	// TODO: 在此添加您的方法。
@@ -21,7 +23,7 @@ namespace SATParameters{
 	//////////////////////////////////////////////////////////////////////////
 	// 通用的结构体;
 	typedef struct __ST_DEVICE__{
-		std::string strStatus;
+		std::string strStatus;				// 0表示设备空闲; 1表示设备忙碌
 		std::string strDeviceSerial;
 		std::string strHardwareVersion;
 		std::string strManu;
@@ -123,7 +125,7 @@ namespace SATParameters{
 		std::string strDeviceId;
 		std::string strLoopNumber;
 		std::vector<std::string> vtEmails;
-		std::string strTaskType;
+		std::string strTaskType;	// 1=表示SAT任务可执行, 2=表示SAT上停止了任务,请在执行完当前脚本后退出; 3=表示SAT上停止任务,并要求马上停止;
 		std::string strMonkeyFrequency;
 		std::string strCloudVersion;
 		std::string strTaskInstanceName;
@@ -171,7 +173,7 @@ namespace SATParameters{
 		std::string strStartTime;
 		std::string strStopTime;
 		std::string strTaskName;
-		int Id;
+		int Id;			// 注意:对应__ST_NOTIFY_JOB_START_REQ__的strInstanceId,而非__ST_TASK__.nInstanceId;
 		int fd;
 		int nTaskId;
 		STJob Job;
@@ -202,7 +204,7 @@ namespace SATParameters{
 	// 5、SetResultList;
 	typedef struct __ST_JOB_PROCESS_REQ__
 	{
-		std::string strResultState;
+		std::string strResultState;		// 空表示Runner开始执行任务; 1=表示Runner已执行完成任务;
 		std::string strCaseScene;
 		std::string strCaseStep;
 		std::string strApkMD5;
@@ -284,25 +286,11 @@ SATHTTP_API int UpdateDeviceMessage(std::string url, const SATParameters::STUpda
 SATHTTP_API int Heartbeat(std::string url, const SATParameters::STHeartbeatReq &stHeartbeatReq, SATParameters::STHeartbeatResp &stHeartbeatResp) throw();
 
 // 从心跳包中获取到任务后,通知SAT任务开始(变更SAT上的任务状态);
+// 注意坑:STNotifyJobStartReq.strInstanceId引用的是STTask.Id而非STTask.nInstanceId
 SATHTTP_API int SetResult(std::string url, const SATParameters::STNotifyJobStartReq &stNotifyJobStartReq, SATParameters::STNotifyJobStartResp &stNotifyJobStartResp) throw();
 
-__if_not_exists(NotifyJobStart)
-{
-	SATHTTP_API int NotifyJobStart(std::string url, const SATParameters::STNotifyJobStartReq &stNotifyJobStartReq, SATParameters::STNotifyJobStartResp &stNotifyJobStartResp) throw()
-	{
-		return SetResult(url, stNotifyJobStartReq, stNotifyJobStartResp);
-	}
-}
-
 // 通知SAT用例脚本已开始;
 SATHTTP_API int SetResultList(std::string url, const SATParameters::STJobProcessReq &stJobProcessReq, SATParameters::STJobProcessResp &stJobProcessResp) throw();
-__if_not_exists(ProcessJob)
-{
-	SATHTTP_API int ProcessJob(std::string url, const SATParameters::STJobProcessReq &stJobProcessReq, SATParameters::STJobProcessResp &stJobProcessResp) throw()
-	{
-		return SetResultList(url, stJobProcessReq, stJobProcessResp);
-	}
-}
 
 SATHTTP_API int GetCaseFileListUrl(std::string url, std::string strCaseId, SATParameters::STScriptUrlResp &stScriptUrlResp) throw();
 SATHTTP_API int DownloadScript(std::string url, std::string strCaseId, std::string strSaveDir, SATParameters::STScriptUrlResp &stScriptUrlResp) throw();

+ 3 - 0
SATHTTP/SATHTTP/SATHTTP.vcproj

@@ -89,6 +89,7 @@
 			/>
 			<Tool
 				Name="VCPostBuildEventTool"
+				CommandLine="copy $(TargetDir)$(TargetName).lib ..\..\SATService\SATService\$(TargetName).lib /y/a&#x0D;&#x0A;copy $(TargetName).h ..\..\SATService\SATService\$(TargetName).h /y/a"
 			/>
 		</Configuration>
 		<Configuration
@@ -96,6 +97,7 @@
 			OutputDirectory="..\..\..\..\bin\$(SolutionName)"
 			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)"
 			ConfigurationType="2"
+			UseOfMFC="2"
 			CharacterSet="2"
 			WholeProgramOptimization="1"
 			>
@@ -166,6 +168,7 @@
 			/>
 			<Tool
 				Name="VCPostBuildEventTool"
+				CommandLine="copy $(TargetDir)$(TargetName).lib ..\..\SATService\SATService\$(TargetName).lib /y/a&#x0D;&#x0A;copy $(TargetName).h ..\..\SATService\SATService\$(TargetName).h /y/a"
 			/>
 		</Configuration>
 		<Configuration