|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
#include "SATHTTP.h"
|
|
|
+#include <direct.h>
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
#define new DEBUG_NEW
|
|
@@ -16,6 +17,8 @@ CWinApp theApp;
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
+bool MKDIR(LPCTSTR dir);
|
|
|
+
|
|
|
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
|
|
|
{
|
|
|
int nRetCode = 0;
|
|
@@ -50,7 +53,7 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
|
|
|
stDevice.strLastJob = "";
|
|
|
stDevice.strLastTimeConnected = "2019-12-16 10:16:01";
|
|
|
stDevice.strElectric = "";
|
|
|
- //////////////////////////////////////////////////////////////////////////
|
|
|
+ // ##########################先登录##############################;
|
|
|
SATParameters::STLoginReq stLoginReq;
|
|
|
SATParameters::STLoginResp stLoginResp;
|
|
|
std::string url = host + "/btc_execute_se/ajaxInteractiveManage!executeLogin.action";
|
|
@@ -67,7 +70,6 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
|
|
|
stLoginReq.strPassword = "123456";
|
|
|
stLoginReq.strCPU = "";
|
|
|
|
|
|
- // ##########################先登录##############################;
|
|
|
if ( !Login(url, stLoginReq, stLoginResp) )
|
|
|
{
|
|
|
system("pause");
|
|
@@ -145,6 +147,142 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
|
|
|
stHeartbeatResp.strCode.c_str(),
|
|
|
stHeartbeatResp.strMessage.c_str(),
|
|
|
stHeartbeatResp.strStr.c_str());
|
|
|
+
|
|
|
+ // 判断是否有任务获取成功;
|
|
|
+ if ( stHeartbeatResp.vtTask.size() )
|
|
|
+ {
|
|
|
+ // #########################################################################################
|
|
|
+ // 判断任务是否在SAT上存在;(感觉没什么意义!!!)
|
|
|
+ SATParameters::STTask stTask = stHeartbeatResp.vtTask[0];
|
|
|
+ SATParameters::STNotifyJobStartReq stNotifyJobStartReq;
|
|
|
+ SATParameters::STNotifyJobStartResp stNotifyJobStartResp;
|
|
|
+
|
|
|
+ TCHAR szValue[36] = {0};
|
|
|
+ _itoa_s(stTask.nDeviceId, szValue, 10);
|
|
|
+ stNotifyJobStartReq.strDeviceId = szValue;
|
|
|
+
|
|
|
+ _itoa_s(stTask.nExecuteId, szValue, 10);
|
|
|
+ stNotifyJobStartReq.strExecuteId = szValue;
|
|
|
+
|
|
|
+ _itoa_s(stTask.nInstanceId, szValue, 10);
|
|
|
+ stNotifyJobStartReq.strInstanceId = szValue;
|
|
|
+
|
|
|
+ _itoa_s(stTask.nTaskId, szValue, 10);
|
|
|
+ stNotifyJobStartReq.strTaskId = szValue;
|
|
|
+
|
|
|
+ stNotifyJobStartReq.strSignalImageUrl = "D:\\SAT\\Runner\\btc_runner_se\\runner\\output\\ODF_NPI_RT2841\\20191216101613370\\192.168.1.119_5555";
|
|
|
+
|
|
|
+ __if_not_exists(url)
|
|
|
+ {
|
|
|
+ std::string url = host + "/btc_execute_se/ajaxInteractiveManage!setResult.action";
|
|
|
+ }
|
|
|
+ __if_exists(url)
|
|
|
+ {
|
|
|
+ url = host + "/btc_execute_se/ajaxInteractiveManage!setResult.action";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询任务是否已在SAT上存在;
|
|
|
+ if ( NotifyJobStart(url, stNotifyJobStartReq, stNotifyJobStartResp) )
|
|
|
+ {
|
|
|
+ printf("NotifyJobStart 成功\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ printf("NotifyJobStart 失败\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ // #########################################################################################
|
|
|
+ // 开始Job;
|
|
|
+ SATParameters::STJobProcessReq stJobProcessReq;
|
|
|
+ SATParameters::STJobProcessResp stJobProcessResp;
|
|
|
+ __if_not_exists(url)
|
|
|
+ {
|
|
|
+ std::string url = host + "/btc_execute_se/ajaxInteractiveManage!setResultList.action";
|
|
|
+ }
|
|
|
+ __if_exists(url)
|
|
|
+ {
|
|
|
+ url = host + "/btc_execute_se/ajaxInteractiveManage!setResultList.action";
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ stJobProcessReq.strResultState = "";
|
|
|
+ stJobProcessReq.strCaseScene = "";
|
|
|
+ stJobProcessReq.strCaseStep = "0";
|
|
|
+ stJobProcessReq.strApkMD5 = "";
|
|
|
+ stJobProcessReq.strCrashTime = "";
|
|
|
+ // 就是Task中的ExecuteId
|
|
|
+ _itoa_s(stTask.nExecuteId, szValue, 10);
|
|
|
+ stJobProcessReq.strRunnerId = szValue;
|
|
|
+ stJobProcessReq.strCPUInfo = "0";
|
|
|
+ stJobProcessReq.strRunnedActionNameList = "";
|
|
|
+ stJobProcessReq.strArtificialResult = "";
|
|
|
+ stJobProcessReq.strArtificialModify = "";
|
|
|
+ stJobProcessReq.strRunnerName = "";
|
|
|
+ stJobProcessReq.strTaskType = "FUNCTIONALITY";
|
|
|
+ stJobProcessReq.strCaseRepeat = "";
|
|
|
+ stJobProcessReq.strApplicationGroup = "";
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(stTask.nInstanceId, szValue, 10);
|
|
|
+ stJobProcessReq.strInstanceId = szValue;
|
|
|
+ stJobProcessReq.strCaseId = "";
|
|
|
+ stJobProcessReq.strProgress = "0";
|
|
|
+ stJobProcessReq.strReusltMessage = "任务开始";
|
|
|
+ stJobProcessReq.strJobRepeat = "";
|
|
|
+ stJobProcessReq.strScreenShot = "";
|
|
|
+ stJobProcessReq.strStartTime = "2019-12-16 10:16:43";
|
|
|
+ stJobProcessReq.strCrashNumber = "";
|
|
|
+ stJobProcessReq.strCaseName = "";
|
|
|
+ stJobProcessReq.strFailedReason = "";
|
|
|
+ stJobProcessReq.strImgName = "";
|
|
|
+ stJobProcessReq.strCaseIndex = "";
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(stTask.nDeviceId, szValue, 10);
|
|
|
+ stJobProcessReq.strDeviceId = szValue;
|
|
|
+ stJobProcessReq.strSceneIndex = "";
|
|
|
+ // 实例Id;
|
|
|
+ _itoa_s(stTask.nTaskId, szValue, 10);
|
|
|
+ stJobProcessReq.strTaskId = szValue;
|
|
|
+ stJobProcessReq.strAnalysis = "";
|
|
|
+ // 设备名称:即DeviceSerial;
|
|
|
+ stJobProcessReq.strDevnceName = stDevice.strDeviceSerial;
|
|
|
+ // 固定为:TOTAL
|
|
|
+ stJobProcessReq.strInfoType = "TOTAL";
|
|
|
+ // 如果是Android设备,需要通过adb获取;
|
|
|
+ stJobProcessReq.strMemoryInfo = stDevice.strMemory;
|
|
|
+ stJobProcessReq.strEndTime = "2019-12-16 10:18:20";
|
|
|
+ stJobProcessReq.strRoundNumber = "1";
|
|
|
+ stJobProcessReq.strResultType = "0";
|
|
|
+ stJobProcessReq.strOperationStep = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 向SAT上报:任务开始,请SAT变更任务状态;
|
|
|
+ if ( ProcessJob(url, stJobProcessReq, stJobProcessResp) )
|
|
|
+ {
|
|
|
+ // 开始下载脚本;
|
|
|
+ __if_not_exists(url)
|
|
|
+ {
|
|
|
+ std::string url = host + "/btc_caseManagement_se/ajaxInteractiveManage!getCaseFileListUrl.action";
|
|
|
+ }
|
|
|
+ __if_exists(url)
|
|
|
+ {
|
|
|
+ url = host + "/btc_caseManagement_se/ajaxInteractiveManage!getCaseFileListUrl.action";
|
|
|
+ }
|
|
|
+
|
|
|
+ SATParameters::STScriptUrlResp stScriptUrlResp;
|
|
|
+ std::vector<SATParameters::STCase>::iterator it = stTask.Job.vtCases.begin();
|
|
|
+ for ( ; it != stTask.Job.vtCases.end(); it++ )
|
|
|
+ {
|
|
|
+ if ( DownloadScript(url, it->strId, "D:\\SAT\\", stScriptUrlResp) )
|
|
|
+ {
|
|
|
+ printf("获取脚本下载地址成功:%s\n路径:%s\n", stScriptUrlResp.strURL.c_str(), stScriptUrlResp.strScripFile.c_str());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ printf("获取脚本下载地址失败\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Sleep(3000);
|
|
@@ -159,7 +297,41 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
|
|
|
|
|
|
#endif //__CONSOLE__
|
|
|
|
|
|
+bool MKDIR(LPCTSTR dir)
|
|
|
+{
|
|
|
+ //////////////////////////////////////////////////////////////////////////
|
|
|
+ // 创建目录;
|
|
|
+ int nleft = 0;
|
|
|
+ int nIndex = -1;
|
|
|
+ std::string strdir = dir;
|
|
|
+ strdir = strdir.substr(0, strdir.find_last_of(_T("\\")));
|
|
|
+
|
|
|
+ if (strdir.at(strdir.size() - 1) != _T('\\'))
|
|
|
+ strdir.append(_T("\\"));
|
|
|
+
|
|
|
+ // 共享路径和硬盘盘符;
|
|
|
+ if (_tcscmp(strdir.substr(0, 2).c_str(), _T("\\\\")) == 0)
|
|
|
+ nleft = strdir.find_first_of(_T("\\"), 2) + 1; // 去除共享主机名;
|
|
|
+ else if (strdir.at(2) == _T('\\'))
|
|
|
+ nleft = 3;
|
|
|
+
|
|
|
+ do
|
|
|
+ {
|
|
|
+ nIndex = strdir.substr(nleft, -1).find_first_of(_T("\\"));
|
|
|
+
|
|
|
+ if (nIndex != string::npos)
|
|
|
+ {
|
|
|
+ if (_mkdir(strdir.substr(0, nIndex + nleft).c_str()) == -1 && (errno != EEXIST))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ nleft += nIndex + 1;
|
|
|
+ }
|
|
|
+ } while (nIndex != -1);
|
|
|
|
|
|
+ return true;
|
|
|
+};
|
|
|
|
|
|
SATHTTP_API int Login(std::string url, const SATParameters::STLoginReq &stLoginReq, SATParameters::STLoginResp &stLoginResp)
|
|
|
{
|
|
@@ -769,7 +941,7 @@ SATHTTP_API int SetResultList(std::string url, const SATParameters::STJobProcess
|
|
|
cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
|
|
|
if (pObj != NULL)
|
|
|
{
|
|
|
-
|
|
|
+ stJobProcessResp.strIsDelete = cJSON_GetObjectItem(pObj, "isDelete") ? (cJSON_GetObjectItem(pObj, "isDelete")->valuestring ? cJSON_GetObjectItem(pObj, "isDelete")->valuestring : "") : "";
|
|
|
}
|
|
|
|
|
|
// 释放内存;
|
|
@@ -855,7 +1027,11 @@ SATHTTP_API int GetCaseFileListUrl(std::string url, std::string strCaseId, SATPa
|
|
|
{
|
|
|
cJSON *pScripURL = cJSON_GetArrayItem(pObj, 0);
|
|
|
if ( pScripURL )
|
|
|
+ {
|
|
|
stScriptUrlResp.strURL = cJSON_GetObjectItem(pScripURL, "url") ? (cJSON_GetObjectItem(pScripURL, "url")->valuestring ? cJSON_GetObjectItem(pScripURL, "url")->valuestring : "") : "";
|
|
|
+ // 同时下载脚本目录到指定目录中;
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -872,5 +1048,118 @@ SATHTTP_API int GetCaseFileListUrl(std::string url, std::string strCaseId, SATPa
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ return FALSE;
|
|
|
+}
|
|
|
+
|
|
|
+SATHTTP_API int DownloadScript(std::string url, std::string strCaseId, std::string strSaveDir, SATParameters::STScriptUrlResp &stScriptUrlResp)
|
|
|
+{
|
|
|
+ // 转化为Json;
|
|
|
+ cJSON *pRoot = cJSON_CreateObject();
|
|
|
+ if ( pRoot == NULL )
|
|
|
+ {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ ASSERT(cJSON_AddStringToObject(pRoot, "sysCode", "Execute"));
|
|
|
+ ASSERT(cJSON_AddStringToObject(pRoot, "function", "getCaseFileListUrl"));
|
|
|
+ cJSON *pData = cJSON_CreateObject();
|
|
|
+ if ( pData )
|
|
|
+ {
|
|
|
+ ASSERT(cJSON_AddStringToObject(pData, "testCaseId", strCaseId.c_str()));
|
|
|
+ // 添加到根结点中;
|
|
|
+ cJSON_AddItemToObject(pRoot, "data", pData);
|
|
|
+ }
|
|
|
+
|
|
|
+ char *pText = cJSON_Print(pRoot);
|
|
|
+ std::string post_data = "requestMsg=";
|
|
|
+ post_data.append(CharEncoding::EnCode_UTF8URL(pText));
|
|
|
+
|
|
|
+ // 释放堆内存;
|
|
|
+ if (pText)
|
|
|
+ delete pText;
|
|
|
+ pText = NULL;
|
|
|
+
|
|
|
+ if ( pRoot )
|
|
|
+ cJSON_Delete(pRoot);
|
|
|
+ pRoot = NULL;
|
|
|
+
|
|
|
+ CCurlClient curl;
|
|
|
+ std::string reponse;
|
|
|
+ CURLcode curlCode = CURLE_OK;
|
|
|
+ if ( CURLE_OK == curl.Initialize() )
|
|
|
+ {
|
|
|
+ if (_tcsstr(url.c_str(), "https://") || _tcsstr(url.c_str(), "HTTPS://") )
|
|
|
+ curlCode = curl.Posts(url, post_data, reponse);
|
|
|
+ else
|
|
|
+ curlCode = curl.Post(url, post_data, reponse);
|
|
|
+
|
|
|
+ if ( curlCode == CURLE_OK )
|
|
|
+ {
|
|
|
+ reponse = CharEncoding::DeCode_URLUTF8(reponse.c_str());
|
|
|
+
|
|
|
+ // 解析返回值;
|
|
|
+ pRoot = cJSON_Parse(reponse.c_str());
|
|
|
+ if (pRoot != NULL)
|
|
|
+ {
|
|
|
+ cJSON *pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
|
|
|
+ if ( pMsg )
|
|
|
+ {
|
|
|
+ stScriptUrlResp.strCode = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
|
|
|
+ stScriptUrlResp.strMessage = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
|
|
|
+ stScriptUrlResp.strProjectId = cJSON_GetObjectItem(pMsg, "strProjectId") ? (cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring ? cJSON_GetObjectItem(pMsg, "strProjectId")->valuestring : "") : "";
|
|
|
+ stScriptUrlResp.strCaseType = cJSON_GetObjectItem(pMsg, "caseType") ? (cJSON_GetObjectItem(pMsg, "caseType")->valuestring ? cJSON_GetObjectItem(pMsg, "caseType")->valuestring : "") : "";
|
|
|
+ if ( stScriptUrlResp.strCode == "00" )
|
|
|
+ {
|
|
|
+ cJSON *pObj = cJSON_GetObjectItem(pMsg, "data");
|
|
|
+ if (pObj != NULL)
|
|
|
+ {
|
|
|
+ if ( cJSON_GetArraySize(pObj) >= 1 )
|
|
|
+ {
|
|
|
+ cJSON *pScripURL = cJSON_GetArrayItem(pObj, 0);
|
|
|
+ if ( pScripURL )
|
|
|
+ {
|
|
|
+ stScriptUrlResp.strURL = cJSON_GetObjectItem(pScripURL, "url") ? (cJSON_GetObjectItem(pScripURL, "url")->valuestring ? cJSON_GetObjectItem(pScripURL, "url")->valuestring : "") : "";
|
|
|
+ std::string strFileDir;
|
|
|
+ std::string strFileName;
|
|
|
+ int nPos1 = 0, nPos2 = 0;
|
|
|
+ nPos1 = stScriptUrlResp.strURL.find("fileDir=");
|
|
|
+ nPos2 = stScriptUrlResp.strURL.find("&fileName=");
|
|
|
+ if ( nPos1 != std::string::npos && nPos2 != std::string::npos )
|
|
|
+ {
|
|
|
+ strFileDir = stScriptUrlResp.strURL.substr(nPos1 + strlen("fileDir="), nPos2 - nPos1 - strlen("fileDir="));
|
|
|
+ strFileName = stScriptUrlResp.strURL.substr(nPos2 + strlen("&fileName="));
|
|
|
+ //strSavePath.append(strFileDir + "\\" + strFileName);
|
|
|
+ CString strPath = strSaveDir.c_str();
|
|
|
+ strPath.TrimRight('\\');
|
|
|
+ strPath += strFileDir.c_str();
|
|
|
+ strPath.Replace('/', '\\');
|
|
|
+ strSaveDir = strPath.GetString();
|
|
|
+ strSaveDir.append("\\"+strFileName);
|
|
|
+ // 创建目录;
|
|
|
+ if ( MKDIR(strSaveDir.c_str()) )
|
|
|
+ {
|
|
|
+ // 同时下载脚本目录到指定目录中;
|
|
|
+ if ( curl.Download(stScriptUrlResp.strURL, strSaveDir, 10000) )
|
|
|
+ {
|
|
|
+ stScriptUrlResp.strScripFile = strSaveDir;
|
|
|
+ // 释放内存;
|
|
|
+ cJSON_Delete(pRoot);
|
|
|
+ // 返回结果;
|
|
|
+ return TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 错误产生,可输出msg方便查询;
|
|
|
+ cJSON_Delete(pRoot);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return FALSE;
|
|
|
}
|