mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 15:55:39 +02:00
General cleanup
This commit is contained in:
@@ -16,9 +16,9 @@ public class DatabaseController
|
||||
string strUDPFrameType = strUDPFrame.type;
|
||||
string strUDPFrameTimestamp = strUDPFrame.timestamp;
|
||||
string strUDPFrameInstance = strUDPFrame.instance;
|
||||
string strUDPFramePayload = "";
|
||||
string strUDPFramePayload_Perun = "";
|
||||
string strSQLQueryTxt = "";
|
||||
string strUDPFramePayload;
|
||||
string strUDPFramePayload_Perun;
|
||||
string strSQLQueryTxt;
|
||||
|
||||
|
||||
// Some frames may come without timestamp, use database currrent timestampe then
|
||||
@@ -86,48 +86,58 @@ public class DatabaseController
|
||||
}
|
||||
|
||||
// Connect to mysql and execute sql
|
||||
connMySQL = new MySqlConnection(strMySQLConnectionString);
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Sending data to MySQL - Begin");
|
||||
connMySQL.Open();
|
||||
bStatus = true;
|
||||
MySqlCommand cmdMySQL = new MySqlCommand(strSQLQueryTxt, connMySQL);
|
||||
MySqlDataReader rdrMySQL = cmdMySQL.ExecuteReader();
|
||||
connMySQL = new MySqlConnection(strMySQLConnectionString);
|
||||
|
||||
while (rdrMySQL.Read())
|
||||
try
|
||||
{
|
||||
Console.WriteLine(rdrMySQL[0] + " -- " + rdrMySQL[1]);
|
||||
Console.WriteLine("Sending data to MySQL - Begin");
|
||||
connMySQL.Open();
|
||||
bStatus = true;
|
||||
MySqlCommand cmdMySQL = new MySqlCommand(strSQLQueryTxt, connMySQL);
|
||||
MySqlDataReader rdrMySQL = cmdMySQL.ExecuteReader();
|
||||
|
||||
while (rdrMySQL.Read())
|
||||
{
|
||||
Console.WriteLine(rdrMySQL[0] + " -- " + rdrMySQL[1]);
|
||||
}
|
||||
rdrMySQL.Close();
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > MySQL updated, package type: " + strUDPFrameType);
|
||||
}
|
||||
rdrMySQL.Close();
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#"+strUDPFrameInstance + " > MySQL updated, package type: " + strUDPFrameType);
|
||||
}
|
||||
catch (ArgumentException a_ex)
|
||||
{
|
||||
// General exception found
|
||||
Console.WriteLine(a_ex.ToString());
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - package type: " + strUDPFrameType);
|
||||
bStatus = false;
|
||||
}
|
||||
catch (MySqlException m_ex)
|
||||
{
|
||||
// MySQL exception found
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - package type: " + strUDPFrameType);
|
||||
switch (m_ex.Number)
|
||||
catch (ArgumentException a_ex)
|
||||
{
|
||||
case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port)
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - unable to connect");
|
||||
break;
|
||||
case 0: // Access denied (Check DB name,username,password)
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - access denied");
|
||||
break;
|
||||
default:
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - " + m_ex.Number);
|
||||
break;
|
||||
// General exception found
|
||||
Console.WriteLine(a_ex.ToString());
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - package type: " + strUDPFrameType);
|
||||
bStatus = false;
|
||||
}
|
||||
bStatus = false;
|
||||
catch (MySqlException m_ex)
|
||||
{
|
||||
// MySQL exception found
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - package type: " + strUDPFrameType);
|
||||
switch (m_ex.Number)
|
||||
{
|
||||
case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port)
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - unable to connect");
|
||||
break;
|
||||
case 0: // Access denied (Check DB name,username,password)
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - access denied");
|
||||
break;
|
||||
default:
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - " + m_ex.Number);
|
||||
break;
|
||||
}
|
||||
bStatus = false;
|
||||
}
|
||||
connMySQL.Close();
|
||||
Console.WriteLine("Sending data to MySQL - Done");
|
||||
}
|
||||
connMySQL.Close();
|
||||
Console.WriteLine("Sending data to MySQL - Done");
|
||||
catch (ArgumentException)
|
||||
{
|
||||
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - wrong connection parameters");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user