Przeglądaj źródła

脚本执行流程:差上报任务结果 ;

scbc.sat2 5 lat temu
rodzic
commit
7726de69b3

+ 130 - 0
SATService/SATService/Base64.cpp

@@ -0,0 +1,130 @@
+#include "stdafx.h"
+#include "Base64.h"
+
+CBase64::CBase64(void)
+{
+}
+
+CBase64::~CBase64(void)
+{
+}
+
+const char CBase64::sm_base64digits[65] =
+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+const char CBase64::sm_base64val[128] = {
+	BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD,
+	BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD,
+	BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD, 62, BAD,BAD,BAD, 63,
+	52, 53, 54, 55,  56, 57, 58, 59,  60, 61,BAD,BAD, BAD,BAD,BAD,BAD,
+	BAD,  0,  1,  2,   3,  4,  5,  6,   7,  8,  9, 10,  11, 12, 13, 14,
+	15, 16, 17, 18,  19, 20, 21, 22,  23, 24, 25,BAD, BAD,BAD,BAD,BAD,
+	BAD, 26, 27, 28,  29, 30, 31, 32,  33, 34, 35, 36,  37, 38, 39, 40,
+	41, 42, 43, 44,  45, 46, 47, 48,  49, 50, 51,BAD, BAD,BAD,BAD,BAD
+};
+
+/************************************************************************/
+/*  函数:[6/2/2016 IT];
+/*  描述:将字节转换为Base64字符;
+/*  参数:;
+/*  	[IN] pbinary:			要转换成Base64字符的二进制字节数组;
+/*  	[IN] nbinaryLen:		pbinary所指向的缓存大小;
+/*  	[OUT] pOutBase64:		返回转换后的Base64字符,以'\0'结束;
+/*  返回:返回转换成功后的Base64字符数;
+/*  注意:注意参数1是字节BYTE,返回的pOutBase64是人为加上'\0'结束符;
+/*  示例:;
+/*
+/*  修改:;
+/*  日期:;
+/*  内容:;
+/************************************************************************/
+void CBase64::binToBase64(IN const unsigned char *pbinary, IN size_t nbinaryLen, OUT char *pOutBase64)
+{
+	for ( ; nbinaryLen >= 3; nbinaryLen -= 3, pbinary += 3) 
+	{
+		*pOutBase64++ = sm_base64digits[pbinary[0] >> 2];
+		*pOutBase64++ = sm_base64digits[((pbinary[0] << 4) & 0x30) | (pbinary[1] >> 4)];
+		*pOutBase64++ = sm_base64digits[((pbinary[1] << 2) & 0x3c) | (pbinary[2] >> 6)];
+		*pOutBase64++ = sm_base64digits[pbinary[2] & 0x3f];
+	}
+
+	if (nbinaryLen > 0) 
+	{
+		unsigned char fragment;
+		*pOutBase64++ = sm_base64digits[pbinary[0] >> 2];
+		fragment = (pbinary[0] << 4) & 0x30;
+
+		if (nbinaryLen > 1)
+			fragment |= pbinary[1] >> 4;
+
+		*pOutBase64++ = sm_base64digits[fragment];
+		*pOutBase64++ = (nbinaryLen < 2) ? '=' : sm_base64digits[(pbinary[1] << 2) & 0x3c];
+		*pOutBase64++ = '=';
+	}
+	*pOutBase64 = '\0';
+}
+
+/************************************************************************/
+/*  函数:[6/2/2016 IT];
+/*  描述:将Base64字符串转为化二进制字节字符串;
+/*  参数:;
+/*  	[IN] pBase64:		要转化成二进制字节字符串的Base64字符;
+/*  	[OUT] pbinary:		返回转化成二进制字节的字符串;
+/*  	[IN] maxLen:		pbinary指向的缓存大小;
+/*  返回:返回转化成二进制字节字符数;
+/*  注意:;
+/*  示例:;
+/*
+/*  修改:;
+/*  日期:;
+/*  内容:;
+/************************************************************************/
+int CBase64::base64ToBin(IN const char *pBase64, OUT unsigned char *pbinary, IN size_t maxLen)
+{
+	size_t len = 0;
+	unsigned char digit1, digit2, digit3, digit4;
+
+	if (pBase64[0] == '+' && pBase64[1] == ' ')
+		pBase64 += 2;
+	if (pBase64[0] == '\r')
+		return 0;
+
+	while (*pBase64 && *pBase64 != '\r' /*&& digit4 != '='*/) 
+	{
+		digit1 = pBase64[0];
+		if (decode64(digit1) == BAD)
+			return -1;
+		digit2 = pBase64[1];
+		if (decode64(digit2) == BAD)
+			return -1;
+		digit3 = pBase64[2];
+		if (digit3 != '=' && decode64(digit3) == BAD)
+			return -1; 
+		digit4 = pBase64[3];
+		if (digit4 != '=' && decode64(digit4) == BAD)
+			return -1;
+		pBase64 += 4;
+
+		++len;
+		if (maxLen && len > maxLen)
+			return -1;
+
+		*(pbinary++) = (decode64(digit1) << 2) | (decode64(digit2) >> 4);
+		if (digit3 != '=') 
+		{
+			++len;
+			if (maxLen && len > maxLen)
+				return -1;
+			*(pbinary++) = ((decode64(digit2) << 4) & 0xf0) | (decode64(digit3) >> 2);
+			if (digit4 != '=') 
+			{
+				++len;
+				if (maxLen && len > maxLen)
+					return -1;
+				*(pbinary++) = ((decode64(digit3) << 6) & 0xc0) | decode64(digit4);
+			} // if
+		} // if
+	} // while
+
+	return len;
+}

+ 70 - 0
SATService/SATService/Base64.h

@@ -0,0 +1,70 @@
+/************************************************************************/
+/*  Copyright (C), 2016-2020, [IT], 保留所有权利;
+/*  模 块 名:;
+/*  描    述:;
+/*
+/*  版    本:[V];	
+/*  作    者:[IT];
+/*  日    期:[5/24/2016];
+/*
+/*
+/*  注    意:;
+/*
+/*  修改记录:[IT];
+/*  修改日期:;
+/*  修改版本:;
+/*  修改内容:;
+/************************************************************************/
+#ifndef __BASE64_CODE__
+#define __BASE64_CODE__
+
+#pragma once
+
+class CBase64
+{
+public:
+	CBase64(void);
+	~CBase64(void);
+
+	/************************************************************************/
+	/*  函数:[5/24/2016 IT];
+	/*  描述:获取指定字符串长度对应的Base64字符长度;
+	/*  参数:;
+	/*  	[IN] len:要计算的字符长度;
+	/*  返回:返回指定长度len的字符串转换为编码Base64对应的长度,并多加一个'\0'结束符;
+	/*  注意:;
+	/************************************************************************/
+	static int CalcBase64Len(IN const size_t& len) {
+		return (len / 3 + (len % 3 ? 1 : 0)) * 4 + 1; // one more byte for '\0'
+	}
+
+	static void binToBase64(IN const unsigned char *pbinary, IN size_t nbinaryLen, OUT char *pOutBase64);
+
+	/************************************************************************/
+	/*  函数:[5/24/2016 IT];
+	/*  描述:获取指定Base64字符串长度对应的字节长度;
+	/*  参数:;
+	/*  	[IN] len:要计算的Base64字符长度;
+	/*  返回:返回指定长度len的Base64字符串转换为字节对应的长度;
+	/*  注意:;
+	/************************************************************************/
+	static int CalcBinLen(size_t len) {
+		return len / 4 * 3; 
+	}
+
+	static int base64ToBin(IN const char *pBase64, OUT unsigned char *pbinary, IN size_t maxLen);
+
+private:
+	static char decode64(unsigned char ch) {
+		return ch < 128 ? sm_base64val[ch] : BAD;
+	}
+
+private:
+	enum {BAD = -1};
+	// 必须是ASCII字符;
+	static const char sm_base64digits[65];
+	// 必须是ASCII字符;
+	static const char sm_base64val[128];
+};
+
+#endif // __BASE64_CODE__

+ 740 - 0
SATService/SATService/CharEncoding.cpp

