Files
TestEGk/TegExecutor.cpp
T

183 lines
4.9 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : TegExecutor.cpp Data : 19.01.14 Versione : 1.5a6
// 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/EGnStringUtils.h"
#include "/EgtDev/Include/EGnStringConverter.h"
#include "/EgtDev/Include/EGnFileUtils.h"
#include "/EgtDev/Include/EGnFileCompare.h"
#include "/EgtDev/Include/EgnCmdParser.h"
#include "/EgtDev/Include/EGkDllMain.h"
#include "/EgtDev/Include/EGkGeomDB.h"
#include "/EgtDev/Include/EGkGdbExecutor.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 = sCmd1 ;
if ( ! sCmd2.empty())
sOut += "." + sCmd2 ;
sOut += "( " ;
for ( theConstIter = vsParams.begin() ; theConstIter != vsParams.end() ; ++theConstIter) {
if ( theConstIter != vsParams.begin())
sOut += ", " ;
sOut += *theConstIter ;
}
sOut += ")" ;
LOG_DBG_INFO( m_pLogger, sOut.c_str())
// esecuzione comando
if ( sCmd1 == "RUN") {
ExecuteRun( sCmd2, vsParams) ;
return true ;
}
else if ( sCmd1 == "DIR") {
ExecuteDir( sCmd2, vsParams) ;
return true ;
}
else if ( sCmd1 == "FILE") {
ExecuteFile( 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
SetEGkLogger( m_pLogger) ;
pGdb->Init() ;
pGdbExec->Init( Get( pGdb)) ;
if ( ! pCmdParser->Init( vsParams[0], Get( pGdbExec), m_pLogger, 1)) {
string sOut = "Error on Parser.Init (" + vsParams[0] + ")" ;
LOG_ERROR( m_pLogger, sOut.c_str())
return false ;
}
// esecuzione comandi
return pCmdParser->Run() ;
}
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 ;
// svuoto il direttorio
EmptyDirectory( vsParams[0]) ;
return true ;
}
return false ;
}
//----------------------------------------------------------------------------
bool
TegExecutor::ExecuteFile( const string& sCmd2, const STRVECTOR& vsParams)
{
// cancellazione file
if ( sCmd2 == "DEL") {
// 1 parametro : file
if ( vsParams.size() != 1)
return false ;
// eseguo la cancellazione
EraseFile( vsParams[0]) ;
return true ;
}
// confronto tra file
else if ( sCmd2 == "CMP") {
// 4 parametri : file1, file2, inizio commento, file diff
if ( vsParams.size() != 4)
return false ;
// eseguo il confronto
TextFileCompare( vsParams[0], vsParams[1], vsParams[2], vsParams[3]) ;
return true ;
}
return false ;
}