Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/branches/R_10_00@22223 c028cbd2-c16b-5b4b-a496-9718f37d4682
188 lines
4.9 KiB
C++
Executable File
188 lines
4.9 KiB
C++
Executable File
#include <automask.h>
|
||
#include <config.h>
|
||
#include <execp.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");
|
||
if (xvt_fsys_is_fixed_drive(study))
|
||
i_am_server = true;
|
||
}
|
||
return i_am_server;
|
||
}
|
||
|
||
bool THardy_transaction::is_by_postino() const
|
||
{
|
||
TFilename trans = argv(2);
|
||
return (trans.starts_with("/i") || trans.starts_with("-i"));
|
||
}
|
||
|
||
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
|
||
|
||
long last_size = 0L;
|
||
for (int s = 0; s < 60; s++)
|
||
{
|
||
xvt_sys_sleep(3000);
|
||
long size = fsize(upload);
|
||
if (size == last_size && size > 0)
|
||
break;
|
||
last_size = size;
|
||
}
|
||
|
||
if (last_size == 0L)
|
||
return cantread_box(upload);
|
||
|
||
return true;
|
||
}
|
||
|
||
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();
|
||
|
||
//sono il server?
|
||
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);
|
||
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
|
||
if (i_am_server)
|
||
elabora(*mask);
|
||
else //senno' prepara il .ini per l'elaborazione postinica
|
||
{
|
||
TFilename lista_files = _trans_path;
|
||
lista_files.add(name());
|
||
lista_files.ext("ini");
|
||
TConfig ini(lista_files, "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"));
|
||
}
|
||
}
|
||
} //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");
|
||
_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())
|
||
return error_box(FR("Non esiste la cartella di archiviazione dei files processati &s!"), (const char*)_archive_path);
|
||
|
||
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!"), _conc_path);
|
||
|
||
if (!_trans_path.exist())
|
||
return error_box(FR("Non esiste la cartella di transazione %s!"), (const char*)_trans_path);
|
||
|
||
return TSkeleton_application::create();
|
||
} |