Fix avvio post connessione DB...
This commit is contained in:
@@ -31,20 +31,16 @@ namespace MTC_ADB
|
||||
/// <summary>
|
||||
/// valore booleano di check se sia stato AVVIATO l'adapter (Running)
|
||||
/// </summary>
|
||||
public bool adpRunning = false;
|
||||
public bool adpRunning;
|
||||
/// <summary>
|
||||
/// valore booleano di check se l'adapter STIA SALVANDO
|
||||
/// </summary>
|
||||
public bool adpSaving = false;
|
||||
public bool adpSaving;
|
||||
/// <summary>
|
||||
/// valore booleano (richiesta di riavvio automatico)
|
||||
/// </summary>
|
||||
public bool adpTryRestart;
|
||||
/// <summary>
|
||||
/// porta x adapter (x restart)
|
||||
/// </summary>
|
||||
protected int adpPortNum;
|
||||
/// <summary>
|
||||
/// ultimo ID letto
|
||||
/// </summary>
|
||||
protected uint lastId = 0;
|
||||
@@ -166,15 +162,18 @@ namespace MTC_ADB
|
||||
// salvo al form chiamante
|
||||
parentForm = caller;
|
||||
|
||||
adpRunning = false;
|
||||
adpSaving = false;
|
||||
|
||||
// item base
|
||||
mAdapter.AddDataItem(mAvail);
|
||||
mAdapter.AddDataItem(mStatus);
|
||||
mAdapter.AddDataItem(mClock);
|
||||
mAdapter.AddDataItem(mMessage);
|
||||
mAvail.Value = "";
|
||||
mStatus.Value = "";
|
||||
mClock.Value = "";
|
||||
mMessage.Value = "";
|
||||
mAvail.Value = "ND";
|
||||
mStatus.Value = "ND";
|
||||
mClock.Value = string.Format("{0:yyyy-MM-dd} {0:HH:mm:ss}", DateTime.Now);
|
||||
mMessage.Value = "INIT";
|
||||
|
||||
createDbConn();
|
||||
|
||||
@@ -204,12 +203,16 @@ namespace MTC_ADB
|
||||
/// </summary>
|
||||
public void loadServerConf()
|
||||
{
|
||||
ServerType = utils.CRS("ServerType");
|
||||
ServerAddress = utils.CRS("ServerAddress");
|
||||
DbName = utils.CRS("DbName");
|
||||
DbUser = utils.CRS("DbUser");
|
||||
DbPwd = utils.CRS("DbPwd");
|
||||
DbConn.ConnectionString = string.Format("SERVER={0};database={1};uid={2};password={3}", ServerAddress, DbName, DbUser, DbPwd);
|
||||
// disconnetto e riconnetto SE fosse già connesso...
|
||||
if (!connectionOk)
|
||||
{
|
||||
ServerType = utils.CRS("ServerType");
|
||||
ServerAddress = utils.CRS("ServerAddress");
|
||||
DbName = utils.CRS("DbName");
|
||||
DbUser = utils.CRS("DbUser");
|
||||
DbPwd = utils.CRS("DbPwd");
|
||||
DbConn.ConnectionString = string.Format("SERVER={0};database={1};uid={2};password={3}", ServerAddress, DbName, DbUser, DbPwd);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -242,7 +245,6 @@ namespace MTC_ADB
|
||||
|
||||
// salvo porta!
|
||||
mAdapter.Port = port;
|
||||
adpPortNum = port;
|
||||
// avvio!
|
||||
mAdapter.Start();
|
||||
|
||||
@@ -286,7 +288,6 @@ namespace MTC_ADB
|
||||
lg.Error(exc, "Eccezione in chiusura Adapter");
|
||||
}
|
||||
dtStopAdp = DateTime.Now;
|
||||
adpPortNum = mAdapter.Port;
|
||||
adpTryRestart = tryRestart;
|
||||
adpRunning = false;
|
||||
// chiudo!
|
||||
@@ -355,7 +356,7 @@ namespace MTC_ADB
|
||||
catch (Exception exc)
|
||||
{
|
||||
// segnalo eccezione e indico disconnesso...
|
||||
lg.Error(exc, "Errore in gestione ciclo principale ADP, fermo adapter");
|
||||
lg.Error(exc, string.Format("Errore in gestione ciclo principale ADP, fermo adapter{0}{1}", Environment.NewLine, exc));
|
||||
parentForm.fermaAdapter(true);
|
||||
}
|
||||
// tolgo flag running
|
||||
@@ -443,15 +444,22 @@ namespace MTC_ADB
|
||||
public virtual void tryConnect()
|
||||
{
|
||||
mMessage.Code = "DB-CONN";
|
||||
try
|
||||
if (!connectionOk)
|
||||
{
|
||||
DbConn.Open();
|
||||
mMessage.Value = "ADP - DB Connesso";
|
||||
try
|
||||
{
|
||||
DbConn.Open();
|
||||
mMessage.Value = "ADP - DB Connesso";
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lg.Error(exc, string.Format("Errore apertura connessione DB: {0}{1}", Environment.NewLine, exc));
|
||||
mMessage.Value = "ADP - Errore apertura connessione DB";
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
else
|
||||
{
|
||||
lg.Error(exc, string.Format("Errore apertura connessione DB: {0}{1}", Environment.NewLine, exc));
|
||||
mMessage.Value = "ADP - Errore apertura connessione DB";
|
||||
lg.Info("Exit tryConnect (ADP connected)");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -496,18 +504,23 @@ namespace MTC_ADB
|
||||
DbCommand qrycmd = DbConn.CreateCommand();
|
||||
qrycmd.CommandText = Query;
|
||||
qrycmd.Connection = DbConn;
|
||||
DbDataReader reader = qrycmd.ExecuteReader();
|
||||
try
|
||||
using (DbDataReader reader = qrycmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
try
|
||||
{
|
||||
answ = reader["num"].ToString();
|
||||
while (reader.Read())
|
||||
{
|
||||
answ = reader["num"].ToString();
|
||||
}
|
||||
// chiudo reader!
|
||||
reader.Close();
|
||||
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lg.Error(exc, string.Format("Errore in recupero conteggio eventi: {0}{1}", Environment.NewLine, exc));
|
||||
answ = "ERR";
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lg.Error(exc, string.Format("Errore in recupero conteggio eventi: {0}{1}", Environment.NewLine, exc));
|
||||
answ = "ERR";
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
<add key="normCount" value="300"/><!--30 sec-->
|
||||
<add key="slowCount" value="600"/><!--60 sec-->
|
||||
<add key="verySlowCount" value="1200"/><!--2 min-->
|
||||
<!--parametri gestione watchdog-->
|
||||
<add key="maxAdapterLockSec" value="5"/>
|
||||
<!--conf file-->
|
||||
<add key="dataPath" value="DATA" />
|
||||
<add key="dataConfPath" value="DATA\CONF" />
|
||||
|
||||
@@ -43,23 +43,23 @@ namespace MTC_ADB
|
||||
/// <summary>
|
||||
/// timer base (base moltiplica)
|
||||
/// </summary>
|
||||
protected int timerIntMs = 100; // di norma 100 msec x refresh...
|
||||
protected int timerIntMs = 100; // di norma 100 msec x timer base...
|
||||
/// <summary>
|
||||
/// contatore veloce
|
||||
/// </summary>
|
||||
protected int fastCount = 10; // di norma 1 sec x refresh...
|
||||
protected int fastCount = 1; // 100ms primo refresh...
|
||||
/// <summary>
|
||||
/// contatore normale
|
||||
/// </summary>
|
||||
protected int normCount = 300; // di norma 30 sec x refresh...
|
||||
protected int normCount = 2; // 200ms primo refresh...
|
||||
/// <summary>
|
||||
/// contatore slow
|
||||
/// </summary>
|
||||
protected int slowCount = 600; // di norma 60 sec x refresh...
|
||||
protected int slowCount = 3; // 300ms primo refresh...
|
||||
/// <summary>
|
||||
/// contatore lentissimo
|
||||
/// </summary>
|
||||
protected int verySlowCount = 1200; // di norma 2 minuti
|
||||
protected int verySlowCount = 4; // 400ms primo refresh...
|
||||
/// <summary>
|
||||
/// ultimo tentativo riavvio...
|
||||
/// </summary>
|
||||
@@ -155,6 +155,7 @@ namespace MTC_ADB
|
||||
avviaAdapter();
|
||||
}
|
||||
checkStarted();
|
||||
checkConnected();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -168,10 +169,29 @@ namespace MTC_ADB
|
||||
checkConnected();
|
||||
}
|
||||
/// <summary>
|
||||
/// Tentativo connessione al DB
|
||||
/// </summary>
|
||||
private void connectAdapter()
|
||||
{
|
||||
displayTaskAndWait("...CONNECTIONG DB...");
|
||||
agObj.tryConnect();
|
||||
checkConnected();
|
||||
}
|
||||
/// <summary>
|
||||
/// Tentativo disconnessione al DB
|
||||
/// </summary>
|
||||
private void disconnectAdapter()
|
||||
{
|
||||
displayTaskAndWait("...DISCONNECTIONG DB...");
|
||||
agObj.tryDisconnect();
|
||||
checkConnected();
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifica se il server sia connesso...
|
||||
/// </summary>
|
||||
private void checkConnected()
|
||||
{
|
||||
lblLastData.Text = DateTime.Now.ToString("yy-MM-dd HH:mm:ss");
|
||||
if (agObj.connectionOk)
|
||||
{
|
||||
lblStatus.Text = "CONNECTED";
|
||||
@@ -179,6 +199,7 @@ namespace MTC_ADB
|
||||
lblStatus.ForeColor = Color.Yellow;
|
||||
btnConnect.Text = "close";
|
||||
lblServer.ForeColor = Color.Black;
|
||||
lblServer.Text = string.Format("{0} | {1}", agObj.ServerType, agObj.ServerAddress);
|
||||
// recupero conteggio degli eventi...
|
||||
advProgBar();
|
||||
lblNumData.Text = string.Format("{0} new data", agObj.numRecAvail);
|
||||
@@ -385,14 +406,16 @@ namespace MTC_ADB
|
||||
{
|
||||
// avvio adapter vero e proprio...
|
||||
displayTaskAndWait("Adapter starting");
|
||||
|
||||
// inizio con la connessione al DB
|
||||
loadServerConf();
|
||||
advProgBar();
|
||||
|
||||
agObj = new AdapterGeneric(this);
|
||||
// inizio con la connessione al DB
|
||||
if (!agObj.connectionOk)
|
||||
{
|
||||
loadServerConf();
|
||||
connectAdapter();
|
||||
advProgBar();
|
||||
}
|
||||
agObj.startAdapter(portMTC);
|
||||
displayTaskAndWait("Adapter started!");
|
||||
//displayTaskAndWait("Adapter started!");
|
||||
btnOpenDump.Enabled = true;
|
||||
if (utils.CRB("openDumpOnStart"))
|
||||
{
|
||||
@@ -406,6 +429,7 @@ namespace MTC_ADB
|
||||
fastCount = utils.CRI("fastCount");
|
||||
normCount = utils.CRI("normCount");
|
||||
slowCount = utils.CRI("slowCount");
|
||||
verySlowCount = utils.CRI("verySlowCount");
|
||||
displayTaskAndWait("Adapter Running...");
|
||||
|
||||
}
|
||||
@@ -460,6 +484,7 @@ namespace MTC_ADB
|
||||
lastStartTry = DateTime.Now;
|
||||
agObj.tryConnect();
|
||||
agObj.loadPersData();
|
||||
checkStarted();
|
||||
checkConnected();
|
||||
}
|
||||
}
|
||||
@@ -493,7 +518,6 @@ namespace MTC_ADB
|
||||
if (slowCount <= 0)
|
||||
{
|
||||
slowCount = utils.CRI("slowCount");
|
||||
// avvio fase raccolta dati e invio con adapter
|
||||
agObj.gaterAndSend(gatherCycle.LF);
|
||||
}
|
||||
}
|
||||
@@ -503,7 +527,6 @@ namespace MTC_ADB
|
||||
if (verySlowCount <= 0)
|
||||
{
|
||||
verySlowCount = utils.CRI("verySlowCount");
|
||||
// avvio fase raccolta dati e invio con adapter
|
||||
agObj.gaterAndSend(gatherCycle.VLF);
|
||||
// effettua salvataggio del file di conf con i valori ATTUALI dei parametri ove applicabile/aggiornati (es ore utilizzo, KM assi percorsi...) --> sia file corrente che file "history"
|
||||
persistData();
|
||||
@@ -558,8 +581,7 @@ namespace MTC_ADB
|
||||
if (normCount <= 0)
|
||||
{
|
||||
normCount = utils.CRI("normCount");
|
||||
// avvio fase raccolta dati e invio con adapter
|
||||
agObj.gaterAndSend(gatherCycle.MF);
|
||||
agObj.gaterAndSend(gatherCycle.MF);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -585,9 +607,8 @@ namespace MTC_ADB
|
||||
if (fastCount <= 0)
|
||||
{
|
||||
fastCount = utils.CRI("fastCount");
|
||||
// avvio fase raccolta dati e invio con adapter
|
||||
agObj.gaterAndSend(gatherCycle.HF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -730,12 +751,16 @@ namespace MTC_ADB
|
||||
lblStatus.BackColor = Color.Goldenrod;
|
||||
displayTaskAndWait("Closing DB Connection");
|
||||
// CHIUDO!
|
||||
agObj.tryDisconnect();
|
||||
disconnectAdapter();
|
||||
}
|
||||
else
|
||||
{
|
||||
lblStatus.Text = "...CONNECTING...";
|
||||
lblStatus.BackColor = Color.Goldenrod;
|
||||
displayTaskAndWait("Opening DB Connection");
|
||||
// APRO!
|
||||
loadServerConf();
|
||||
connectAdapter();
|
||||
}
|
||||
// sblocco button...
|
||||
btnConnect.Enabled = true;
|
||||
@@ -752,17 +777,15 @@ namespace MTC_ADB
|
||||
// processo
|
||||
if (agObj.adpRunning)
|
||||
{
|
||||
displayTaskAndWait("Stopping Adapter");
|
||||
// CHIUDO!
|
||||
fermaTutto(true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
avviaAdapter();
|
||||
agObj.loadPersData();
|
||||
displayTaskAndWait("Adapter Started");
|
||||
}
|
||||
checkStarted();
|
||||
checkConnected();
|
||||
// sblocco button...
|
||||
btnStart.Enabled = true;
|
||||
btnStart.Refresh();
|
||||
|
||||
Reference in New Issue
Block a user