scbc.sat2 5 gadi atpakaļ
vecāks
revīzija
d97ede7554
2 mainītis faili ar 91 papildinājumiem un 1 dzēšanām
  1. 88 1
      SATHelper/SATHelper/SVNProc.cpp
  2. 3 0
      SATHelper/SATHelper/SVNProc.h

+ 88 - 1
SATHelper/SATHelper/SVNProc.cpp

@@ -1,5 +1,6 @@
 #include "StdAfx.h"
 #include "SVNProc.h"
+#include <afxinet.h>
 
 CSVNProc::CSVNProc(void)
 {
@@ -47,4 +48,90 @@ void CSVNProc::Checkout(std::string strSVNAddress, std::string strSavePath, DWOR
 void CSVNProc::Rollback(std::string strSVNAddress, std::string strSavePath, DWORD dwSVNVersion)
 {
 	SVNProcess(strSVNAddress, strSavePath, dwSVNVersion, SVN_ROLLBACK);
-}
+}
+
+BOOL CSVNProc::CheckNewVersion(std::string url, std::string strContent)
+{
+	// 分解地址;
+	DWORD dwServiceType;
+	CString strServer;
+	CString strObject;
+	INTERNET_PORT nPort;
+	AfxParseURL(url.c_str(), dwServiceType, strServer, strObject, nPort);
+	if ((AFX_INET_SERVICE_HTTP != dwServiceType) && (AFX_INET_SERVICE_HTTPS != dwServiceType)) {
+		return FALSE;
+	}
+
+	// 设置超时
+	CInternetSession session;
+	session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 2000);
+	session.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 3);
+	session.SetOption(INTERNET_OPTION_SEND_TIMEOUT, 10000);
+	session.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, 20000);
+	// http://10.201.40.65:8580/btc_execute_se/ajaxInteractiveManage!getSvnVersion.action
+	
+	// 打开HTTP连接
+	CHttpConnection* pHttpConnection = session.GetHttpConnection(strServer, dwServiceType == AFX_INET_SERVICE_HTTP ? INTERNET_FLAG_KEEP_CONNECTION : INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_SECURE, nPort);
+	if (NULL == pHttpConnection) {
+		return FALSE;
+	}
+	
+	// 开启一个HTTP请求
+	url.append("!" + strContent);
+	CHttpFile* pHttpFile = pHttpConnection->OpenRequest(_T("POST"), url.c_str(), NULL, 1, NULL, NULL, dwServiceType == AFX_INET_SERVICE_HTTP ? INTERNET_FLAG_KEEP_CONNECTION : INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_SECURE);
+	if (NULL == pHttpFile) {
+		return FALSE;
+	}
+	
+	// 设置HTTP请求包头
+	std::string output;
+	pHttpFile->AddRequestHeaders(_T("User-Agent: MYPRODUCT/1.0.0 (Windows)"));
+	pHttpFile->AddRequestHeaders(_T("Content-Type: application/octet-stream"));
+	pHttpFile->AddRequestHeaders(_T("Charset: UTF-8"));
+	
+	// 发送数据
+	BOOL bResult = pHttpFile->SendRequest(NULL, 0, (LPVOID)strContent.data(), (DWORD)strContent.length());
+	if (!bResult) {
+		return FALSE;
+	}
+	
+	// 查询状态
+	DWORD dwHttpCode = 0;
+	bResult = pHttpFile->QueryInfoStatusCode(dwHttpCode);
+	if (!bResult) {
+		return FALSE;
+	}
+	
+	// 出错的原因
+	char szBuffer[4096] = { 0 };
+	DWORD dwBufferSize;
+	if ((dwHttpCode < 200) || (dwHttpCode >= 300)) {
+		BOOL bResult = pHttpFile->QueryInfo(HTTP_QUERY_STATUS_TEXT, szBuffer, &dwBufferSize);
+		return FALSE;
+	}
+	
+	// 接收响应
+	std::string data;
+	DWORD dwReadBytes;	
+	while ((dwReadBytes = pHttpFile->Read((void*)szBuffer, 4096)) > 0) {
+		data.append(szBuffer, dwReadBytes);
+		memset(szBuffer, 0, 4096 * sizeof(char));
+	}
+
+	// 释放资源
+	if (NULL != pHttpFile) {
+		pHttpFile->Close();
+		delete pHttpFile;
+		pHttpFile = NULL;
+	}
+
+	if (NULL != pHttpConnection) {
+		pHttpConnection->Close();
+		delete pHttpConnection;
+		pHttpConnection = NULL;
+	}
+
+	session.Close();
+
+	TRACE1(_T("请求结果:%s"), data.c_str());
+}

+ 3 - 0
SATHelper/SATHelper/SVNProc.h

@@ -25,6 +25,9 @@ public:
 	void Checkout(std::string strSVNAddress, std::string strSavePath, DWORD dwSVNVersion);
 	// 回退指定版本号的svn路径;
 	void Rollback(std::string strSVNAddress, std::string strSavePath, DWORD dwSVNVersion);
+
+	// 检测版本:有新版本返回TRUE;
+	BOOL CheckNewVersion(std::string url = "http://10.201.40.65:8580/btc_execute_se/ajaxInteractiveManage", std::string strContent = "getSvnVersion.action");
 };