Files correlati : ha1.exe Ricompilazione Demo : [ ] Commento : Corretta creazione file di testo per concentratore: ora viene creato un file .tmp che viene rinominato in .txt solo alla fine della scrittura in modo da evitare problemi di sincronizzazione. git-svn-id: svn://10.65.10.50/branches/R_10_00@22437 c028cbd2-c16b-5b4b-a496-9718f37d4682
229 lines
6.1 KiB
C++
Executable File
229 lines
6.1 KiB
C++
Executable File
#include <automask.h>
|
||
#include <config.h>
|
||
#include <execp.h>
|
||
#include <progind.h>
|
||
#include <relation.h>
|
||
#include <utility.h>
|
||
|
||
#include "ha1250.h"
|
||
|
||
bool THardy_transaction::is_server() const
|
||
{
|
||
bool i_am_server = false;
|
||
TConfig config(CONFIG_INSTALL, "Main");
|
||
const int type = config.get_int("Type");
|
||
if (type == 2)
|
||
{
|
||
const TFilename study = config.get("Study");
|
||
i_am_server = xvt_fsys_is_fixed_drive(study) != 0;
|
||
}
|
||
return i_am_server;
|
||
}
|
||
|
||
bool THardy_transaction::is_by_postino() const
|
||
{
|
||
if (argc() < 3)
|
||
return false;
|
||
|
||
const TFixed_string trans(argv(2));
|
||
return (trans.starts_with("/i", true) || trans.starts_with("-i", true));
|
||
}
|
||
|
||
bool THardy_transaction::wait_for_file(const TFilename& filename) const
|
||
{
|
||
TString msg;
|
||
msg << TR("In attesa del file ") << filename;
|
||
const int time_to_wait = 60;
|
||
|
||
TProgind pi(time_to_wait, msg, true, true);
|
||
|
||
long last_size = 0L;
|
||
for (int s = 0; s < 60; s++)
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
|
||
xvt_sys_sleep(3000);
|
||
long size = fsize(filename);
|
||
if (size == last_size && size > 0)
|
||
break;
|
||
last_size = size;
|
||
}
|
||
|
||
if (last_size == 0L && !is_by_postino())
|
||
return cantread_box(filename);
|
||
|
||
return last_size > 0L;
|
||
}
|
||
|
||
/*
|
||
void THardy_transaction::chiudi_concentratore()
|
||
{
|
||
TFilename bat_chiudi = _conc_path;
|
||
bat_chiudi.add("chiudi.bat");
|
||
TExternal_app app_chiudi(bat_chiudi);
|
||
app_chiudi.run();
|
||
//sara' meglio aspettare qualche secondo
|
||
xvt_sys_sleep(3000);
|
||
}
|
||
|
||
void THardy_transaction::carica_concentratore()
|
||
{
|
||
TFilename bat_carica = _conc_path;
|
||
bat_carica.add("car.bat");
|
||
TExternal_app app_carica(bat_carica);
|
||
app_carica.run();
|
||
//sara' meglio aspettare qualche secondo
|
||
xvt_sys_sleep(1000);
|
||
}
|
||
|
||
bool THardy_transaction::scarica_concentratore()
|
||
{
|
||
TFilename bat_scarica = _conc_path;
|
||
bat_scarica.add("descar.bat");
|
||
TExternal_app app_scarica(bat_scarica);
|
||
app_scarica.run();
|
||
//deve assicurarsi che il file upload.d sia completato; usa un test sulle dimensioni
|
||
//aspetta qualche secondo per permettere al concentratore di iniziare a generare il file
|
||
TFilename upload = _input_path;
|
||
upload.add("upload.d");
|
||
//se trova il file upload.d comincia a fare i test
|
||
return wait_for_file(upload);
|
||
}
|
||
|
||
void THardy_transaction::trasmetti_concentratore()
|
||
{
|
||
TFilename bat_trasm = _conc_path;
|
||
bat_trasm.add("trasmissione.bat");
|
||
TExternal_app app_trasm(bat_trasm);
|
||
app_trasm.run();
|
||
}
|
||
*/
|
||
|
||
void THardy_transaction::main_loop()
|
||
{
|
||
TMask* mask = create_mask();
|
||
TLog_report log(title());
|
||
log.kill_duplicates();
|
||
log.log(0, "");
|
||
|
||
//sono il server?
|
||
const bool i_am_server = is_server();
|
||
|
||
//sono lanciato dal postino?
|
||
if (is_by_postino())
|
||
{
|
||
//se sono il server eseguo subito l'elaborazione
|
||
if (i_am_server)
|
||
{
|
||
//legge i files da trasferire
|
||
TFilename trans = argv(2);
|
||
trans.ltrim(2);
|
||
TConfig ini(trans, fake_trans_file());
|
||
FOR_EACH_MASK_FIELD(*mask, i, f)
|
||
{
|
||
const TFieldref* field = f->field();
|
||
if (field != NULL)
|
||
{
|
||
const char* val = field->read(ini, fake_trans_file());
|
||
if (val && *val)
|
||
{
|
||
f->set(val);
|
||
f->on_hit();
|
||
}
|
||
}
|
||
}
|
||
if (ini.get("Mode", "Transaction")[0] == 'A')
|
||
{
|
||
elabora(*mask, log);
|
||
|
||
//sono il server ma via postino; viene salvato il log in formato txt
|
||
trans.ext("txt");
|
||
log.save(trans);
|
||
|
||
delete mask;
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
error_box(TR("Le transazioni possono essere eseguite solo dal server!"));
|
||
}
|
||
else //sono lanciato in modo interattivo
|
||
{
|
||
while (mask->run() == K_ENTER)
|
||
{
|
||
//se <20> il server -> esegue le operazioni di elaborazione, viene fatta la preview diretta del log
|
||
|
||
// if (i_am_server) // Non c'<27> pi<70> distinzione tra server e client
|
||
{
|
||
log.reset();
|
||
elabora(*mask, log);
|
||
log.preview();
|
||
}
|
||
/*
|
||
else //senno' prepara il .ini per l'elaborazione postinica
|
||
{
|
||
TFilename trans = _trans_path;
|
||
trans.add(name());
|
||
trans.ext("ini");
|
||
TConfig ini(trans, "Transaction");
|
||
ini.set("Action", "RUN");
|
||
ini.set("Mode", "AUTO");
|
||
ini.set_paragraph(fake_trans_file());
|
||
FOR_EACH_MASK_FIELD(*mask, i, f)
|
||
{
|
||
const TFieldref* field = f->field();
|
||
if (field != NULL && f->active())
|
||
field->write(ini, fake_trans_file(), f->get());
|
||
}
|
||
message_box(TR("Transazione di scarico inviata al server"));
|
||
//client in interattivo: gli viene spedito il log via file txt e fatta la preview cosi' che l'utente..
|
||
//..lo possa vedere
|
||
trans.ext("txt");
|
||
if (wait_for_file(trans))
|
||
{
|
||
TScanner f(trans);
|
||
log.recordset()->read_from(f);
|
||
log.preview();
|
||
trans.fremove();
|
||
}
|
||
}
|
||
*/
|
||
}
|
||
} //if(by_postino(...
|
||
|
||
delete mask;
|
||
}
|
||
|
||
|
||
bool THardy_transaction::create()
|
||
{
|
||
TConfig config(CONFIG_DITTA, "ha");
|
||
_output_path = config.get("OutputPath");
|
||
_input_path = config.get("InputPath");
|
||
_archive_path = config.get("ArchivePath");
|
||
|
||
if (!_output_path.exist())
|
||
return error_box(FR("Non esiste la cartella di destinazione %s!"), (const char*)_output_path);
|
||
|
||
if (!_input_path.exist())
|
||
return error_box(FR("Non esiste la cartella di upload %s!"), (const char*)_input_path);
|
||
|
||
if (!_archive_path.exist())
|
||
return error_box(FR("Non esiste la cartella di archiviazione dei files processati %s!"), (const char*)_archive_path);
|
||
|
||
/* Controllo inutile
|
||
_conc_path = config.get("ConcentratorePath");
|
||
if (!_conc_path.exist())
|
||
return error_box(FR("Non esiste la cartella del concentratore %s!"), (const char*)_conc_path);
|
||
TFilename conc_prog_path = _conc_path;
|
||
conc_prog_path.add("ProgettoConcentratore.exe");
|
||
if (!conc_prog_path.exist())
|
||
return error_box(FR("Il programma concentratore non si trova nella cartella %s!"), (const char*)_conc_path);
|
||
_trans_path = config.get("TransactionPath");
|
||
if (!_trans_path.exist())
|
||
return error_box(FR("Non esiste la cartella di transazione %s!"), (const char*)_trans_path);
|
||
*/
|
||
|
||
return TSkeleton_application::create();
|
||
} |