2011-06-06 15:50:46 +00:00
|
|
|
|
#include <automask.h>
|
|
|
|
|
#include <config.h>
|
2011-06-07 10:04:39 +00:00
|
|
|
|
#include <execp.h>
|
2011-06-07 15:34:40 +00:00
|
|
|
|
#include <progind.h>
|
2011-06-06 15:50:46 +00:00
|
|
|
|
#include <relation.h>
|
2011-06-07 10:04:39 +00:00
|
|
|
|
#include <utility.h>
|
2011-06-06 15:50:46 +00:00
|
|
|
|
|
|
|
|
|
#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");
|
2011-09-12 11:09:22 +00:00
|
|
|
|
i_am_server = xvt_fsys_is_fixed_drive(study) != 0;
|
2011-06-06 15:50:46 +00:00
|
|
|
|
}
|
|
|
|
|
return i_am_server;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-07 10:04:39 +00:00
|
|
|
|
bool THardy_transaction::is_by_postino() const
|
|
|
|
|
{
|
2011-09-12 11:09:22 +00:00
|
|
|
|
if (argc() < 3)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const TFixed_string trans(argv(2));
|
|
|
|
|
return (trans.starts_with("/i", true) || trans.starts_with("-i", true));
|
2011-06-07 10:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-07 15:34:40 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-07 10:04:39 +00:00
|
|
|
|
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
|
2011-06-07 15:34:40 +00:00
|
|
|
|
return wait_for_file(upload);
|
2011-06-07 10:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void THardy_transaction::trasmetti_concentratore()
|
|
|
|
|
{
|
|
|
|
|
TFilename bat_trasm = _conc_path;
|
|
|
|
|
bat_trasm.add("trasmissione.bat");
|
|
|
|
|
TExternal_app app_trasm(bat_trasm);
|
|
|
|
|
app_trasm.run();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-06 15:50:46 +00:00
|
|
|
|
|
|
|
|
|
void THardy_transaction::main_loop()
|
|
|
|
|
{
|
|
|
|
|
TMask* mask = create_mask();
|
2011-06-07 15:34:40 +00:00
|
|
|
|
TLog_report log(title());
|
|
|
|
|
log.kill_duplicates();
|
|
|
|
|
log.log(0, "");
|
2011-06-06 15:50:46 +00:00
|
|
|
|
|
|
|
|
|
//sono il server?
|
2011-09-12 11:09:22 +00:00
|
|
|
|
const bool i_am_server = is_server();
|
2011-06-06 15:50:46 +00:00
|
|
|
|
|
2011-06-07 10:04:39 +00:00
|
|
|
|
//sono lanciato dal postino?
|
|
|
|
|
if (is_by_postino())
|
2011-06-06 15:50:46 +00:00
|
|
|
|
{
|
|
|
|
|
//se sono il server eseguo subito l'elaborazione
|
|
|
|
|
if (i_am_server)
|
|
|
|
|
{
|
|
|
|
|
//legge i files da trasferire
|
2011-06-07 10:04:39 +00:00
|
|
|
|
TFilename trans = argv(2);
|
2011-06-06 15:50:46 +00:00
|
|
|
|
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')
|
|
|
|
|
{
|
2011-06-07 15:34:40 +00:00
|
|
|
|
elabora(*mask, log);
|
|
|
|
|
|
|
|
|
|
//sono il server ma via postino; viene salvato il log in formato txt
|
|
|
|
|
trans.ext("txt");
|
|
|
|
|
log.save(trans);
|
|
|
|
|
|
2011-06-06 15:50:46 +00:00
|
|
|
|
delete mask;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
error_box(TR("Le transazioni possono essere eseguite solo dal server!"));
|
|
|
|
|
}
|
2011-06-07 10:04:39 +00:00
|
|
|
|
else //sono lanciato in modo interattivo
|
2011-06-06 15:50:46 +00:00
|
|
|
|
{
|
2011-06-07 10:04:39 +00:00
|
|
|
|
while (mask->run() == K_ENTER)
|
2011-06-06 15:50:46 +00:00
|
|
|
|
{
|
2011-06-07 15:34:40 +00:00
|
|
|
|
//se <20> il server -> esegue le operazioni di elaborazione, viene fatta la preview diretta del log
|
2011-06-07 10:04:39 +00:00
|
|
|
|
if (i_am_server)
|
2011-06-07 15:34:40 +00:00
|
|
|
|
{
|
|
|
|
|
log.reset();
|
|
|
|
|
elabora(*mask, log);
|
|
|
|
|
log.preview();
|
|
|
|
|
}
|
2011-06-07 10:04:39 +00:00
|
|
|
|
else //senno' prepara il .ini per l'elaborazione postinica
|
2011-06-06 15:50:46 +00:00
|
|
|
|
{
|
2011-06-07 15:34:40 +00:00
|
|
|
|
TFilename trans = _trans_path;
|
|
|
|
|
trans.add(name());
|
|
|
|
|
trans.ext("ini");
|
|
|
|
|
TConfig ini(trans, "Transaction");
|
2011-06-07 10:04:39 +00:00
|
|
|
|
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"));
|
2011-06-07 15:34:40 +00:00
|
|
|
|
//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();
|
|
|
|
|
}
|
2011-06-06 15:50:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-07 10:04:39 +00:00
|
|
|
|
} //if(by_postino(...
|
|
|
|
|
|
2011-06-06 15:50:46 +00:00
|
|
|
|
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");
|
|
|
|
|
_conc_path = config.get("ConcentratorePath");
|
|
|
|
|
_trans_path = config.get("TransactionPath");
|
|
|
|
|
|
|
|
|
|
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())
|
2011-09-12 11:09:22 +00:00
|
|
|
|
return error_box(FR("Non esiste la cartella di archiviazione dei files processati %s!"), (const char*)_archive_path);
|
2011-06-06 15:50:46 +00:00
|
|
|
|
|
2011-09-12 11:09:22 +00:00
|
|
|
|
/* Controllo inutile
|
2011-06-06 15:50:46 +00:00
|
|
|
|
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())
|
2011-06-07 15:34:40 +00:00
|
|
|
|
return error_box(FR("Il programma concentratore non si trova nella cartella %s!"), (const char*)_conc_path);
|
2011-06-06 15:50:46 +00:00
|
|
|
|
if (!_trans_path.exist())
|
|
|
|
|
return error_box(FR("Non esiste la cartella di transazione %s!"), (const char*)_trans_path);
|
2011-09-12 11:09:22 +00:00
|
|
|
|
*/
|
2011-06-06 15:50:46 +00:00
|
|
|
|
|
|
|
|
|
return TSkeleton_application::create();
|
|
|
|
|
}
|