TestEGk 1.4a4 : sistemazioni varie per Logger, batch mode, Ini file, UTF-8.
This commit is contained in:
+161
@@ -0,0 +1,161 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2013-2013
|
||||
//----------------------------------------------------------------------------
|
||||
// File : TegExecutor.cpp Data : 09.12.13 Versione : 1.4a4
|
||||
// Contenuto : Implementazione della classe TegExecutor.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 09.12.13 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "TegExecutor.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
#include "/EgtDev/Include/EGnStringConverter.h"
|
||||
#include "/EgtDev/Include/EgnCmdParser.h"
|
||||
#include "/EgtDev/Include/EGkGeomDB.h"
|
||||
#include "/EgtDev/Include/EGkGdbExecutor.h"
|
||||
#include <io.h>
|
||||
|
||||
using namespace std ;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
TegExecutor::TegExecutor( void)
|
||||
{
|
||||
m_pLogger = nullptr ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
TegExecutor::~TegExecutor( void)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void
|
||||
TegExecutor::Init( ILogger* pLogger)
|
||||
{
|
||||
m_pLogger = pLogger ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
TegExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR& vsParams)
|
||||
{
|
||||
string sOut ;
|
||||
STRVECTOR::const_iterator theConstIter ;
|
||||
|
||||
|
||||
// output di debug
|
||||
sOut = "Cmd = [" + sCmd1 + "/" + sCmd2 + "] Par = [" ;
|
||||
for ( theConstIter = vsParams.begin() ; theConstIter != vsParams.end() ; ++theConstIter) {
|
||||
if ( theConstIter != vsParams.begin())
|
||||
sOut += "/" ;
|
||||
sOut += *theConstIter ;
|
||||
}
|
||||
sOut += "]" ;
|
||||
LOG_DEBUG( m_pLogger, sOut.c_str()) ;
|
||||
|
||||
// esecuzione comando
|
||||
if ( sCmd1 == "RUN") {
|
||||
ExecuteRun( sCmd2, vsParams) ;
|
||||
return true ;
|
||||
}
|
||||
else if ( sCmd1 == "DIR") {
|
||||
ExecuteDir( sCmd2, vsParams) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
TegExecutor::ExecuteRun( const string& sCmd2, const STRVECTOR& vsParams)
|
||||
{
|
||||
// analisi ed esecuzione dei comandi
|
||||
if ( sCmd2 == "") {
|
||||
|
||||
// 1 parametro : nome file di script da eseguire
|
||||
if ( vsParams.size() != 1)
|
||||
return false ;
|
||||
|
||||
// esecuzione script
|
||||
PtrOwner<IGeomDB> pGdb( CreateGeomDB()) ;
|
||||
PtrOwner<IGdbExecutor> pGdbExec( CreateGdbExecutor()) ;
|
||||
PtrOwner<ICmdParser> pCmdParser( CreateCmdParser()) ;
|
||||
|
||||
// controllo validità oggetti
|
||||
if ( ! IsValid( pGdb)) {
|
||||
LOG_ERROR( m_pLogger, "Error in CreateGeomDB") ;
|
||||
return false ;
|
||||
}
|
||||
if ( ! IsValid( pGdbExec)) {
|
||||
LOG_ERROR( m_pLogger, "Error in CreateGdbExecutor") ;
|
||||
return false ;
|
||||
}
|
||||
if ( ! IsValid( pCmdParser)) {
|
||||
LOG_ERROR( m_pLogger, "Error in CreateCmdParser") ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// inizializzazioni
|
||||
pGdb->Init( m_pLogger) ;
|
||||
pGdbExec->Init( Get( pGdb), m_pLogger) ;
|
||||
if ( ! pCmdParser->Init( vsParams[0], Get( pGdbExec), m_pLogger)) {
|
||||
string sOut = "Error on Parser.Init (" + vsParams[0] + ")" ;
|
||||
LOG_ERROR( m_pLogger, sOut.c_str()) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// esecuzione comandi
|
||||
if ( ! pCmdParser->Run()) {
|
||||
LOG_ERROR( m_pLogger, "Error on Parser.Run") ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
TegExecutor::ExecuteDir( const string& sCmd2, const STRVECTOR& vsParams)
|
||||
{
|
||||
// analisi ed esecuzione dei comandi
|
||||
if ( sCmd2 == "EMPTY") {
|
||||
|
||||
// 1 parametro : nome direttorio da svuotare
|
||||
if ( vsParams.size() != 1)
|
||||
return false ;
|
||||
|
||||
wstring sDir = stringtoW( vsParams[0]) ;
|
||||
wstring sFile = sDir + L"\\*.*" ;
|
||||
|
||||
_wfinddata_t c_file ;
|
||||
intptr_t hFile ;
|
||||
|
||||
// ciclo su tutti i file del direttorio
|
||||
if ( ( hFile = _wfindfirst( sFile.c_str(), &c_file)) != -1L) {
|
||||
do {
|
||||
if ( c_file.attrib != _A_SUBDIR) {
|
||||
sFile = sDir + L"\\" + c_file.name ;
|
||||
::DeleteFileW( sFile.c_str()) ;
|
||||
}
|
||||
} while( _wfindnext( hFile, &c_file) == 0) ;
|
||||
_findclose( hFile) ;
|
||||
errno = 0 ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user