@@ -0,0 +1,740 @@
+#include "stdafx.h"
+#include "CharEncoding.h"
+
+WCHAR* CharEncoding::ASCII2UNICODE(IN LPCCH lpASCIIStr)
+{
+	if ( lpASCIIStr == NULL )
+		return NULL;
+
+	// 获取宽字符字节数;
+	int cchWideChar  = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, NULL, 0);
+	if ( cchWideChar == 0)
+		return NULL;
+
+	// 转换成宽字符串;
+	WCHAR *pWideChar = new WCHAR[cchWideChar + 1];
+	memset(pWideChar, 0 , sizeof(WCHAR)*(cchWideChar + 1));
+	int nWriteNum = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, pWideChar, cchWideChar );
+	if ( nWriteNum != cchWideChar)
+	{ 
+		if (pWideChar) 
+			delete []pWideChar;
+		return NULL;
+	}
+
+	return pWideChar;
+}
+
+BOOL CharEncoding::ASCII2UNICODE(IN LPCCH lpASCIIStr, OUT PWCH pUNICODEStr, IN CONST INT& nUNICODEStrLen)
+{
+	if ( lpASCIIStr == NULL )
+		return FALSE;
+
+	// 获取宽字符字节数;
+	int cchWideChar  = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, NULL, 0);
+	if ( cchWideChar == 0 || cchWideChar >= nUNICODEStrLen)
+		return FALSE;
+
+	// 转换成宽字符串;
+	memset(pUNICODEStr, 0 , sizeof(WCHAR)*nUNICODEStrLen);
+	int nWriteNum = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, pUNICODEStr, cchWideChar );
+	if ( nWriteNum != cchWideChar)
+		return FALSE;
+
+	return TRUE;
+}
+
+BOOL CharEncoding::ASCII2UNICODE(IN LPCCH lpASCIIStr, OUT wstring &strResult)
+{
+	if ( lpASCIIStr == NULL )
+		return FALSE;
+
+	// 获取宽字符字节数;
+	int cchWideChar  = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, NULL, 0);
+	if ( cchWideChar == 0 )
+		return FALSE;
+
+	// 转换成宽字符串;
+	WCHAR *pResult = new WCHAR[cchWideChar];
+	memset(pResult, 0 , sizeof(WCHAR)*cchWideChar);
+	int nWriteNum = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, pResult, cchWideChar );
+	if ( nWriteNum != cchWideChar)
+		return FALSE;
+
+	strResult = pResult;
+	if ( pResult )
+		delete[] pResult;
+
+	return TRUE;
+}
+
+CHAR* CharEncoding::UNICODE2ASCII(IN LPWCH lpUNICODEStr)
+{
+	if ( lpUNICODEStr == NULL )
+		return NULL;
+
+	// 获取多字节字符字节数;
+	int cbMultiByte = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
+	if ( cbMultiByte == 0 )
+		return NULL;
+
+	// 转换成多字节字符;
+	CHAR *pMultiByteStr = new CHAR[cbMultiByte+1];
+	memset(pMultiByteStr, 0, cbMultiByte + 1);
+	int nWriteNum = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, pMultiByteStr, cbMultiByte, NULL, NULL);
+	if (nWriteNum != cbMultiByte)
+	{
+		if (pMultiByteStr) 
+			delete []pMultiByteStr;
+		return NULL;
+	}
+
+	return pMultiByteStr;
+}
+
+BOOL CharEncoding::UNICODE2ASCII(IN LPWCH lpUNICODEStr, OUT LPCH pASCIIStr, IN CONST INT& nASCIIStrLen)
+{
+	if ( lpUNICODEStr == NULL )
+		return FALSE;
+
+	// 获取多字节字符字节数;
+	int cbMultiByte = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
+	if ( cbMultiByte == 0 || cbMultiByte >= nASCIIStrLen )
+		return FALSE;
+
+	// 转换成多字节字符;
+	memset((void*)pASCIIStr, 0, nASCIIStrLen);
+	int nWriteNum = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, pASCIIStr, cbMultiByte, NULL, NULL);
+	if (nWriteNum != cbMultiByte)
+	{
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+BOOL CharEncoding::UNICODE2ASCII(IN LPWCH lpUNICODEStr, OUT string &strResult)
+{
+	if ( lpUNICODEStr == NULL )
+		return FALSE;
+
+	// 获取多字节字符字节数;
+	int cbMultiByte = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
+	if ( cbMultiByte == 0 )
+		return FALSE;
+
+	// 转换成多字节字符;
+	CHAR* pResult = new CHAR[cbMultiByte];
+	memset(pResult, 0, cbMultiByte);
+	int nWriteNum = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, pResult, cbMultiByte, NULL, NULL);
+	if (nWriteNum != cbMultiByte)
+		return FALSE;
+
+	strResult = pResult;
+	if ( pResult )
+		delete[] pResult;
+
+	return TRUE;
+}
+
+CHAR* CharEncoding::UNICODE2UTF8(IN LPWCH lpUNICODEStr)
+{
+	if ( lpUNICODEStr == NULL )
+		return NULL;
+
+	// 获取多字节字符字节数;
+	int cbMultiByte = WideCharToMultiByte(CP_UTF8, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
+	if ( cbMultiByte == 0 )
+		return NULL;
+
+	// 转换成多字节字符;
+	CHAR* pMultiByteStr = new CHAR[cbMultiByte+1];
+	memset(pMultiByteStr, 0, cbMultiByte + 1);
+	int nWriteNum = WideCharToMultiByte(CP_UTF8, 0, lpUNICODEStr, -1, pMultiByteStr, cbMultiByte, NULL, NULL);
+	if (nWriteNum != cbMultiByte)
+	{
+		if (pMultiByteStr) 
+			delete []pMultiByteStr;
+		return NULL;
+	}
+
+	return pMultiByteStr;
+}
+
+BOOL CharEncoding::UNICODE2UTF8(IN LPWCH lpUNICODEStr, OUT LPCH pUTF8Str, IN CONST INT& nUTF8StrLen)
+{
+	if ( lpUNICODEStr == NULL )
+		return FALSE;
+
+	// 获取多字节字符字节数;
+	int cbMultiByte = WideCharToMultiByte(CP_UTF8, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
+	if ( cbMultiByte == 0 || cbMultiByte >= nUTF8StrLen )
+		return FALSE;
+
+	// 转换成多字节字符;
+	memset(pUTF8Str, 0, nUTF8StrLen);
+	int nWriteNum = WideCharToMultiByte(CP_UTF8, 0, lpUNICODEStr, -1, pUTF8Str, cbMultiByte, NULL, NULL);
+	if (nWriteNum != cbMultiByte)
+	{
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+BOOL CharEncoding::UNICODE2UTF8(IN LPWCH lpUNICODEStr, OUT string &strResult)
+{
+	if ( lpUNICODEStr == NULL )
+		return FALSE;
+
+	// 获取多字节字符字节数;
+	int cbMultiByte = WideCharToMultiByte(CP_UTF8, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
+	if ( cbMultiByte == 0 )
+		return FALSE;
+
+	// 转换成多字节字符;
+	CHAR *pResult = new CHAR[cbMultiByte];
+	memset(pResult, 0, cbMultiByte);
+	int nWriteNum = WideCharToMultiByte(CP_UTF8, 0, lpUNICODEStr, -1, pResult, cbMultiByte, NULL, NULL);
+	
+	strResult = pResult;
+	if ( pResult )
+		delete[] pResult;
+
+	if (nWriteNum != cbMultiByte)
+		return FALSE;
+
+	return TRUE;
+}
+
+CHAR* CharEncoding::ASCII2UTF8(IN LPCCH lpASCIIStr)
+{
+	// 将ASCII字符串转成UNICODE字符串;
+	WCHAR* pWideChar = ASCII2UNICODE(lpASCIIStr);
+	if ( pWideChar == NULL )
+		return NULL;
+
+	// 再将UICODE转成UTF8;
+	CHAR* pUTF8 = UNICODE2UTF8(pWideChar);
+	if ( pWideChar )
+		delete []pWideChar;
+
+	return pUTF8;
+}
+
+BOOL CharEncoding::ASCII2UTF8(IN LPCCH lpASCIIStr, OUT LPCH pUTF8Str, IN CONST INT& nUTF8StrLen)
+{
+	// 将ASCII字符串转成UNICODE字符串;
+	WCHAR* pWideChar = ASCII2UNICODE(lpASCIIStr);
+	if ( pWideChar == NULL )
+		return FALSE;
+
+	// 再将UICODE转成UTF8;
+	BOOL bResult = UNICODE2UTF8(pWideChar, pUTF8Str, nUTF8StrLen);
+
+	if ( pWideChar )
+		delete []pWideChar;
+
+	return bResult;
+}
+
+BOOL CharEncoding::ASCII2UTF8(IN LPCCH lpASCIIStr, OUT string &strResult)
+{
+	// 将ASCII字符串转成UNICODE字符串;
+	WCHAR* pWideChar = ASCII2UNICODE(lpASCIIStr);
+	if ( pWideChar == NULL )
+		return FALSE;
+
+	// 再将UICODE转成UTF8;
+	BOOL bResult = UNICODE2UTF8(pWideChar, strResult);
+
+	if ( pWideChar )
+		delete []pWideChar;
+
+	return bResult;
+}
+
+WCHAR* CharEncoding::UTF82UNICODE(IN LPCCH lpUTF8)
+{
+	if ( lpUTF8 == NULL )
+		return NULL;
+
+	// 获取unicode字符数;
+	int cchWideChar = MultiByteToWideChar(CP_UTF8, 0, lpUTF8, -1, NULL, 0);
+	if ( cchWideChar == 0)
+		return NULL;
+
+	// 转换成宽字符串;
+	WCHAR *pWideChar = new WCHAR[cchWideChar + 1];
+	memset(pWideChar, 0 , sizeof(WCHAR)*(cchWideChar + 1));
+	int nWriteNum = MultiByteToWideChar(CP_UTF8, 0, lpUTF8, -1, pWideChar, cchWideChar );
+	if ( nWriteNum != cchWideChar)
+	{ 
+		if (pWideChar) 
+			delete []pWideChar;
+		return NULL;
+	}
+
+	return pWideChar;
+}
+
+BOOL CharEncoding::UTF82UNICODE(IN LPCCH lpUTF8, OUT PWCH pUNICODEStr, IN CONST INT& nUNICODEStrLen)
+{
+	if ( lpUTF8 == NULL )
+		return FALSE;
+
+	// 获取宽字符字节数;
+	int cchWideChar  = MultiByteToWideChar(CP_UTF8, 0, lpUTF8, -1, NULL, 0);
+	if ( cchWideChar == 0 || cchWideChar >= nUNICODEStrLen)
+		return FALSE;
+
+	// 转换成宽字符串;
+	memset(pUNICODEStr, 0 , sizeof(WCHAR)*nUNICODEStrLen);
+	int nWriteNum = MultiByteToWideChar(CP_UTF8, 0, lpUTF8, -1, pUNICODEStr, cchWideChar );
+	if ( nWriteNum != cchWideChar)
+		return FALSE;
+
+	return TRUE;
+}
+
+BOOL CharEncoding::UTF82UNICODE(IN LPCCH lpUTF8, OUT wstring &strResult)
+{
+	if ( lpUTF8 == NULL )
+		return FALSE;
+
+	// 获取宽字符字节数;
+	int cchWideChar  = MultiByteToWideChar(CP_UTF8, 0, lpUTF8, -1, NULL, 0);
+	if ( cchWideChar == 0 )
+		return FALSE;
+
+	// 转换成宽字符串;
+	WCHAR* pResult = new WCHAR[cchWideChar];
+	memset(pResult, 0 , sizeof(WCHAR)*cchWideChar);
+	int nWriteNum = MultiByteToWideChar(CP_UTF8, 0, lpUTF8, -1, pResult, cchWideChar );
+	if ( nWriteNum != cchWideChar)
+		return FALSE;
+
+	strResult = pResult;
+	if ( pResult )
+		delete[] pResult;
+
+	return TRUE;
+}
+
+CHAR* CharEncoding::UTF82ASCII(IN LPCCH lpUTF8)
+{
+	// 将ASCII字符串转成UNICODE字符串;
+	WCHAR* pWideChar = UTF82UNICODE(lpUTF8);
+	if ( pWideChar == NULL )
+		return NULL;
+
+	// 再将UICODE转成UTF8;
+	CHAR* pUTF8 = UNICODE2ASCII(pWideChar);
+	if ( pWideChar )
+		delete []pWideChar;
+
+	return pUTF8;
+}
+
+BOOL CharEncoding::UTF82ASCII(IN LPCCH lpUTF8, OUT LPCH pASCIIStr, IN CONST INT& nASCIIStrLen)
+{
+	// 将ASCII字符串转成UNICODE字符串;
+	WCHAR* pWideChar = UTF82UNICODE(lpUTF8);
+	if ( pWideChar == NULL )
+		return FALSE;
+
+	// 再将UICODE转成UTF8;
+	BOOL bResult = UNICODE2ASCII(pWideChar, pASCIIStr, nASCIIStrLen);
+
+	if ( pWideChar )
+		delete []pWideChar;
+
+	return bResult;
+}
+
+BOOL CharEncoding::UTF82ASCII(IN LPCCH lpUTF8, OUT string &strResult)
+{
+	// 将ASCII字符串转成UNICODE字符串;
+	WCHAR* pWideChar = UTF82UNICODE(lpUTF8);
+	if ( pWideChar == NULL )
+		return FALSE;
+
+	// 再将UICODE转成UTF8;
+	BOOL bResult = UNICODE2ASCII(pWideChar, strResult);
+
+	if ( pWideChar )
+		delete []pWideChar;
+
+	return bResult;
+}
+
+//做为解Url使用
+char CharEncoding::CharToInt(char ch)
+{
+	if (ch >= '0' && ch <= '9')return (char)(ch - '0');
+	if (ch >= 'a' && ch <= 'f')return (char)(ch - 'a' + 10);
+	if (ch >= 'A' && ch <= 'F')return (char)(ch - 'A' + 10);
+	return -1;
+}
+
+char CharEncoding::StrToBin(IN char (&str)[2])
+{
+	char tempWord[2];
+	char chn;
+
+	tempWord[0] = CharToInt(str[0]);                         //make the B to 11 -- 00001011
+	tempWord[1] = CharToInt(str[1]);                         //make the 0 to 0  -- 00000000
+
+	chn = (tempWord[0] << 4) | tempWord[1];                //to change the BO to 10110000
+
+	return chn;
+}
+
+//GB2312 转为 UTF-8
+void CharEncoding::GB2312ToUTF_8(string& pOut, const char *pText, int pLen)
+{
+	char buf[4];
+	memset(buf, 0, 4);
+
+	pOut.clear();
+
+	int i = 0;
+	while (i < pLen)
+	{
+		//如果是英文直接复制就可以;
+		if (pText[i] >= 0)
+		{
+			char asciistr[2] = { 0 };
+			asciistr[0] = (pText[i++]);
+			pOut.append(asciistr);
+		}
+		else
+		{
+			WCHAR pbuffer[2] = {0};
+			MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pText + i, 2, pbuffer, 1);
+			UNICODE2UTF8(pbuffer, buf, 4);
+			pOut.append(buf);
+			i += 2;
+		}
+	}
+
+	return;
+}
+
+/************************************************************************/
+/*  函数:[7/26/2016 IT];
+/*  描述:将字符串编码成为GB2312格式的URL;;
+/*  参数:;
+/*  	[IN] :;
+/*  	[OUT] :;
+/*  	[IN/OUT] :;
+/*  返回:void;
+/*  注意:;
+/*  示例:;
+/*
+/*  修改:;
+/*  日期:;
+/*  内容:;
+/************************************************************************/
+string CharEncoding::EnCode_GB2312URL(IN const CHAR* pText)
+{
+	string dd;
+	size_t len = strlen(pText);
+	for (size_t i = 0; i < len; i++)
+	{
+		if (isalnum((BYTE)pText[i]))
+		{
+			char tempbuff[2];
+			sprintf_s(tempbuff, "%c", pText[i]);
+			dd.append(tempbuff);
+		}
+		else if (isspace((BYTE)pText[i]))
+		{
+			dd.append("+");
+		}
+		else
+		{
+			char tempbuff[4];
+			sprintf_s(tempbuff, "%%%X%X", ((BYTE*)pText)[i] >> 4, ((BYTE*)pText)[i] % 16);
+			dd.append(tempbuff);
+		}
+	}
+	return dd;
+}
+
+void CharEncoding::EnCode_GB2312URL(IN CHAR* pText, OUT string& strResult)
+{
+	size_t len = strlen(pText);
+	for (size_t i = 0; i < len; i++)
+	{
+		if (isalnum((BYTE)pText[i]))
+		{
+			char tempbuff[2];
+			sprintf_s(tempbuff, "%c", pText[i]);
+			strResult.append(tempbuff);
+		}
+		else if (isspace((BYTE)pText[i]))
+		{
+			strResult.append("+");
+		}
+		else
+		{
+			char tempbuff[4];
+			sprintf_s(tempbuff, "%%%X%X", ((BYTE*)pText)[i] >> 4, ((BYTE*)pText)[i] % 16);
+			strResult.append(tempbuff);
+		}
+	}
+}
+
+/************************************************************************/
+/*  函数:[7/26/2016 IT];
+/*  描述:;
+/*  参数:;
+/*  	[IN] :;
+/*  	[OUT] :;
+/*  	[IN/OUT] :;
+/*  返回:void;
+/*  注意:;
+/*  示例:;
+/*
+/*  修改:;
+/*  日期:;
+/*  内容:;
+/************************************************************************/
+string CharEncoding::EnCode_UTF8URL(IN const CHAR* pText)
+{
+	string tt = "";
+	string dd = "";
+	ASCII2UTF8(pText,tt);
+
+	size_t len = tt.length();
+	for (size_t i = 0; i < len; i++)
+	{
+		if (isalnum((BYTE)tt.at(i)))
+		{
+			char tempbuff[2] = { 0 };
+			sprintf_s(tempbuff, "%c", (BYTE)tt.at(i));
+			dd.append(tempbuff);
+		}
+		else if (isspace((BYTE)tt.at(i)))
+		{
+			dd.append("+");
+		}
+		else
+		{
+			char tempbuff[4];
+			sprintf_s(tempbuff, "%%%X%X", ((BYTE)tt.at(i)) >> 4, ((BYTE)tt.at(i)) % 16);
+			dd.append(tempbuff);
+		}
+	}
+	return dd;
+}
+
+void CharEncoding::EnCode_UTF8URL(IN const CHAR* pText, OUT string& strResult)
+{
+	string tt = "";
+	ASCII2UTF8(pText,tt);
+
+	size_t len = tt.length();
+	for (size_t i = 0; i < len; i++)
+	{
+		if (isalnum((BYTE)tt.at(i)))
+		{
+			char tempbuff[2] = { 0 };
+			sprintf_s(tempbuff, "%c", (BYTE)tt.at(i));
+			strResult.append(tempbuff);
+		}
+		else if (isspace((BYTE)tt.at(i)))
+		{
+			strResult.append("+");
+		}
+		else
+		{
+			char tempbuff[4];
+			sprintf_s(tempbuff, "%%%X%X", ((BYTE)tt.at(i)) >> 4, ((BYTE)tt.at(i)) % 16);
+			strResult.append(tempbuff);
+		}
+	}
+}
+
+string CharEncoding::EnCode_UNICODEURL(IN const CHAR* pText)
+{
+	return "";
+}
+
+/************************************************************************/
+/*  函数:[7/26/2016 IT];
+/*  描述:;
+/*  参数:;
+/*  	[IN] :;
+/*  	[OUT] :;
+/*  	[IN/OUT] :;
+/*  返回:void;
+/*  注意:;
+/*  示例:;
+/*
+/*  修改:;
+/*  日期:;
+/*  内容:;
+/************************************************************************/
+string CharEncoding::DeCode_URLGB2312(IN const CHAR* pURLText)
+{
+	string output = "";
+	char tmp[2];
+	int i = 0, idx = 0, len = strlen(pURLText);
+
+	while (i < len){
+		if (pURLText[i] == '%')
+		{
+			tmp[0] = pURLText[i + 1];
+			tmp[1] = pURLText[i + 2];
+			output += StrToBin(tmp);
+			i = i + 3;
+		}
+		else if (pURLText[i] == '+')
+		{
+			output += ' ';
+			i++;
+		}
+		else{
+			output += pURLText[i];
+			i++;
+		}
+	}
+
+	return output;
+}
+
+void CharEncoding::DeCode_URLGB2312(IN const CHAR* pURLText, OUT string& strResult)
+{
+	char tmp[2];
+	int i = 0, idx = 0, len = strlen(pURLText);
+
+	while (i < len){
+		if (pURLText[i] == '%')
+		{
+			tmp[0] = pURLText[i + 1];
+			tmp[1] = pURLText[i + 2];
+			strResult += StrToBin(tmp);
+			i = i + 3;
+		}
+		else if (pURLText[i] == '+')
+		{
+			strResult += ' ';
+			i++;
+		}
+		else{
+			strResult += pURLText[i];
+			i++;
+		}
+	}
+}
+
+/************************************************************************/
+/*  函数:[7/26/2016 IT];
+/*  描述:;
+/*  参数:;
+/*  	[IN] :;
+/*  	[OUT] :;
+/*  	[IN/OUT] :;
+/*  返回:void;
+/*  注意:;
+/*  示例:;
+/*
+/*  修改:;
+/*  日期:;
+/*  内容:;
+/************************************************************************/
+string CharEncoding::DeCode_URLUTF8(IN const CHAR* pURLText)
+{
+	string output = "";
+	string temp = DeCode_URLGB2312(pURLText);
+	UTF82ASCII(temp.c_str(), output);
+	return output;
+}
+
+void CharEncoding::DeCode_URLUTF8(IN const CHAR* pURLText, OUT string& strResult)
+{
+	string temp = DeCode_URLGB2312(pURLText);
+	UTF82ASCII(temp.c_str(), strResult);
+}
+
+/************************************************************************/
+/*  函数:[7/26/2016 IT];
+/*  描述:;
+/*  参数:;
+/*  	[IN] :;
+/*  	[OUT] :;
+/*  	[IN/OUT] :;
+/*  返回:void;
+/*  注意:;
+/*  示例:;
+/*
+/*  修改:;
+/*  日期:;
+/*  内容:;
+/************************************************************************/
+string CharEncoding::DeCode_URLUNICODE(IN const CHAR* pURLText)
+{
+	string str = pURLText;
+	string strResult = "";
+
+	INT nIndex = 0;
+	string strTemp = "";
+
+	while ( str.find_first_of("\\u") != string::npos )
+	{
+		nIndex = str.find_first_of("\\u");
+		strResult.append(str.substr(0, nIndex));
+		strTemp = str.substr(nIndex + 2, 4);
+		str = str.substr(nIndex + 2 +4);
+		CHAR szReturn[10] = {0};
+
+		union  __UNION_VAR_INT{
+			BYTE   ch[2];   
+			int	   value;   
+		}unionVarInt;
+
+		unionVarInt.ch[0] =  (CharToInt(strTemp.at(2)) << 4) | (CharToInt(strTemp.at(3))  & 0x00FF);
+		unionVarInt.ch[1] =  (CharToInt(strTemp.at(0)) << 4) | (CharToInt(strTemp.at(1))  & 0x00FF);
+
+		WCHAR szWide[2] = {0};
+		szWide[0] = unionVarInt.value;
+		UNICODE2ASCII(szWide,szReturn,10);
+		strResult.append(szReturn);
+	}
+	strResult.append(str);
+
+	return strResult;
+}
+
+void CharEncoding::DeCode_URLUNICODE(IN const CHAR* pURLText, OUT string& strResult)
+{
+	string str = pURLText;
+
+	INT nIndex = 0;
+	string strTemp = "";
+
+	while ( str.find_first_of("\\u") != string::npos )
+	{
+		nIndex = str.find_first_of("\\u");
+		strResult.append(str.substr(0, nIndex));
+		strTemp = str.substr(nIndex + 2, 4);
+		str = str.substr(nIndex + 2 +4);
+		CHAR szReturn[10] = {0};
+
+		union  __UNION_VAR_INT{
+			BYTE   ch[2];   
+			int	   value;   
+		}unionVarInt;
+
+		unionVarInt.ch[0] =  (CharToInt(strTemp.at(2)) << 4) | (CharToInt(strTemp.at(3))  & 0x00FF);
+		unionVarInt.ch[1] =  (CharToInt(strTemp.at(0)) << 4) | (CharToInt(strTemp.at(1))  & 0x00FF);
+
+		WCHAR szWide[2] = {0};
+		szWide[0] = unionVarInt.value;
+		UNICODE2ASCII(szWide,szReturn,10);
+		strResult.append(szReturn);
+	}
+	strResult.append(str);
+}

+ 97 - 0
SATService/SATService/CharEncoding.h

@@ -0,0 +1,97 @@
+/************************************************************************/
+/*  Copyright (C), 2016-2020, [IT], 保留所有权利;
+/*  模 块 名:公共模块,未做性能优化;
+/*  描    述:;
+/*
+/*  版    本:[V];	
+/*  作    者:[IT];
+/*  日    期:[7/26/2016];
+/*
+/*
+/*  注    意:;
+/*
+/*  修改记录:[IT];
+/*  修改日期:;
+/*  修改版本:;
+/*  修改内容:;
+/************************************************************************/
+#ifndef __CHAR_ENCODING__
+#define __CHAR_ENCODING__
+
+#include <string>
+#include <vector>
+using namespace std;
+
+#ifndef _UNICODE
+typedef string TString;
+#else
+typedef wstring TString;
+#endif
+
+#pragma once
+
+
+class  CharEncoding
+{
+public:
+	// 将字符转化为对应的ASCII十进制值;
+	static char CharToInt(char ch);
+	// 将两个字符串转化成十六进制值;
+	static char StrToBin(IN char (&str)[2]);
+	static void GB2312ToUTF_8(string& pOut, const char *pText, int pLen);
+	// 将ASCII字符串转成UNICODE字符串;
+	static WCHAR* ASCII2UNICODE(IN LPCCH lpASCIIStr);
+	static BOOL   ASCII2UNICODE(IN LPCCH lpASCIIStr, OUT PWCH pUNICODEStr, IN CONST INT& nUNICODEStrLen);
+	static BOOL   ASCII2UNICODE(IN LPCCH lpASCIIStr, OUT wstring &strResult);
+
+	// 将UNICODE字符串转成ASCII字符串;
+	static CHAR* UNICODE2ASCII(IN LPWCH lpUNICODEStr);
+	static BOOL  UNICODE2ASCII(IN LPWCH lpUNICODEStr, OUT LPCH pASCIIStr, IN CONST INT& nASCIIStrLen);
+	static BOOL  UNICODE2ASCII(IN LPWCH lpUNICODEStr, OUT string &strResult);
+
+	// 将UNICODE字符串转成UFT8字符串;
+	static CHAR* UNICODE2UTF8(IN LPWCH lpUNICODEStr);
+	static BOOL  UNICODE2UTF8(IN LPWCH lpUNICODEStr, OUT LPCH pUTF8Str, IN CONST INT& nUTF8StrLen);
+	static BOOL  UNICODE2UTF8(IN LPWCH lpUNICODEStr, OUT string &strResult);
+
+	// 将ASCII字符串转成UTF8字符串;
+	static CHAR* ASCII2UTF8(IN LPCCH lpASCIIStr);
+	static BOOL  ASCII2UTF8(IN LPCCH lpASCIIStr, OUT LPCH pUTF8Str, IN CONST INT& nUTF8StrLen);
+	static BOOL  ASCII2UTF8(IN LPCCH lpASCIIStr, OUT string &strResult);
+
+	// 将UTF-8字符串转成UNICODE字符串;
+	static WCHAR* UTF82UNICODE(IN LPCCH lpUTF8);
+	static BOOL   UTF82UNICODE(IN LPCCH lpUTF8, OUT PWCH pUNICODEStr, IN CONST INT& nUNICODEStrLen);
+	static BOOL   UTF82UNICODE(IN LPCCH lpUTF8, OUT wstring &strResult);
+
+	// 将UTF-8字符串转成ASCII字符串;
+	static CHAR*  UTF82ASCII(IN LPCCH lpUTF8);
+	static BOOL   UTF82ASCII(IN LPCCH lpUTF8, OUT LPCH pASCIIStr, IN CONST INT& nASCIIStrLen);
+	static BOOL   UTF82ASCII(IN LPCCH lpUTF8, OUT string &strResult);
+
+	// 将UTF-8编码成GB2312;
+	static string UTF8IntoGB2313(IN CHAR* pUTF8Text, IN const INT& nUTF8TextLen);
+	// 将GB2312编码成UTF-8;
+	static string GB2312IntoUTF8(IN CHAR* pGB2312Text, IN const INT& nGB2312TextLen);
+
+	// 将字符串编码成为GB2312编码格式的URL;
+	static string EnCode_GB2312URL(IN const CHAR* pText);
+	static void EnCode_GB2312URL(IN CHAR* pText, OUT string& strResult);
+	// 将字符串编码成为UTF-8编码格式的URL;
+	static string EnCode_UTF8URL(IN const CHAR* pText);
+	static void EnCode_UTF8URL(IN const CHAR* pText, OUT string& strResult);
+	// 将字符串编码成为UNICODE编码格式的URL;
+	static string EnCode_UNICODEURL(IN const CHAR* pText);	// 未完成该函数;
+
+	// 解码UTF-8编码格式的URL;
+	static string DeCode_URLUTF8(IN const CHAR* pURLText);
+	static void DeCode_URLUTF8(IN const CHAR* pURLText, OUT string& strResult);
+	// 解码GB2312编码格式的URL;
+	static string DeCode_URLGB2312(IN const CHAR* pURLText);
+	static void DeCode_URLGB2312(IN const CHAR* pURLText, OUT string& strResult);
+	// 解码UNICODE编码格式的URL;
+	static string DeCode_URLUNICODE(IN const CHAR* pURLText);
+	static void DeCode_URLUNICODE(IN const CHAR* pURLText, OUT string& strResult);
+};
+
+#endif

+ 534 - 62
SATService/SATService/SATExecutor.cpp

@@ -1,6 +1,7 @@
 #include "StdAfx.h"
 #include "SATExecutor.h"
 #include "ScriptExecutor.h"
+#include "CharEncoding.h"
 
 CSATExecutor::CSATExecutor(void)
 {
@@ -87,7 +88,7 @@ SATParameters::STCase* CSATExecutor::GetFreeCaseScript(std::vector<SATParameters
 	return NULL;
 }
 
-void CSATExecutor::ExecuteFreeCaseScript(SATParameters::STTask* pTask)
+SATParameters::STCase* CSATExecutor::ExecuteFreeCaseScript(SATParameters::STTask* pTask)
 {
 	SATParameters::STCase* pCase = GetFreeCaseScript(pTask->Job.vtCases);
 	if (pCase)
@@ -98,7 +99,9 @@ void CSATExecutor::ExecuteFreeCaseScript(SATParameters::STTask* pTask)
 			if ( pExcutor )
 			{
 				pCase->_pExcutor = pExcutor;
-				if ( pExcutor->InitScript(pCase->_strScriptPath, pCase->_strFileDir + "\\" + pCase->_strFileName + ".txt", "", SUBPROCESS) )
+				// 用例的日志文件路径;
+				pCase->_strCaseLog = pCase->_strFileDir + "\\" + pCase->_strFileName + ".txt";
+				if ( pExcutor->InitScript(pCase->_strScriptPath, pCase->_strCaseLog, "", SUBPROCESS) )
 				{
 					pExcutor->StartScript();
 					// 标记用例执行中;
@@ -107,6 +110,7 @@ void CSATExecutor::ExecuteFreeCaseScript(SATParameters::STTask* pTask)
 					pTask->_nExecutionState = 1;
 					// 记录开始时间;
 					pCase->_ulStartTickCount = GetTickCount64();
+					pCase->_strStartTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
 				}
 			}	
 		}
@@ -115,12 +119,15 @@ void CSATExecutor::ExecuteFreeCaseScript(SATParameters::STTask* pTask)
 			CScriptExecutor *pExcutor = (CScriptExecutor *)pCase->_pExcutor;
 		}
 	}
+
+	return pCase;
 }
 
 bool CSATExecutor::Login()
 {
 #ifdef _DEBUG
-	std::string url = "http://10.126.16.60:8580/btc_execute_se/ajaxInteractiveManage!executeLogin.action";
+	std::string url = Global::g_stSATConfig.szExecuteServer;
+	url.append("/ajaxInteractiveManage!executeLogin.action");
 	// 示例值;
 	m_stLoginReq.strUserName = "superAdmin";
 	m_stLoginReq.strStatus = "0";
@@ -175,8 +182,9 @@ bool CSATExecutor::UpdateDevice()
 
 	SATParameters::STUpdateDeviceReq stUpdateDeviceReq;
 	SATParameters::STUpdateDeviceResp stUpdateDeviceResp;
-	std::string url = "http://10.126.16.60:8580/btc_execute_se/ajaxInteractiveManage!updateDeviceMessage.action";
-
+	std::string url = Global::g_stSATConfig.szExecuteServer;
+	url.append("/ajaxInteractiveManage!updateDeviceMessage.action");
+	
 	stUpdateDeviceReq.strStatus = "0";
 	stUpdateDeviceReq.strUserName = "superAdmin";		
 	stUpdateDeviceReq.strIP = "10.118.158.175";
@@ -201,6 +209,476 @@ bool CSATExecutor::UpdateDevice()
 #endif
 }
 
+bool CSATExecutor::NotifyTaskStart(SATParameters::STTask* pTask)
+{
+	if ( !pTask )
+		return false;
+
+	SATParameters::STNotifyJobStartReq stNotifyJobStartReq;
+	SATParameters::STNotifyJobStartResp stNotifyJobStartResp;
+	std::string url = Global::g_stSATConfig.szExecuteServer;
+	url.append("/ajaxInteractiveManage!setResult.action");
+
+	TCHAR szValue[36] = {0};
+	_itoa_s(pTask->nDeviceId, szValue, 10);
+	stNotifyJobStartReq.strDeviceId = szValue;
+
+	_itoa_s(pTask->nExecuteId, szValue, 10);
+	stNotifyJobStartReq.strExecuteId = szValue;
+
+	// _itoa_s(stTask.nInstanceId, szValue, 10); // 误导:应该使用id而不是nInstanceId
+	_itoa_s(pTask->Id, szValue, 10);
+	stNotifyJobStartReq.strInstanceId = szValue;					
+
+	_itoa_s(pTask->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";
+	stNotifyJobStartReq.strSignalImageUrl.append(pTask->strTaskName+"\\\\");
+	stNotifyJobStartReq.strSignalImageUrl.append(pTask->Job.strUniqueId+"\\\\");
+	stNotifyJobStartReq.strSignalImageUrl.append(pTask->Job.strDeviceId);
+
+	if ( SetResult(url, stNotifyJobStartReq, stNotifyJobStartResp) )
+	{
+		// 此处可能需要设置设备为忙碌状态;
+		// SetDeviceStatus(BUSY);
+		return true;
+	}
+
+#ifdef _DEBUG
+	OutputDebugString("通知SAT失败\n");
+#endif
+
+	return false;
+}
+
+bool CSATExecutor::UploadCaseImg(SATParameters::STTask* pTask, SATParameters::STCase *pCase, std::string img)
+{
+	TCHAR szValue[MAX_PATH] = {0};
+	std::string url = Global::g_stSATConfig.szExecuteServer;
+	url.append("/ajaxInteractiveManage!saveResultImg.action");
+
+	SATParameters::STSaveImgReq stSaveImgReq;
+	SATParameters::STSaveImgResp stSaveImgResp;
+
+	stSaveImgReq.strCaseId = pCase->strId;
+	stSaveImgReq.strCaseRepeat = "0";
+	stSaveImgReq.strCaseStep = pCase->strIndex;
+	// 实例Id;
+	_itoa_s(pTask->nDeviceId, szValue, 10);
+	stSaveImgReq.strDeviceId = szValue;//pTask->Job.strDeviceId;
+	// 就是Task中的ExecuteId
+	_itoa_s(pTask->nExecuteId, szValue, 10);
+	stSaveImgReq.strExecuteId = szValue;
+	// 实例Id;
+	_itoa_s(pTask->nInstanceId, szValue, 10);
+	stSaveImgReq.strInstanceId = szValue;
+	stSaveImgReq.strJobRepeat = "0";
+	// 注意避坑:roundnum必须赋值0或1;
+	stSaveImgReq.strRoundNum = "0";
+	stSaveImgReq.strTaskType = pTask->strTaskType;
+	stSaveImgReq.strUploads = img;
+
+	// 上传用例图片;
+	if ( SaveResultImg(url, stSaveImgReq, stSaveImgResp) )
+	{
+		return true;
+	}
+
+	return false;
+}
+
+bool CSATExecutor::UploadCaseLog(SATParameters::STTask* pTask, SATParameters::STCase *pCase)
+{
+	TCHAR szValue[MAX_PATH] = {0};
+	std::string url = Global::g_stSATConfig.szExecuteServer;
+	url.append("/ajaxInteractiveManage!saveCaseOrTaskLog.action");
+
+	SATParameters::STSaveLogReq stSaveLogReq;
+	SATParameters::STSaveLogResp stSaveLogResp;
+
+	stSaveLogReq.strCaseId = pCase->strId;
+	// 执行ID;
+	_itoa_s(pTask->nExecuteId, szValue, 10);
+	stSaveLogReq.strExecuteId = szValue;
+	stSaveLogReq.strFileType = "caseLogFile";
+	// 任务Id;
+	_itoa_s(pTask->nTaskId, szValue, 10);
+	stSaveLogReq.strTaskId = szValue;
+	stSaveLogReq.strUserId = pTask->Job.strUserId;
+	// 要上传的日志文件;
+	stSaveLogReq.strUploads = pCase->_strCaseLog;
+	if ( SaveCaseOrTaskLog(url, stSaveLogReq, stSaveLogResp) )
+	{
+		return true;
+	}
+
+	return false;
+}
+
+bool CSATExecutor::ReportCaseItemFinish(SATParameters::STTask* pTask, SATParameters::STCase *pCase, STCaseItem &caseItem)
+{
+	TCHAR szValue[MAX_PATH] = {0};
+	std::string url = Global::g_stSATConfig.szExecuteServer;
+	url.append("/ajaxInteractiveManage!setResultList.action");
+
+	SATParameters::STJobProcessReq stJobProcessReq;
+	SATParameters::STJobProcessResp stJobProcessResp;
+
+	stJobProcessReq.strResultState = caseItem.result ? "1" : "0";
+	stJobProcessReq.strCaseScene = "";
+	// 索引;
+	stJobProcessReq.strCaseStep = pCase->strIndex;
+	stJobProcessReq.strApkMD5 = "";
+	stJobProcessReq.strCrashTime = "";
+	// 就是Task中的ExecuteId
+	_itoa_s(pTask->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(pTask->nInstanceId, szValue, 10);
+	stJobProcessReq.strInstanceId = szValue;
+	stJobProcessReq.strCaseId = pCase->strId;
+	// 进度;
+	_itoa_s(100*(atoi(pCase->strIndex.c_str()))/pTask->Job.vtCases.size(), szValue, 10);
+	stJobProcessReq.strProgress = szValue;
+	// 需要将utf-8转gbk;
+	stJobProcessReq.strReusltMessage = CharEncoding::UTF82ASCII(caseItem.name.c_str());
+	stJobProcessReq.strJobRepeat = "";
+	stJobProcessReq.strScreenShot = "";
+	stJobProcessReq.strStartTime = pCase->_strStartTime;
+	stJobProcessReq.strCrashNumber = "";
+	stJobProcessReq.strCaseName = pCase->strCaseName;
+	stJobProcessReq.strFailedReason = CharEncoding::UTF82ASCII(caseItem.remark.c_str());
+	for (std::vector<std::string>::iterator it = caseItem.imgs.begin(); it != caseItem.imgs.end(); it++ )
+	{
+		int npos = it->find_last_of('/');
+		if ( std::string::npos != npos )
+		{
+			stJobProcessReq.strImgName.append(it->substr(npos));
+			stJobProcessReq.strImgName.append("&");
+		}
+	}
+	if ( stJobProcessReq.strImgName.size() && stJobProcessReq.strImgName.at(stJobProcessReq.strImgName.size()-1) == '&')
+		stJobProcessReq.strImgName.erase(stJobProcessReq.strImgName.size()-1);
+	stJobProcessReq.strCaseIndex = pCase->strIndex;
+	// 实例Id;
+	_itoa_s(pTask->nDeviceId, szValue, 10);
+	stJobProcessReq.strDeviceId = szValue;
+	stJobProcessReq.strSceneIndex = "";
+	// 实例Id;
+	_itoa_s(pTask->nTaskId, szValue, 10);
+	stJobProcessReq.strTaskId = szValue;
+	stJobProcessReq.strAnalysis = CharEncoding::UTF82ASCII(caseItem.data.c_str());
+	// 设备名称:即DeviceSerial;
+	stJobProcessReq.strDevnceName = pTask->Job.strDeviceId;	// 命名及其不范围,一会deviceid是deviceserial,一会是id;
+	// 固定为:TOTAL
+	stJobProcessReq.strInfoType = "";
+	// 如果是Android设备,需要通过adb获取;
+	//stJobProcessReq.strMemoryInfo = stDevice.strMemory;
+	stJobProcessReq.strEndTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));//"2019-12-16 10:18:20";
+	stJobProcessReq.strRoundNumber = "1";
+	stJobProcessReq.strResultType = "4";		// reportActionFinish;
+	stJobProcessReq.strOperationStep = "";
+
+	if ( SetResultList(url, stJobProcessReq, stJobProcessResp) )
+	{
+		// 再上传图片;
+		std::string img;
+		for (std::vector<std::string>::iterator it = caseItem.imgs.begin(); it != caseItem.imgs.end(); it++ )
+		{
+			img = "D:/SAT/results/";
+			img.append(it->substr(3));
+			UploadCaseImg(pTask, pCase, img);
+		}
+
+		return true;
+	}
+
+	return false;
+}
+
+bool CSATExecutor::ReportCaseFinish(SATParameters::STTask* pTask, SATParameters::STCase *pCase)
+{
+	TCHAR szValue[MAX_PATH] = {0};
+	std::string url = Global::g_stSATConfig.szExecuteServer;
+	url.append("/ajaxInteractiveManage!setResultList.action");
+
+	SATParameters::STJobProcessReq stJobProcessReq;
+	SATParameters::STJobProcessResp stJobProcessResp;
+
+	// 上报用例结果:0表示脚本成功执行,	1表示脚本出错或超时;
+	if ( pCase->_nExecutionState == 2 )
+		stJobProcessReq.strResultState = "0";	// 脚本未执行完成;
+	else if ( pCase->_nExecutionState == 1 )	
+		stJobProcessReq.strResultState = "1";	// 脚本执行中,认为fail;
+	
+	stJobProcessReq.strCaseScene = "";
+	// 索引;
+	stJobProcessReq.strCaseStep = pCase->strIndex;
+	stJobProcessReq.strApkMD5 = "";
+	stJobProcessReq.strCrashTime = "";
+	// 就是Task中的ExecuteId
+	_itoa_s(pTask->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(pTask->nInstanceId, szValue, 10);
+	stJobProcessReq.strInstanceId = szValue;
+	stJobProcessReq.strCaseId = pCase->strId;
+	// 进度(###需要修改此处###);
+	_itoa_s(100*(atoi(pCase->strIndex.c_str()))/pTask->Job.vtCases.size(), szValue, 10);
+	stJobProcessReq.strProgress = szValue;
+	// 需要将utf-8转gbk;
+	stJobProcessReq.strReusltMessage = "测试用例结果:";
+	stJobProcessReq.strJobRepeat = "";
+	stJobProcessReq.strScreenShot = "";
+	stJobProcessReq.strStartTime = pCase->_strStartTime;
+	stJobProcessReq.strCrashNumber = "";
+	stJobProcessReq.strCaseName = pCase->strCaseName;
+	stJobProcessReq.strFailedReason = "";
+
+	stJobProcessReq.strImgName = "";
+	stJobProcessReq.strCaseIndex = pCase->strIndex;
+	// 实例Id;
+	_itoa_s(pTask->nDeviceId, szValue, 10);
+	stJobProcessReq.strDeviceId = szValue;
+	stJobProcessReq.strSceneIndex = "";
+	// 实例Id;
+	_itoa_s(pTask->nTaskId, szValue, 10);
+	stJobProcessReq.strTaskId = szValue;
+	stJobProcessReq.strAnalysis = "";
+	// 设备名称:即DeviceSerial;
+	stJobProcessReq.strDevnceName = pTask->Job.strDeviceId;	// 命名及其不范围,一会deviceid是deviceserial,一会是id;
+	// 固定为:TOTAL
+	stJobProcessReq.strInfoType = "TOTAL";
+	// 如果是Android设备,需要通过adb获取;
+	//stJobProcessReq.strMemoryInfo = stDevice.strMemory;
+	stJobProcessReq.strEndTime = pCase->_strEndTime;//CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));//"2019-12-16 10:18:20";
+	stJobProcessReq.strRoundNumber = "1";
+	stJobProcessReq.strResultType = "5";		// reportCaseFinish;
+	stJobProcessReq.strOperationStep = "";
+
+	if ( SetResultList(url, stJobProcessReq, stJobProcessResp) )
+	{
+		return true;
+	}
+
+	return false;
+}
+
+bool CSATExecutor::ReportCaseResult(SATParameters::STTask* pTask, SATParameters::STCase *pCase)
+{
+	// 获取xml文件内容;
+	std::string xmlpath = "D:\\SAT\\results\\detail\\";
+	xmlpath.append(pCase->_strFileName);
+	xmlpath.append("_result.xml");
+	std::vector<STCaseItem> vtCaseItem;
+	GetCaseXMLResult(xmlpath, vtCaseItem);
+	if ( vtCaseItem.size() == 0 )
+		return false;
+	
+	int nIndex = 1;
+	TCHAR szValue[MAX_PATH] = {0};
+	std::string url = Global::g_stSATConfig.szExecuteServer;
+	url.append("/ajaxInteractiveManage!setResultList.action");
+	SATParameters::STJobProcessReq stJobProcessReq;
+	SATParameters::STJobProcessResp stJobProcessResp;
+	// 遍历所有用例测试项;
+	std::vector<STCaseItem>::iterator it = vtCaseItem.begin();
+	for (; it != vtCaseItem.end(); it++ )
+	{
+		// 上报测试项结果(包含相片);
+		ReportCaseItemFinish(pTask, pCase, *it);		
+	}
+
+	// 上报用例完成;
+	ReportCaseFinish(pTask, pCase);
+
+	// 上传用例日志;
+	UploadCaseLog(pTask, pCase);
+
+	return true;
+}
+
+bool CSATExecutor::UploadTaskLog(SATParameters::STTask* pTask)
+{
+	TCHAR szValue[MAX_PATH] = {0};
+	std::string url = Global::g_stSATConfig.szExecuteServer;
+	url.append("/ajaxInteractiveManage!saveCaseOrTaskLog.action");
+
+	SATParameters::STSaveLogReq stSaveLogReq;
+	SATParameters::STSaveLogResp stSaveLogResp;
+
+	stSaveLogReq.strCaseId = "";
+	// 执行ID;
+	_itoa_s(pTask->nExecuteId, szValue, 10);
+	stSaveLogReq.strExecuteId = szValue;
+	stSaveLogReq.strFileType = "taskLogFile";
+	// 任务Id;
+	_itoa_s(pTask->nTaskId, szValue, 10);
+	stSaveLogReq.strTaskId = szValue;
+	stSaveLogReq.strUserId = pTask->Job.strUserId;
+	// 要上传的日志文件;
+	stSaveLogReq.strUploads = pTask->_strTaskLog;
+	if ( SaveCaseOrTaskLog(url, stSaveLogReq, stSaveLogResp) )
+	{
+		return true;
+	}
+
+	return false;
+}
+
+bool CSATExecutor::ReportTaskFinish(SATParameters::STTask* pTask)
+{
+	TCHAR szValue[MAX_PATH] = {0};
+	std::string url = Global::g_stSATConfig.szExecuteServer;
+	url.append("/ajaxInteractiveManage!setResultList.action");
+
+	SATParameters::STJobProcessReq stJobProcessReq;
+	SATParameters::STJobProcessResp stJobProcessResp;
+
+	// 需要处理###
+	stJobProcessReq.strResultState = "0";	// 脚本执行中,认为fail;
+
+	stJobProcessReq.strCaseScene = "";
+	// 索引;
+	stJobProcessReq.strCaseStep = "0";
+	stJobProcessReq.strApkMD5 = "";
+	stJobProcessReq.strCrashTime = "";
+	// 就是Task中的ExecuteId
+	_itoa_s(pTask->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(pTask->nInstanceId, szValue, 10);
+	stJobProcessReq.strInstanceId = szValue;
+	stJobProcessReq.strCaseId = "";
+	// 进度(###需要修改此处###);
+	stJobProcessReq.strProgress = "100";
+	// 需要将utf-8转gbk;
+	stJobProcessReq.strReusltMessage = "任务结束";
+	stJobProcessReq.strJobRepeat = "";
+	stJobProcessReq.strScreenShot = "";
+	stJobProcessReq.strStartTime = pTask->strStartTime;
+	stJobProcessReq.strCrashNumber = "";
+	stJobProcessReq.strCaseName = "";
+	stJobProcessReq.strFailedReason = "";
+
+	stJobProcessReq.strImgName = "";
+	stJobProcessReq.strCaseIndex = "";
+	// 实例Id;
+	_itoa_s(pTask->nDeviceId, szValue, 10);
+	stJobProcessReq.strDeviceId = szValue;
+	stJobProcessReq.strSceneIndex = "";
+	// 实例Id;
+	_itoa_s(pTask->nTaskId, szValue, 10);
+	stJobProcessReq.strTaskId = szValue;
+	stJobProcessReq.strAnalysis = "";
+	// 设备名称:即DeviceSerial;
+	stJobProcessReq.strDevnceName = pTask->Job.strDeviceId;	// 命名及其不范围,一会deviceid是deviceserial,一会是id;
+	// 固定为:TOTAL
+	stJobProcessReq.strInfoType = "";
+	// 如果是Android设备,需要通过adb获取;
+	//stJobProcessReq.strMemoryInfo = stDevice.strMemory;
+	stJobProcessReq.strEndTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));//"2019-12-16 10:18:20";
+	stJobProcessReq.strRoundNumber = "1";
+	stJobProcessReq.strResultType = "1";		// reportJobFinish;
+	stJobProcessReq.strOperationStep = "";
+
+	if ( SetResultList(url, stJobProcessReq, stJobProcessResp) )
+	{
+		return true;
+	}
+
+	return false;
+}
+
+bool CSATExecutor::GetCaseXMLResult(std::string xmlpath, std::vector<STCaseItem> &vtCaseItem)
+{
+	// 解析xml;
+	tinyxml2::XMLDocument doc;
+	if (tinyxml2::XML_SUCCESS != doc.LoadFile(xmlpath.c_str()) )
+	{
+		return false;
+	}
+
+	tinyxml2::XMLElement *pXmlRoot = NULL;
+	if ((pXmlRoot = doc.RootElement()) == NULL)
+		return false;
+	
+	if (_tcsicmp(pXmlRoot->Value(), "results") != 0)
+		return false;
+	
+	tinyxml2::XMLElement *pXmlElent = pXmlRoot->FirstChildElement();
+	while (pXmlElent)
+	{
+		if (_tcsicmp(pXmlElent->Value(), _T("item")) == 0)
+		{
+			STCaseItem cItem;
+			tinyxml2::XMLElement *pItem = pXmlElent->FirstChildElement();
+			while (pItem)
+			{
+				if (_tcsicmp(pItem->Value(), _T("name")) == 0)
+				{
+					cItem.name = pItem->GetText();
+				}
+				else if (_tcsicmp(pItem->Value(), _T("result")) == 0)
+				{
+					cItem.result = pItem->BoolText();
+				}
+				else if (_tcsicmp(pItem->Value(), _T("data")) == 0)
+				{
+					cItem.data = pItem->GetText();
+				}
+				else if (_tcsicmp(pItem->Value(), _T("log")) == 0)
+				{
+					cItem.log = pItem->GetText();
+				}
+				else if (_tcsicmp(pItem->Value(), _T("remark")) == 0)
+				{
+					cItem.remark = pItem->GetText();
+				}
+				else if (_tcsicmp(pItem->Value(), _T("screen")) == 0)
+				{
+					cItem.imgs.push_back(pItem->GetText());
+				}
+
+				pItem = pItem->NextSiblingElement();
+			}
+
+			// 压入容器;
+			if ( cItem.name.size() )
+				vtCaseItem.push_back(cItem);
+		}
+
+		pXmlElent = pXmlElent->NextSiblingElement();
+	}
+	
+	return true;
+}
+
 void CSATExecutor::StartWork()
 {
 	m_hEventHearbeat = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -256,14 +734,11 @@ void CSATExecutor::EndofWork()
 DWORD CSATExecutor::HearbeatThread(LPVOID lpVoid)
 {
 	CSATExecutor *that = (CSATExecutor*)lpVoid;
-	if ( !that )
-		return 0;
+	if ( !that ) return 0;
 	
-	do 
-	{
+	do {
 		// 没有登录成功,不查询;
-		if ( !that->m_bLogin )
-			continue;
+		if ( !that->m_bLogin ) continue;
 		
 		SATParameters::STHeartbeatReq stHeartbeatReq;
 		SATParameters::STHeartbeatResp stHeartbeatResp;
@@ -273,24 +748,19 @@ DWORD CSATExecutor::HearbeatThread(LPVOID lpVoid)
 		stHeartbeatReq.strUserName = that->m_stLoginReq.strUserName;
 		stHeartbeatReq.strRunnerMac = that->m_stLoginReq.strMAC;
 		stHeartbeatReq.devicelist.assign(that->m_vtDevice.begin(), that->m_vtDevice.end());
-		if ( Heartbeat(url, stHeartbeatReq, stHeartbeatResp) )
-		{
+		if ( Heartbeat(url, stHeartbeatReq, stHeartbeatResp) ) {
 			std::vector<SATParameters::STTask>::iterator it = stHeartbeatResp.vtTask.begin();
-			for ( ; it != stHeartbeatResp.vtTask.end(); it++ )
-			{
-				if (!that->IsTaskExist(*it))
-				{
+			for ( ; it != stHeartbeatResp.vtTask.end(); it++ ) {
+				if (!that->IsTaskExist(*it)) {
 					// 将任务压入队列中;
 					AutoThreadSection ats(&that->m_csTask);
 					// 同时下载任务;
 					std::string host = Global::g_stSATConfig.szCaseServer;
 					std::string url = host + "/ajaxInteractiveManage!getCaseFileListUrl.action";
 					std::vector<SATParameters::STCase>::iterator _case = it->Job.vtCases.begin();
-					for ( ;_case != it->Job.vtCases.end(); _case++)
-					{
+					for ( ;_case != it->Job.vtCases.end(); _case++) {
 						SATParameters::STScriptUrlResp stScriptUrlResp;
-						if ( DownloadScript(url, _case->strId, Global::g_stSATConfig.szScriptDir, stScriptUrlResp) )
-						{
+						if ( DownloadScript(url, _case->strId, Global::g_stSATConfig.szScriptDir, stScriptUrlResp) ) {
 							_case->_strFileDir = stScriptUrlResp._strFileDir;
 							_case->_strFileName = stScriptUrlResp._strFileName;
 							_case->_strScriptPath = stScriptUrlResp._strScripFile;
@@ -298,7 +768,12 @@ DWORD CSATExecutor::HearbeatThread(LPVOID lpVoid)
 					}
 
 					that->m_vtTask.push_back(*it);
+
+					// 通知SAT服务器,脚本开始执行;
 					// 待开发:同时将任务存储到数据库中;
+					/*
+						db process
+					*/
 				}
 			}
 		}
@@ -311,66 +786,61 @@ DWORD CSATExecutor::HearbeatThread(LPVOID lpVoid)
 DWORD CSATExecutor::ExecuteScriptThread(LPVOID lpVoid)
 {
 	CSATExecutor *that = (CSATExecutor*)lpVoid;
-	if ( !that )
-		return 0;
+	if ( !that ) return 0;
 
-	do 
-	{
+	do {
 		SATParameters::STTask *pTask = that->IsTaskProcess();
-		if ( pTask )
-		{// 有任务在执行中;
-			if ( pTask->_bConcurrent )
-			{// 并发;
+		if ( pTask ) {// 有任务在执行中;
+			if ( pTask->_bConcurrent ) {// 并发;
 
 			}
-			else
-			{// 串行,查询执行中的任务是否超时;
+			else {// 串行;
+				// 查询执行中的任务是否完成或超时;
 				SATParameters::STCase* pCase = that->IsCaseScriptProcess(pTask->Job.vtCases);
-				if ( pCase )
-				{
+				if ( pCase ) {
 					CScriptExecutor *pExcutor = (CScriptExecutor*)pCase->_pExcutor;
-					if ( pExcutor )
-					{
-						if ( pExcutor->IsScriptOver() )
-						{
+					if ( pExcutor ) {
+						if ( pExcutor->IsScriptOver() ) {
 							pCase->_nExecutionState = 2;
+							// 上报服务器,完成脚本用例,并上传用例结果;
+							that->ReportCaseResult(pTask, pCase);
 						}
-						else
-						{
+						else {
 							// 判断是否超时;
-							if ( GetTickCount64() - pCase->_ulStartTickCount > 1800000 )
-							{
+							ULONGLONG ulCurTickCount = GetTickCount64();
+							if ( ulCurTickCount - pExcutor->GetActiveTickCount() > 1800000) {	
 								// 超时中断;
 								pCase->_nExecutionState = 3;
+								// 上报用例结果;
+								that->ReportCaseResult(pTask, pCase);
 							}
 						}
 					}
 				}
-				else
-				{
+				else {
 					// 没有在执行的用例,开始执行新的用例;
-					that->ExecuteFreeCaseScript(pTask);
+					pCase = that->ExecuteFreeCaseScript(pTask);
+					if ( NULL == pCase ) {
+						// 没有空闲的用例可执行,说明所有用例已执行完成;
+						pTask->_nExecutionState = 2;
+						// 上报任务结果;
+						that->UploadTaskLog(pTask);
+					}
 				}
 			}
 		}
-		else
-		{
-			// 获取未执行的任务;
+		else {
+			// 获取空闲的任务;
 			pTask = that->GetFreeTask();
-			if ( pTask)
-			{
+			if ( pTask ) {
 				// 是否支持并发;
-				if ( pTask->_bConcurrent )
-				{
+				if ( pTask->_bConcurrent ) {
 					// 暂时全部一起并发;
 					std::vector<SATParameters::STCase>::iterator _case = pTask->Job.vtCases.begin();
-					for ( ; _case != pTask->Job.vtCases.end(); _case++)
-					{
-						if (!_case->_pExcutor)
-						{					
+					for ( ; _case != pTask->Job.vtCases.end(); _case++) {
+						if (!_case->_pExcutor) {					
 							CScriptExecutor *pExcutor = new CScriptExecutor();
-							if ( pExcutor )
-							{
+							if ( pExcutor ) {
 								_case->_pExcutor = pExcutor;
 								pExcutor->InitScript(_case->_strScriptPath, _case->_strFileDir + "\\" + _case->_strFileName + ".txt", "", SUBPROCESS);
 								pExcutor->StartScript();
@@ -383,15 +853,17 @@ DWORD CSATExecutor::ExecuteScriptThread(LPVOID lpVoid)
 					// 标记任务为执行中;
 					pTask->_nExecutionState = 1;
 				}
-				else
-				{
+				else {
 					// 是否有用例脚本在执行;
 					SATParameters::STCase* pCase = that->IsCaseScriptProcess(pTask->Job.vtCases);
-					if ( !pCase )
-					{
+					if ( !pCase ) {
+						// 执行空闲用例脚本;
 						that->ExecuteFreeCaseScript(pTask);
 					}				
-				}				
+				}
+
+				// 通知SAT服务器,脚本开始执行;
+				that->NotifyTaskStart(pTask);
 			}		
 		}
 	} while ( WaitForSingleObject(that->m_hEventExcuteScript, 10000) == WAIT_TIMEOUT );

+ 30 - 2
SATService/SATService/SATExecutor.h

@@ -5,6 +5,17 @@
 
 #include "CritSection.h"
 
+// 用例xml;
+typedef struct __ST_CASEITEM__
+{
+	bool result;
+	std::string name;
+	std::string data;
+	std::vector<std::string> imgs;
+	std::string log;
+	std::string remark;
+}STCaseItem, *pSTCaseItem;
+
 class CSATExecutor
 {
 	CSATExecutor(void);
@@ -54,7 +65,7 @@ protected:
 	SATParameters::STCase* GetFreeCaseScript(std::vector<SATParameters::STCase> &vtCases);
 
 	// 执行空闲新用例;
-	void ExecuteFreeCaseScript(SATParameters::STTask* pTask);
+	SATParameters::STCase* ExecuteFreeCaseScript(SATParameters::STTask* pTask);
 public:
 	// 登录;
 	bool Login();
@@ -62,7 +73,24 @@ public:
 	void Logout();
 	// 更新设备信息;
 	bool UpdateDevice();
-
+	// 通知SAT任务开始;
+	bool NotifyTaskStart(SATParameters::STTask* pTask);
+	// 上传用例图片;
+	bool UploadCaseImg(SATParameters::STTask* pTask, SATParameters::STCase *pCase, std::string img);
+	// 上传用例结果;
+	bool UploadCaseLog(SATParameters::STTask* pTask, SATParameters::STCase *pCase);
+	// 上报用例测试项完成;
+	bool ReportCaseItemFinish(SATParameters::STTask* pTask, SATParameters::STCase *pCase, STCaseItem &caseItem);
+	// 上报用例完成;
+	bool ReportCaseFinish(SATParameters::STTask* pTask, SATParameters::STCase *pCase);
+	// 上报用例结果;
+	bool ReportCaseResult(SATParameters::STTask* pTask, SATParameters::STCase *pCase);
+	// 上传任务结果;
+	bool UploadTaskLog(SATParameters::STTask* pTask);
+	// 上报任务完成;
+	bool ReportTaskFinish(SATParameters::STTask* pTask);
+	// 获取用例xml结果;
+	bool GetCaseXMLResult(std::string xmlpath, std::vector<STCaseItem> &vtCaseItem);
 	// 其他接口;
 public:
 	// 工作开始函数;	

+ 2 - 4
SATService/SATService/SATService.cpp

@@ -21,12 +21,10 @@ extern int test();
 // 工作启动回调函数;
 void CALLBACK WorkStart()
 {
-#ifdef _DEBUG
-	Sleep(20000);
-#endif
 	WindowsService::GetDebugPriv();
 
 #ifdef _DEBUG
+	//Sleep(20000);
 	CSATExecutor::GetInstance()->Login();
 	CSATExecutor::GetInstance()->UpdateDevice();
 #endif
@@ -60,7 +58,7 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 	{
 		// TODO: 在此处为应用程序的行为编写代码。
 		Global::GetIniInfo();
-#if 0
+#if 1
 		WorkStart();
 		system("pause");
 		return 0;

+ 16 - 0
SATService/SATService/SATService.vcproj

@@ -180,6 +180,14 @@
 			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
 			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
 			>
+			<File
+				RelativePath=".\Base64.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\CharEncoding.cpp"
+				>
+			</File>
 			<File
 				RelativePath=".\Global.cpp"
 				>
@@ -218,6 +226,14 @@
 			Filter="h;hpp;hxx;hm;inl;inc;xsd"
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
 			>
+			<File
+				RelativePath=".\Base64.h"
+				>
+			</File>
+			<File
+				RelativePath=".\CharEncoding.h"
+				>
+			</File>
 			<File
 				RelativePath=".\CritSection.h"
 				>

+ 8 - 1
SATService/SATService/ScriptExecutor.cpp

@@ -44,6 +44,8 @@ CScriptExecutor::CScriptExecutor(void)
 	m_dwThreadId = 0;
 	m_dwSubprocessId = 0;
 	m_bRuned = FALSE;
+
+	m_ulStartTickCount = 0;
 }
 
 CScriptExecutor::~CScriptExecutor(void)
@@ -67,8 +69,11 @@ DWORD CScriptExecutor::_WorkerThread(LPVOID lpParam)
 	}
 	else if (that->m_nRunType == SUBPROCESS)
 	{
-		//that->RunScriptProcess();
+#ifdef _DEBUG
+		that->RunScriptProcess();
+#else
 		that->ServiceRunScriptProcess();
+#endif
 	}
 
 	CloseHandle(that->m_hWorkThread);
@@ -101,6 +106,7 @@ DWORD CScriptExecutor::_LogExportThread(LPVOID lpParam)
 			if (!bSuccess || dwRead == 0 || !_tcslen(chBuf)) 
 				continue;
 
+			that->m_ulStartTickCount = GetTickCount64();
 			Global::WritePythonLog(that->m_szLogPath, chBuf);
 			memset(chBuf, 0, BUFSIZE);
 		} while (!that->m_bStopLogExport);
@@ -117,6 +123,7 @@ DWORD CScriptExecutor::_LogExportThread(LPVOID lpParam)
 			if (!bSuccess || dwRead == 0 || !_tcslen(chBuf)) 
 				continue;
 
+			that->m_ulStartTickCount = GetTickCount64();
 			Global::WritePythonLog(that->m_szLogPath, chBuf);
 			memset(chBuf, 0, BUFSIZE);
 		} while (!that->m_bStopLogExport);

+ 4 - 0
SATService/SATService/ScriptExecutor.h

@@ -40,6 +40,7 @@ protected:
 	BOOL			m_bStopLogExport;
 	// 执行器执行时间;
 	CTime			m_tStartTime;
+	ULONGLONG		m_ulStartTickCount;
 	// 执行器结束时间;
 	CTime			m_tEndTime;
 	// 子进程ID;
@@ -63,6 +64,7 @@ protected:
 	int RunEmbeddedScript();
 	// 运行脚本进程;
 	int RunScriptProcess();
+	// 在服务进程中创建脚本进程;
 	int ServiceRunScriptProcess();
 	// 开启线程;
 	bool StartWorkThread();
@@ -104,6 +106,8 @@ public:
 		else
 			return m_dwThreadId;
 	}
+	// 获取活动的CPU时间;
+	ULONGLONG GetActiveTickCount() const { return m_ulStartTickCount;}
 };
 
 #endif // __SCRIPT_EXECUTOR__

+ 1 - 0
SATService/SATService/stdafx.h

@@ -35,4 +35,5 @@
 #include "WindowService.h"
 #include "Global.h"
 #include "cJSON.h"
+#include "tinyxml2.h"
 // TODO: 在此处引用程序需要的其他头文件