Files
TestEGk/TegExecutor.cpp
T
Dario Sassi 0b1abd1792 TestEGk 1.5b3 :
- adattamenti per modifiche a ICmdParser.
2014-02-25 16:42:20 +00:00

186 lines
5.0 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_pOtherExec = nullptr ;
m_pLogger = nullptr ;
}
//----------------------------------------------------------------------------
TegExecutor::~TegExecutor( void)
{
}
//----------------------------------------------------------------------------
void
TegExecutor::SetLogger( ILogger* pLogger)
{
m_pLogger = pLogger ;
}
//----------------------------------------------------------------------------
bool
TegExecutor::SetCmdParser( ICmdParser* pParser)
{
// imposto eventuale parser dipendente
if ( m_pOtherExec != nullptr)
m_pOtherExec->SetCmdParser( pParser) ;
return true ;
}
//----------------------------------------------------------------------------
bool
TegExecutor::AddExecutor( ICmdExecutor* pOtherExec)
{
m_pOtherExec = pOtherExec ;
return true ;
}
//----------------------------------------------------------------------------
bool
TegExecutor::Execute( const string& sCmd1, const string& sCmd2, const STRVECTOR& vsParams)
{
// 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 ;
}
else if ( m_pOtherExec != nullptr)
return m_pOtherExec->Execute( sCmd1, sCmd2, vsParams) ;
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() ;
pGdbExec->SetGeomDB( Get( pGdb)) ;
if ( ! pCmdParser->Init( Get( pGdbExec), 1)) {
LOG_ERROR( m_pLogger, "Error on Parser.Init")
return false ;
}
// esecuzione comandi
return pCmdParser->Run( vsParams[0]) ;
}
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 ;
}