agent/browser/ie/pagetest/PagetestReporting.cpp
/*-----------------------------------------------------------------------------
	Generate a log file of the event for lab/automated testing
-----------------------------------------------------------------------------*/
Generate a log file of the event for lab/automated testing
Generate a log file of the event for lab / automated testing
void CPagetestReporting::GenerateLabReport(bool fIncludeHeader, CString &szLogFile)
{
	includeObjectData_Now = includeObjectData;
	if( !runningScript || script_logData )
	{
		if( includeHeader )
			fIncludeHeader = true;
		CString szFile = szLogFile + "_IEWPG.txt";
		TCHAR szDir[MAX_PATH];
		lstrcpy(szDir, (LPCTSTR)szFile);
		LPTSTR szFilePos = PathFindFileName(szDir);
		*szFilePos = 0;
		if( lstrlen(szDir) > 3 )
			SHCreateDirectoryEx(NULL, szDir, NULL);
		ATLTRACE(_T("[Pagetest] - ***** CPagetestReporting::FlushResults - Creating Log file '%s'\n"), (LPCTSTR)szFile);
		HANDLE hPageFile = INVALID_HANDLE_VALUE;
		do
		{
			hPageFile = CreateFile(szFile, GENERIC_READ | GENERIC_WRITE, 0, &nullDacl, OPEN_ALWAYS, 0, 0 );
			if( hPageFile == INVALID_HANDLE_VALUE )
				Sleep(10);
		}while( hPageFile == INVALID_HANDLE_VALUE );
		szFile = szLogFile + _T("_IEWTR.txt");
		lstrcpy(szDir, (LPCTSTR)szFile);
		szFilePos = PathFindFileName(szDir);
		*szFilePos = 0;
		if( lstrlen(szDir) > 3 )
			SHCreateDirectoryEx(NULL, szDir, NULL);
		ATLTRACE(_T("[Pagetest] - ***** CPagetestReporting::FlushResults - Creating Log file '%s'\n"), (LPCTSTR)szFile);
		HANDLE hObjectFile = INVALID_HANDLE_VALUE;
		if( includeObjectData || (errorCode != 0 && errorCode != 99999) )
		{
			includeObjectData_Now = 1;
			do
			{
				hObjectFile = CreateFile(szFile, GENERIC_READ | GENERIC_WRITE, 0, &nullDacl, OPEN_ALWAYS, 0, 0 );
				if( hObjectFile == INVALID_HANDLE_VALUE )
					Sleep(10);
			}while( hObjectFile == INVALID_HANDLE_VALUE );
		}
		CString result;
		DWORD written = 0;
		ATLTRACE(_T("[Pagetest] - ***** CPagetestReporting::FlushResults - Writing page data\n"));
		if( hPageFile != INVALID_HANDLE_VALUE )
		{
			bool header = fIncludeHeader;
			if( SetFilePointer( hPageFile, 0, 0, FILE_END ) )
				header = false;
			ReportPageData(result, header);
			if( !result.IsEmpty() )
			{
				CT2A str((LPCTSTR)result, CP_UTF8);
				WriteFile( hPageFile, (LPCSTR)str, lstrlenA(str), &written, 0 );
			}
			CloseHandle( hPageFile );
			ATLTRACE(_T("[Pagetest] - ***** CPagetestReporting::FlushResults - Writing object data\n"));
			if( hObjectFile != INVALID_HANDLE_VALUE )
			{
				header = fIncludeHeader;
				if( SetFilePointer( hObjectFile, 0, 0, FILE_END ) )
					header = false;
				ReportObjectData(result, header);
				if( !result.IsEmpty() )
				{
					CT2A str((LPCTSTR)result, CP_UTF8);
					WriteFile( hObjectFile, (LPCSTR)str, lstrlenA(str), &written, 0 );
				}
				CloseHandle( hObjectFile );
			}
		}
		else
		{
			if( hPageFile != INVALID_HANDLE_VALUE )
				CloseHandle( hPageFile );
			if( hObjectFile != INVALID_HANDLE_VALUE )
				CloseHandle( hObjectFile );
		}
	}
}
void CPagetestReporting :: GenerateLabReport ( bool fIncludeHeader , CString & szLogFile ) { includeObjectData_Now = includeObjectData ; if ( ! runningScript || script_logData ) { if ( includeHeader ) fIncludeHeader = true ; CString szFile = szLogFile + " " ; TCHAR szDir [ MAX_PATH ] ; lstrcpy ( szDir , ( LPCTSTR ) szFile ) ; LPTSTR szFilePos = PathFindFileName ( szDir ) ; * szFilePos = 0 ; if ( lstrlen ( szDir ) > 3 ) SHCreateDirectoryEx ( NULL , szDir , NULL ) ; ATLTRACE ( _T ( " \n " ) , ( LPCTSTR ) szFile ) ; HANDLE hPageFile = INVALID_HANDLE_VALUE ; do { hPageFile = CreateFile ( szFile , GENERIC_READ | GENERIC_WRITE , 0 , & nullDacl , OPEN_ALWAYS , 0 , 0 ) ; if ( hPageFile == INVALID_HANDLE_VALUE ) Sleep ( 10 ) ; } while ( hPageFile == INVALID_HANDLE_VALUE ) ; szFile = szLogFile + _T ( " " ) ; lstrcpy ( szDir , ( LPCTSTR ) szFile ) ; szFilePos = PathFindFileName ( szDir ) ; * szFilePos = 0 ; if ( lstrlen ( szDir ) > 3 ) SHCreateDirectoryEx ( NULL , szDir , NULL ) ; ATLTRACE ( _T ( " \n " ) , ( LPCTSTR ) szFile ) ; HANDLE hObjectFile = INVALID_HANDLE_VALUE ; if ( includeObjectData || ( errorCode != 0 && errorCode != 99999 ) ) { includeObjectData_Now = 1 ; do { hObjectFile = CreateFile ( szFile , GENERIC_READ | GENERIC_WRITE , 0 , & nullDacl , OPEN_ALWAYS , 0 , 0 ) ; if ( hObjectFile == INVALID_HANDLE_VALUE ) Sleep ( 10 ) ; } while ( hObjectFile == INVALID_HANDLE_VALUE ) ; } CString result ; DWORD written = 0 ; ATLTRACE ( _T ( " \n " ) ) ; if ( hPageFile != INVALID_HANDLE_VALUE ) { bool header = fIncludeHeader ; if ( SetFilePointer ( hPageFile , 0 , 0 , FILE_END ) ) header = false ; ReportPageData ( result , header ) ; if ( ! result . IsEmpty ( ) ) { CT2A str ( ( LPCTSTR ) result , CP_UTF8 ) ; WriteFile ( hPageFile , ( LPCSTR ) str , lstrlenA ( str ) , & written , 0 ) ; } CloseHandle ( hPageFile ) ; ATLTRACE ( _T ( " \n " ) ) ; if ( hObjectFile != INVALID_HANDLE_VALUE ) { header = fIncludeHeader ; if ( SetFilePointer ( hObjectFile , 0 , 0 , FILE_END ) ) header = false ; ReportObjectData ( result , header ) ; if ( ! result . IsEmpty ( ) ) { CT2A str ( ( LPCTSTR ) result , CP_UTF8 ) ; WriteFile ( hObjectFile , ( LPCSTR ) str , lstrlenA ( str ) , & written , 0 ) ; } CloseHandle ( hObjectFile ) ; } } else { if ( hPageFile != INVALID_HANDLE_VALUE ) CloseHandle ( hPageFile ) ; if ( hObjectFile != INVALID_HANDLE_VALUE ) CloseHandle ( hObjectFile ) ; } } }
Generate a log file of the event for lab/automated testing
Generate a log file of the event for lab / automated testing
// see if there was a registry override for including the header
 // go into a loop trying to open both files (in case they are in use by someone else)
 // need to hold onto a lock to both to make sure our data lines up
 // make sure the directory exists
 // make sure the directory exists
 // force object data
 // write out the page data
