mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 17:05:39 +02:00
Code cleanup
This commit is contained in:
@@ -5,142 +5,142 @@ using System;
|
|||||||
|
|
||||||
public class DatabaseController
|
public class DatabaseController
|
||||||
{
|
{
|
||||||
public string strMySQLConnectionString; // MySQL connection string
|
public string DatabaseConnectionString; // MySQL connection string
|
||||||
public MySqlConnection connMySQL;
|
public MySqlConnection DatabaseConnection;
|
||||||
public bool bStatus;
|
public bool DatabaseStatus;
|
||||||
|
|
||||||
public void SendToMySql(string strRawTCPFrame, bool bCheckConnection = false)
|
public int SendToMySql(string RawTCPFrame, bool CheckConnection = false)
|
||||||
{
|
{
|
||||||
// Main function to send data to mysql
|
// Main function to send data to mysql
|
||||||
if (bCheckConnection)
|
if (CheckConnection)
|
||||||
{
|
{
|
||||||
strRawTCPFrame = "{\"type\": \"-1\"}";
|
RawTCPFrame = "{\"type\": \"-1\"}";
|
||||||
}
|
}
|
||||||
dynamic strTCPFrame = JsonConvert.DeserializeObject(strRawTCPFrame); // Deserialize raw data
|
dynamic TCPFrame = JsonConvert.DeserializeObject(RawTCPFrame); // Deserialize raw data
|
||||||
string strTCPFrameType = strTCPFrame.type;
|
string TCPFrameType = TCPFrame.type;
|
||||||
string strTCPFrameTimestamp = strTCPFrame.timestamp;
|
string TCPFrameTimestamp = TCPFrame.timestamp;
|
||||||
string strTCPFrameInstance = strTCPFrame.instance;
|
string TCPFrameInstance = TCPFrame.instance;
|
||||||
string strTCPFramePayload;
|
string TCPFramePayload;
|
||||||
string strTCPFramePayload_Perun;
|
string TCPFramePayload_Perun;
|
||||||
string strSQLQueryTxt;
|
string SQLQueryTxt;
|
||||||
|
int ReturnValue = 1;
|
||||||
|
|
||||||
// Some frames may come without timestamp, use database currrent timestampe then
|
// Some frames may come without timestamp, use database currrent timestampe then
|
||||||
if (strTCPFrameTimestamp != null)
|
if (TCPFrameTimestamp != null)
|
||||||
{
|
{
|
||||||
strTCPFrameTimestamp = "'" + strTCPFrameTimestamp + "'";
|
TCPFrameTimestamp = "'" + TCPFrameTimestamp + "'";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strTCPFrameTimestamp = "CURRENT_TIMESTAMP()";
|
TCPFrameTimestamp = "CURRENT_TIMESTAMP()";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify specific types
|
// Modify specific types
|
||||||
if (strTCPFrameType == "1")
|
if (TCPFrameType == "1")
|
||||||
{
|
{
|
||||||
strTCPFrame.payload["v_win"] = "v" + Globals.strPerunVersion; // Inject app version information
|
TCPFrame.payload["v_win"] = "v" + Globals.strPerunVersion; // Inject app version information
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specific SQL per each frame type
|
// Specific SQL per each frame type
|
||||||
if (strTCPFrameType == "50")
|
if (TCPFrameType == "50")
|
||||||
{
|
{
|
||||||
// Add entry to chat log
|
// Add entry to chat log
|
||||||
strSQLQueryTxt = "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + strTCPFrame.payload.ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where `pe_DataPlayers_ucid` = '" + strTCPFrame.payload.ucid + "' );";
|
SQLQueryTxt = "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + TCPFrame.payload.ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where `pe_DataPlayers_ucid` = '" + TCPFrame.payload.ucid + "' );";
|
||||||
strSQLQueryTxt += "UPDATE `pe_DataPlayers` SET `pe_DataPlayers_updated` = " + strTCPFrameTimestamp + ",`pe_DataPlayers_lastname`='" + strTCPFrame.payload.player + "' WHERE `pe_DataPlayers_ucid`='" + strTCPFrame.payload.ucid + "' ;";
|
SQLQueryTxt += "UPDATE `pe_DataPlayers` SET `pe_DataPlayers_updated` = " + TCPFrameTimestamp + ",`pe_DataPlayers_lastname`='" + TCPFrame.payload.player + "' WHERE `pe_DataPlayers_ucid`='" + TCPFrame.payload.ucid + "' ;";
|
||||||
strSQLQueryTxt += "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + strTCPFrame.payload.missionhash + "','" + strTCPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` ='" + strTCPFrame.payload.missionhash + "' AND `pe_DataMissionHashes_instance`=" + strTCPFrameInstance + ");";
|
SQLQueryTxt += "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + TCPFrame.payload.missionhash + "','" + TCPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` ='" + TCPFrame.payload.missionhash + "' AND `pe_DataMissionHashes_instance`=" + TCPFrameInstance + ");";
|
||||||
strSQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + strTCPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.missionhash + "' AND `pe_DataMissionHashes_instance`=" + strTCPFrameInstance + " ;";
|
SQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + TCPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.missionhash + "' AND `pe_DataMissionHashes_instance`=" + TCPFrameInstance + " ;";
|
||||||
strSQLQueryTxt += "INSERT INTO `pe_LogChat` (`pe_LogChat_id`,`pe_LogChat_datetime`, `pe_LogChat_playerid`, `pe_LogChat_msg`, `pe_LogChat_all`,`pe_LogChat_missionhash_id`) VALUES (NULL,'" + strTCPFrame.payload.datetime + "', (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strTCPFrame.payload.ucid + "'), '" + strTCPFrame.payload.msg + "', '" + strTCPFrame.payload.all + "',(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.missionhash + "'));";
|
SQLQueryTxt += "INSERT INTO `pe_LogChat` (`pe_LogChat_id`,`pe_LogChat_datetime`, `pe_LogChat_playerid`, `pe_LogChat_msg`, `pe_LogChat_all`,`pe_LogChat_missionhash_id`) VALUES (NULL,'" + TCPFrame.payload.datetime + "', (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.ucid + "'), '" + TCPFrame.payload.msg + "', '" + TCPFrame.payload.all + "',(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.missionhash + "'));";
|
||||||
}
|
}
|
||||||
else if (strTCPFrameType == "51")
|
else if (TCPFrameType == "51")
|
||||||
{
|
{
|
||||||
// Add entry to event log
|
// Add entry to event log
|
||||||
strSQLQueryTxt = "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + strTCPFrame.payload.log_missionhash + "','" + strTCPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.log_missionhash + "' AND `pe_DataMissionHashes_instance`=" + strTCPFrameInstance + ");";
|
SQLQueryTxt = "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + TCPFrame.payload.log_missionhash + "','" + TCPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.log_missionhash + "' AND `pe_DataMissionHashes_instance`=" + TCPFrameInstance + ");";
|
||||||
strSQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + strTCPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.log_missionhash + "' AND `pe_DataMissionHashes_instance`=" + strTCPFrameInstance + ";";
|
SQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + TCPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.log_missionhash + "' AND `pe_DataMissionHashes_instance`=" + TCPFrameInstance + ";";
|
||||||
strSQLQueryTxt += "INSERT INTO `pe_LogEvent` (`pe_LogEvent_arg1`,`pe_LogEvent_arg2`,`pe_LogEvent_id`, `pe_LogEvent_datetime`, `pe_LogEvent_type`, `pe_LogEvent_content`,`pe_LogEvent_missionhash_id`) VALUES ('" + strTCPFrame.payload.log_arg_1 + "','" + strTCPFrame.payload.log_arg_2 + "', NULL, '" + strTCPFrame.payload.log_datetime + "', '" + strTCPFrame.payload.log_type + "', '" + strTCPFrame.payload.log_content + "', (SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.log_missionhash + "'));";
|
SQLQueryTxt += "INSERT INTO `pe_LogEvent` (`pe_LogEvent_arg1`,`pe_LogEvent_arg2`,`pe_LogEvent_id`, `pe_LogEvent_datetime`, `pe_LogEvent_type`, `pe_LogEvent_content`,`pe_LogEvent_missionhash_id`) VALUES ('" + TCPFrame.payload.log_arg_1 + "','" + TCPFrame.payload.log_arg_2 + "', NULL, '" + TCPFrame.payload.log_datetime + "', '" + TCPFrame.payload.log_type + "', '" + TCPFrame.payload.log_content + "', (SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.log_missionhash + "'));";
|
||||||
}
|
}
|
||||||
else if (strTCPFrameType == "52")
|
else if (TCPFrameType == "52")
|
||||||
{
|
{
|
||||||
// Update user stats
|
// Update user stats
|
||||||
strTCPFramePayload = JsonConvert.SerializeObject(strTCPFrame.payload.stat_data_dcs); // Deserialize payload
|
TCPFramePayload = JsonConvert.SerializeObject(TCPFrame.payload.stat_data_dcs); // Deserialize payload
|
||||||
strTCPFramePayload_Perun = JsonConvert.SerializeObject(strTCPFrame.payload.stat_data_perun); // Deserialize payload
|
TCPFramePayload_Perun = JsonConvert.SerializeObject(TCPFrame.payload.stat_data_perun); // Deserialize payload
|
||||||
|
|
||||||
strSQLQueryTxt = "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + strTCPFrame.payload.stat_missionhash + "','" + strTCPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.stat_missionhash + "' AND `pe_DataMissionHashes_instance`=" + strTCPFrameInstance + ");";
|
SQLQueryTxt = "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + TCPFrame.payload.stat_missionhash + "','" + TCPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "' AND `pe_DataMissionHashes_instance`=" + TCPFrameInstance + ");";
|
||||||
strSQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + strTCPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.stat_missionhash + "' AND `pe_DataMissionHashes_instance`=" + strTCPFrameInstance + " ;";
|
SQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + TCPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "' AND `pe_DataMissionHashes_instance`=" + TCPFrameInstance + " ;";
|
||||||
strSQLQueryTxt += "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + strTCPFrame.payload.stat_ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where `pe_DataPlayers_ucid` = '" + strTCPFrame.payload.stat_ucid + "');";
|
SQLQueryTxt += "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + TCPFrame.payload.stat_ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "');";
|
||||||
strSQLQueryTxt += "UPDATE `pe_DataPlayers` SET `pe_DataPlayers_updated`=" + strTCPFrameTimestamp + " WHERE `pe_DataPlayers_ucid`='" + strTCPFrame.payload.stat_ucid + "';";
|
SQLQueryTxt += "UPDATE `pe_DataPlayers` SET `pe_DataPlayers_updated`=" + TCPFrameTimestamp + " WHERE `pe_DataPlayers_ucid`='" + TCPFrame.payload.stat_ucid + "';";
|
||||||
strSQLQueryTxt += "INSERT INTO `pe_DataTypes` (`pe_DataTypes_name`) SELECT '" + strTCPFrame.payload.stat_data_type + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + strTCPFrame.payload.stat_data_type + "');";
|
SQLQueryTxt += "INSERT INTO `pe_DataTypes` (`pe_DataTypes_name`) SELECT '" + TCPFrame.payload.stat_data_type + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + TCPFrame.payload.stat_data_type + "');";
|
||||||
strSQLQueryTxt += "INSERT INTO `pe_LogStats` (`pe_LogStats_playerid`,`pe_LogStats_missionhash_id`,`pe_LogStats_typeid`) SELECT (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strTCPFrame.payload.stat_ucid + "'), (SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.stat_missionhash + "'), (SELECT pe_DataTypes_id FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + strTCPFrame.payload.stat_data_type + "') FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_LogStats` WHERE `pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.stat_missionhash + "') AND `pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strTCPFrame.payload.stat_ucid + "') AND `pe_LogStats_typeid`= (SELECT pe_DataTypes_id FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + strTCPFrame.payload.stat_data_type + "'));";
|
SQLQueryTxt += "INSERT INTO `pe_LogStats` (`pe_LogStats_playerid`,`pe_LogStats_missionhash_id`,`pe_LogStats_typeid`) SELECT (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "'), (SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "'), (SELECT pe_DataTypes_id FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + TCPFrame.payload.stat_data_type + "') FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_LogStats` WHERE `pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "') AND `pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "') AND `pe_LogStats_typeid`= (SELECT pe_DataTypes_id FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + TCPFrame.payload.stat_data_type + "'));";
|
||||||
strSQLQueryTxt += "UPDATE `pe_LogStats` SET `ps_kills_fortification`=" + strTCPFrame.payload.stat_data_perun.ps_kills_fortification + ",`ps_other_landings`=" + strTCPFrame.payload.stat_data_perun.ps_other_landings + ",`ps_other_takeoffs`=" + strTCPFrame.payload.stat_data_perun.ps_other_takeoffs + ",`ps_pvp`=" + strTCPFrame.payload.stat_data_perun.ps_pvp + ",`ps_deaths`=" + strTCPFrame.payload.stat_data_perun.ps_deaths + ",`ps_ejections`=" + strTCPFrame.payload.stat_data_perun.ps_ejections + ",`ps_crashes`=" + strTCPFrame.payload.stat_data_perun.ps_crashes + ",`ps_teamkills`=" + strTCPFrame.payload.stat_data_perun.ps_teamkills + ",`ps_kills_planes`=" + strTCPFrame.payload.stat_data_perun.ps_kills_planes + ",`ps_kills_helicopters`=" + strTCPFrame.payload.stat_data_perun.ps_kills_helicopters + ",`ps_kills_air_defense`=" + strTCPFrame.payload.stat_data_perun.ps_kills_air_defense + ",`ps_kills_armor`=" + strTCPFrame.payload.stat_data_perun.ps_kills_armor + ",`ps_kills_unarmed`=" + strTCPFrame.payload.stat_data_perun.ps_kills_unarmed + ",`ps_kills_infantry`=" + strTCPFrame.payload.stat_data_perun.ps_kills_infantry + ",`ps_kills_ships`=" + strTCPFrame.payload.stat_data_perun.ps_kills_ships + ",`ps_kills_other`=" + strTCPFrame.payload.stat_data_perun.ps_kills_other + ",`ps_airfield_takeoffs`=" + strTCPFrame.payload.stat_data_perun.ps_airfield_takeoffs + ",`ps_airfield_landings`=" + strTCPFrame.payload.stat_data_perun.ps_airfield_landings + ",`ps_ship_takeoffs`=" + strTCPFrame.payload.stat_data_perun.ps_ship_takeoffs + ",`ps_ship_landings`=" + strTCPFrame.payload.stat_data_perun.ps_ship_landings + ",`ps_farp_takeoffs`=" + strTCPFrame.payload.stat_data_perun.ps_farp_takeoffs + ",`ps_farp_landings`=" + strTCPFrame.payload.stat_data_perun.ps_farp_landings + ", `pe_LogStats_datetime`='" + strTCPFrame.payload.stat_datetime + "',`pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strTCPFrame.payload.stat_ucid + "'),`pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.stat_missionhash + "') WHERE `pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strTCPFrame.payload.stat_missionhash + "') AND `pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strTCPFrame.payload.stat_ucid + "') AND `pe_LogStats_typeid`=(SELECT pe_DataTypes_id FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + strTCPFrame.payload.stat_data_type + "');";
|
SQLQueryTxt += "UPDATE `pe_LogStats` SET `ps_kills_fortification`=" + TCPFrame.payload.stat_data_perun.ps_kills_fortification + ",`ps_other_landings`=" + TCPFrame.payload.stat_data_perun.ps_other_landings + ",`ps_other_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_other_takeoffs + ",`ps_pvp`=" + TCPFrame.payload.stat_data_perun.ps_pvp + ",`ps_deaths`=" + TCPFrame.payload.stat_data_perun.ps_deaths + ",`ps_ejections`=" + TCPFrame.payload.stat_data_perun.ps_ejections + ",`ps_crashes`=" + TCPFrame.payload.stat_data_perun.ps_crashes + ",`ps_teamkills`=" + TCPFrame.payload.stat_data_perun.ps_teamkills + ",`ps_kills_planes`=" + TCPFrame.payload.stat_data_perun.ps_kills_planes + ",`ps_kills_helicopters`=" + TCPFrame.payload.stat_data_perun.ps_kills_helicopters + ",`ps_kills_air_defense`=" + TCPFrame.payload.stat_data_perun.ps_kills_air_defense + ",`ps_kills_armor`=" + TCPFrame.payload.stat_data_perun.ps_kills_armor + ",`ps_kills_unarmed`=" + TCPFrame.payload.stat_data_perun.ps_kills_unarmed + ",`ps_kills_infantry`=" + TCPFrame.payload.stat_data_perun.ps_kills_infantry + ",`ps_kills_ships`=" + TCPFrame.payload.stat_data_perun.ps_kills_ships + ",`ps_kills_other`=" + TCPFrame.payload.stat_data_perun.ps_kills_other + ",`ps_airfield_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_airfield_takeoffs + ",`ps_airfield_landings`=" + TCPFrame.payload.stat_data_perun.ps_airfield_landings + ",`ps_ship_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_ship_takeoffs + ",`ps_ship_landings`=" + TCPFrame.payload.stat_data_perun.ps_ship_landings + ",`ps_farp_takeoffs`=" + TCPFrame.payload.stat_data_perun.ps_farp_takeoffs + ",`ps_farp_landings`=" + TCPFrame.payload.stat_data_perun.ps_farp_landings + ", `pe_LogStats_datetime`='" + TCPFrame.payload.stat_datetime + "',`pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "'),`pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "') WHERE `pe_LogStats_missionhash_id`=(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + TCPFrame.payload.stat_missionhash + "') AND `pe_LogStats_playerid` = (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + TCPFrame.payload.stat_ucid + "') AND `pe_LogStats_typeid`=(SELECT pe_DataTypes_id FROM `pe_DataTypes` where `pe_DataTypes_name` = '" + TCPFrame.payload.stat_data_type + "');";
|
||||||
}
|
}
|
||||||
else if (strTCPFrameType == "53")
|
else if (TCPFrameType == "53")
|
||||||
{
|
{
|
||||||
// User logged in to DCS server
|
// User logged in to DCS server
|
||||||
|
|
||||||
strSQLQueryTxt = "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + strTCPFrame.payload.login_ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where pe_DataPlayers_ucid='" + strTCPFrame.payload.login_ucid + "');";
|
SQLQueryTxt = "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + TCPFrame.payload.login_ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where pe_DataPlayers_ucid='" + TCPFrame.payload.login_ucid + "');";
|
||||||
strSQLQueryTxt += "UPDATE `pe_DataPlayers` SET pe_DataPlayers_lastip='" + strTCPFrame.payload.login_ipaddr + "', pe_DataPlayers_lastname='" + strTCPFrame.payload.login_name + "',pe_DataPlayers_updated='" + strTCPFrame.payload.login_datetime + "' WHERE `pe_DataPlayers_ucid`= '" + strTCPFrame.payload.login_ucid + "';";
|
SQLQueryTxt += "UPDATE `pe_DataPlayers` SET pe_DataPlayers_lastip='" + TCPFrame.payload.login_ipaddr + "', pe_DataPlayers_lastname='" + TCPFrame.payload.login_name + "',pe_DataPlayers_updated='" + TCPFrame.payload.login_datetime + "' WHERE `pe_DataPlayers_ucid`= '" + TCPFrame.payload.login_ucid + "';";
|
||||||
strSQLQueryTxt += "INSERT INTO `pe_LogLogins` (`pe_LogLogins_datetime`, `pe_LogLogins_playerid`, `pe_LogLogins_name`, `pe_LogLogins_ip`,`pe_LogLogins_instance`) VALUES ('" + strTCPFrame.payload.login_datetime + "', (SELECT pe_DataPlayers_id from pe_DataPlayers WHERE pe_DataPlayers_ucid = '" + strTCPFrame.payload.login_ucid + "'), '" + strTCPFrame.payload.login_name + "', '" + strTCPFrame.payload.login_ipaddr + "','" + strTCPFrameInstance + "');";
|
SQLQueryTxt += "INSERT INTO `pe_LogLogins` (`pe_LogLogins_datetime`, `pe_LogLogins_playerid`, `pe_LogLogins_name`, `pe_LogLogins_ip`,`pe_LogLogins_instance`) VALUES ('" + TCPFrame.payload.login_datetime + "', (SELECT pe_DataPlayers_id from pe_DataPlayers WHERE pe_DataPlayers_ucid = '" + TCPFrame.payload.login_ucid + "'), '" + TCPFrame.payload.login_name + "', '" + TCPFrame.payload.login_ipaddr + "','" + TCPFrameInstance + "');";
|
||||||
}
|
}
|
||||||
else if (strTCPFrameType == "-1")
|
else if (TCPFrameType == "-1")
|
||||||
{
|
{
|
||||||
// keep alibe
|
// Keep alive message
|
||||||
strSQLQueryTxt = "SELECT 1;";
|
SQLQueryTxt = "SELECT 1;";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// General definition used for 1-10 type packets
|
// General definition used for 1-10 type packets
|
||||||
strTCPFramePayload = JsonConvert.SerializeObject(strTCPFrame.payload); // Deserialize payload
|
TCPFramePayload = JsonConvert.SerializeObject(TCPFrame.payload); // Deserialize payload
|
||||||
|
|
||||||
strSQLQueryTxt = "INSERT INTO `pe_DataRaw` (`pe_dataraw_type`,`pe_dataraw_instance`) SELECT '" + strTCPFrameType + "','" + strTCPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataRaw` WHERE `pe_dataraw_type` = '" + strTCPFrameType + "' AND `pe_dataraw_instance` = " + strTCPFrameInstance + ");";
|
SQLQueryTxt = "INSERT INTO `pe_DataRaw` (`pe_dataraw_type`,`pe_dataraw_instance`) SELECT '" + TCPFrameType + "','" + TCPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataRaw` WHERE `pe_dataraw_type` = '" + TCPFrameType + "' AND `pe_dataraw_instance` = " + TCPFrameInstance + ");";
|
||||||
strSQLQueryTxt += "UPDATE `pe_DataRaw` SET `pe_dataraw_payload` = JSON_QUOTE('" + strTCPFramePayload + "'), `pe_dataraw_updated`=" + strTCPFrameTimestamp + " WHERE `pe_dataraw_type`=" + strTCPFrameType + " AND `pe_dataraw_instance` = " + strTCPFrameInstance + ";";
|
SQLQueryTxt += "UPDATE `pe_DataRaw` SET `pe_dataraw_payload` = JSON_QUOTE('" + TCPFramePayload + "'), `pe_dataraw_updated`=" + TCPFrameTimestamp + " WHERE `pe_dataraw_type`=" + TCPFrameType + " AND `pe_dataraw_instance` = " + TCPFrameInstance + ";";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to mysql and execute sql
|
// Connect to mysql and execute sql
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
connMySQL = new MySqlConnection(strMySQLConnectionString);
|
DatabaseConnection = new MySqlConnection(DatabaseConnectionString);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine("Sending data to MySQL - Begin");
|
Console.WriteLine("Sending data to MySQL - Begin");
|
||||||
connMySQL.Open();
|
DatabaseConnection.Open();
|
||||||
bStatus = true;
|
DatabaseStatus = true;
|
||||||
MySqlCommand cmdMySQL = new MySqlCommand(strSQLQueryTxt, connMySQL);
|
MySqlCommand DatabaseCommand = new MySqlCommand(SQLQueryTxt, DatabaseConnection);
|
||||||
MySqlDataReader rdrMySQL = cmdMySQL.ExecuteReader();
|
MySqlDataReader DatabaseReader = DatabaseCommand.ExecuteReader();
|
||||||
|
DatabaseReader.Close();
|
||||||
|
|
||||||
rdrMySQL.Close();
|
switch (Int32.Parse(TCPFrameType))
|
||||||
switch (Int32.Parse(strTCPFrameType))
|
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Connected players: " + strTCPFrame.payload["c_players"], 1,0,"1");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Connected players: " + TCPFrame.payload["c_players"], 1,0,"1");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Mission: \"" + strTCPFrame.payload["mission"]["name"]+"\""+ ", time:" + strTCPFrame.payload["mission"]["modeltime"], 1, 0, "2");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Mission: \"" + TCPFrame.payload["mission"]["name"]+"\""+ ", time:" + TCPFrame.payload["mission"]["modeltime"], 1, 0, "2");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Slots data updated", 1, 0, "3");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Slots data updated", 1, 0, "3");
|
||||||
break;
|
break;
|
||||||
case 50:
|
case 50:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Player's \""+ strTCPFrame.payload.player + "\" chat message saved", 1, 0, "50");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Player's \""+ TCPFrame.payload.player + "\" chat message saved", 1, 0, "50");
|
||||||
break;
|
break;
|
||||||
case 51:
|
case 51:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Game event: \""+ strTCPFrame.payload.log_content +"\"", 1, 0, "51");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Game event: \""+ TCPFrame.payload.log_content +"\"", 1, 0, "51");
|
||||||
break;
|
break;
|
||||||
case 52:
|
case 52:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Player's \""+ strTCPFrame.payload.stat_name + "\" stats saved", 1, 0, "52");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Player's \""+ TCPFrame.payload.stat_name + "\" stats saved", 1, 0, "52");
|
||||||
break;
|
break;
|
||||||
case 53:
|
case 53:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Player \""+ strTCPFrame.payload.login_name + "\" logged in", 1, 0, "53");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Player \""+ TCPFrame.payload.login_name + "\" logged in", 1, 0, "53");
|
||||||
break;
|
break;
|
||||||
case 100:
|
case 100:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "SRS data send", 1,0,"100");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "SRS data send", 1,0,"100");
|
||||||
break;
|
break;
|
||||||
case 101:
|
case 101:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "LotATC data send", 1,0,"101");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "LotATC data send", 1,0,"101");
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Data send", 1,0, strTCPFrameType);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Data send", 1,0, TCPFrameType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,9 +149,10 @@ public class DatabaseController
|
|||||||
{
|
{
|
||||||
// General exception found
|
// General exception found
|
||||||
Console.WriteLine(a_ex.ToString());
|
Console.WriteLine(a_ex.ToString());
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - error: " + a_ex.Message,1,1, strTCPFrameType);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - error: " + a_ex.Message,1,1, TCPFrameType);
|
||||||
Globals.intGameErros++;
|
Globals.intGameErros++;
|
||||||
bStatus = false;
|
DatabaseStatus = false;
|
||||||
|
ReturnValue = 0;
|
||||||
}
|
}
|
||||||
catch (MySqlException m_ex)
|
catch (MySqlException m_ex)
|
||||||
{
|
{
|
||||||
@@ -159,28 +160,31 @@ public class DatabaseController
|
|||||||
switch (m_ex.Number)
|
switch (m_ex.Number)
|
||||||
{
|
{
|
||||||
case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port)
|
case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port)
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - unable to connect, error: " + m_ex.Message,1,1, strTCPFrameType);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - unable to connect, error: " + m_ex.Message,1,1, TCPFrameType);
|
||||||
break;
|
break;
|
||||||
case 0: // Access denied (Check DB name,username,password)
|
case 0: // Access denied (Check DB name,username,password)
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - access denied, error: " + m_ex.Message,1,1, strTCPFrameType);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - access denied, error: " + m_ex.Message,1,1, TCPFrameType);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - error id: " + m_ex.Number,1,1, strTCPFrameType);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - error id: " + m_ex.Number,1,1, TCPFrameType);
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - query: " + strSQLQueryTxt, 1, 1, strTCPFrameType);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - query: " + SQLQueryTxt, 1, 1, TCPFrameType);
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - error: " + m_ex.Message,1,1, strTCPFrameType);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - error: " + m_ex.Message,1,1, TCPFrameType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Globals.intGameErros++;
|
Globals.intGameErros++;
|
||||||
bStatus = false;
|
DatabaseStatus = false;
|
||||||
|
ReturnValue = 0;
|
||||||
}
|
}
|
||||||
connMySQL.Close();
|
DatabaseConnection.Close();
|
||||||
Console.WriteLine("Sending data to MySQL - Done");
|
Console.WriteLine("Sending data to MySQL - Done");
|
||||||
}
|
}
|
||||||
catch (ArgumentException x_ex)
|
catch (ArgumentException x_ex)
|
||||||
{
|
{
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - unable to connect, error: " + x_ex.Message,1,1, strTCPFrameType);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - unable to connect, error: " + x_ex.Message,1,1, TCPFrameType);
|
||||||
|
ReturnValue = 0;
|
||||||
|
Globals.intGameErros++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ReturnValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
internal class Globals
|
internal class Globals
|
||||||
{
|
{
|
||||||
public static string strPerunVersion = "DEBUG"; // Helper for pulling version definition
|
public static string strPerunVersion = "DEBUG"; // Helper for pulling version definition
|
||||||
public static string[] arrGUILogHistory = new string[10]; // Log history for GUI
|
public static string[] AppLogHistory = new string[10]; // Log history for GUI
|
||||||
public static bool bGUILogHistoryUpdate = true; // Flag if log control requires update
|
public static bool bGUILogHistoryUpdate = true; // Flag if log control requires update
|
||||||
public static string strPerunTitleText = ""; // Helper to update title
|
public static string strPerunTitleText = ""; // Helper to update title
|
||||||
public static int intInstanceId = 0; // Kepp the instance ID
|
public static int intInstanceId = 0; // Kepp the instance ID
|
||||||
|
|||||||
@@ -6,25 +6,25 @@ class LogController
|
|||||||
// TBD - done via https://stackoverflow.com/questions/20185015/how-to-write-log-file-in-c
|
// TBD - done via https://stackoverflow.com/questions/20185015/how-to-write-log-file-in-c
|
||||||
public static void WriteLog(string strLog)
|
public static void WriteLog(string strLog)
|
||||||
{
|
{
|
||||||
StreamWriter log;
|
StreamWriter LogStreamWriter;
|
||||||
FileStream fileStream = null;
|
FileStream LogFileStream = null;
|
||||||
DirectoryInfo logDirInfo = null;
|
DirectoryInfo LogDirectoryInfo = null;
|
||||||
FileInfo logFileInfo;
|
FileInfo LogFileInfo;
|
||||||
|
|
||||||
string logFilePath = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "\\Perun\\";
|
string LogFilePath = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "\\Perun\\";
|
||||||
logFilePath = logFilePath + "Perun_Log_" + System.DateTime.Today.ToString("yyyyddMM") + "." + "txt";
|
LogFilePath = LogFilePath + "Perun_Log_" + System.DateTime.Today.ToString("yyyyddMM") + "." + "txt";
|
||||||
logFileInfo = new FileInfo(logFilePath);
|
LogFileInfo = new FileInfo(LogFilePath);
|
||||||
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
|
LogDirectoryInfo = new DirectoryInfo(LogFileInfo.DirectoryName);
|
||||||
if (!logDirInfo.Exists) logDirInfo.Create();
|
if (!LogDirectoryInfo.Exists) LogDirectoryInfo.Create();
|
||||||
if (!logFileInfo.Exists)
|
if (!LogFileInfo.Exists)
|
||||||
{
|
{
|
||||||
fileStream = logFileInfo.Create();
|
LogFileStream = LogFileInfo.Create();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fileStream = new FileStream(logFilePath, FileMode.Append);
|
LogFileStream = new FileStream(LogFilePath, FileMode.Append);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -33,9 +33,9 @@ class LogController
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
log = new StreamWriter(fileStream);
|
LogStreamWriter = new StreamWriter(LogFileStream);
|
||||||
log.WriteLine(strLog);
|
LogStreamWriter.WriteLine(strLog);
|
||||||
log.Close();
|
LogStreamWriter.Close();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,27 +7,27 @@ internal class PerunHelper
|
|||||||
public static void GUILogHistoryAdd(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
public static void GUILogHistoryAdd(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||||
{
|
{
|
||||||
// Declare values
|
// Declare values
|
||||||
string strDirection;
|
string LogDirection;
|
||||||
string strMarker;
|
string LogMarker;
|
||||||
// Set direction marker
|
// Set direction marker
|
||||||
switch (intDirection)
|
switch (intDirection)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
strDirection = ">";
|
LogDirection = ">";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
strDirection = "<";
|
LogDirection = "<";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
strDirection = "^";
|
LogDirection = "^";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
strDirection = " ";
|
LogDirection = " ";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set marker for user flags (markers)
|
// Set marker for user flags (markers)
|
||||||
strMarker = (intMarker>0) ? "X" : " ";
|
LogMarker = (intMarker>0) ? "X" : " ";
|
||||||
|
|
||||||
// Set frame type
|
// Set frame type
|
||||||
strType=strType.PadLeft(3, ' ');
|
strType=strType.PadLeft(3, ' ');
|
||||||
@@ -41,28 +41,19 @@ internal class PerunHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add new entry
|
// Add new entry
|
||||||
arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("HH:mm:ss") + " " + strDirection + " " + strEntryToAdd; // Add entry at the last position
|
arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("HH:mm:ss") + " " + LogDirection + " " + strEntryToAdd; // Add entry at the last position
|
||||||
|
|
||||||
// Update control at my window
|
// Update control at my window
|
||||||
Globals.bGUILogHistoryUpdate = true;
|
Globals.bGUILogHistoryUpdate = true;
|
||||||
}
|
}
|
||||||
// Add the entry to log file
|
// Add the entry to log file
|
||||||
LogController.WriteLog(DateTime.Now.ToString("yyyy-dd-MM ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.intInstanceId + " | " + strMarker + " | "+ strDirection + " | "+ strType + " | " + strEntryToAdd);
|
LogController.WriteLog(DateTime.Now.ToString("yyyy-dd-MM ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.intInstanceId + " | " + LogMarker + " | "+ LogDirection + " | "+ strType + " | " + strEntryToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetAppVersion(string strBeginning)
|
public static string GetAppVersion(string strBeginning)
|
||||||
{
|
{
|
||||||
// Gets build version
|
// Gets build version
|
||||||
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
|
|
||||||
{
|
|
||||||
// For network deployed
|
|
||||||
System.Deployment.Application.ApplicationDeployment cd = System.Deployment.Application.ApplicationDeployment.CurrentDeployment;
|
|
||||||
Globals.strPerunVersion = cd.CurrentVersion.ToString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// For other cases
|
|
||||||
Globals.strPerunVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
Globals.strPerunVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||||
}
|
|
||||||
return strBeginning + "v" + Globals.strPerunVersion;
|
return strBeginning + "v" + Globals.strPerunVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,14 +127,20 @@ public class TCPController
|
|||||||
{
|
{
|
||||||
// Add to mySQL send buffer (find first empty slot)
|
// Add to mySQL send buffer (find first empty slot)
|
||||||
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "Packet received" , 2,0, strRawTCPFrameType,true);
|
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "Packet received" , 2,0, strRawTCPFrameType,true);
|
||||||
|
bool AddedDataToBuffer = false;
|
||||||
for (int i = 0; i < arrMySQLSendBuffer.Length - 1; i++)
|
for (int i = 0; i < arrMySQLSendBuffer.Length - 1; i++)
|
||||||
{
|
{
|
||||||
if (arrMySQLSendBuffer[i] == null)
|
if (arrMySQLSendBuffer[i] == null)
|
||||||
{
|
{
|
||||||
arrMySQLSendBuffer[i] = strReceivedData;
|
arrMySQLSendBuffer[i] = strReceivedData;
|
||||||
|
AddedDataToBuffer = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!AddedDataToBuffer)
|
||||||
|
{
|
||||||
|
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "ERROR package was dropped", 1, 1, strRawTCPFrameType);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
// Keep alive
|
// Keep alive
|
||||||
|
|||||||
@@ -98,7 +98,6 @@
|
|||||||
this.con_List_Received.Name = "con_List_Received";
|
this.con_List_Received.Name = "con_List_Received";
|
||||||
this.con_List_Received.Size = new System.Drawing.Size(307, 134);
|
this.con_List_Received.Size = new System.Drawing.Size(307, 134);
|
||||||
this.con_List_Received.TabIndex = 0;
|
this.con_List_Received.TabIndex = 0;
|
||||||
this.con_List_Received.SelectedIndexChanged += new System.EventHandler(this.con_List_Received_SelectedIndexChanged);
|
|
||||||
//
|
//
|
||||||
// con_Button_Listen_ON
|
// con_Button_Listen_ON
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -10,28 +10,26 @@ namespace Perun_v1
|
|||||||
public partial class form_Main : Form
|
public partial class form_Main : Form
|
||||||
{
|
{
|
||||||
// Variable definitions
|
// Variable definitions
|
||||||
public string[] arrMySQLSendBuffer = new string[65534]; // MySQL send buffer
|
public string[] DatabaseSendBuffer = new string[50]; // MySQL send buffer
|
||||||
public bool bAllowAppClosure = false; // Helper to handle system tray
|
public bool AppCanClose = false; // Helper to handle system tray - true needed to quit the app
|
||||||
|
|
||||||
public DatabaseController dcConnection = new DatabaseController(); // MySQL controller
|
public DatabaseController DatabaseConnection = new DatabaseController(); // Main MySQL controller
|
||||||
public TCPController tcpServer = new TCPController(); // TCP controller
|
public TCPController TCPServer = new TCPController(); // Main TCP controller
|
||||||
|
|
||||||
public bool bSRSStatus; // Use empty/default SRS status
|
public bool ExtSRSStatus; // True if to use empty/default SRS status
|
||||||
public bool bLotATCStatus; // Use empty/default LotATC status
|
public bool ExtLotATCStatus; // True if to use empty/default LotATC status
|
||||||
|
|
||||||
// ################################ Main ################################
|
// ################################ Main ################################
|
||||||
private void form_Main_Load(object sender, EventArgs e)
|
private void form_Main_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Form loaded - fill controls with default values
|
// Form loaded
|
||||||
Globals.arrGUILogHistory[0] = DateTime.Now.ToString("HH:mm:ss") + " > " + "Perun started";
|
Globals.AppLogHistory[0] = DateTime.Now.ToString("HH:mm:ss") + " > " + "Perun started"; // Add information to the log control
|
||||||
|
form_Main_LoadSettings(); // Load settings from registry
|
||||||
|
|
||||||
// Display build version in title bar
|
// Display build version in title bar
|
||||||
Globals.strPerunTitleText = PerunHelper.GetAppVersion(this.Text + " - ");
|
Globals.strPerunTitleText = PerunHelper.GetAppVersion(this.Text + " - ");
|
||||||
this.Text = Globals.strPerunTitleText;
|
this.Text = Globals.strPerunTitleText;
|
||||||
|
|
||||||
// Load settings from registry
|
|
||||||
form_Main_LoadSettings();
|
|
||||||
|
|
||||||
// Use command line parameters
|
// Use command line parameters
|
||||||
string[] args = Environment.GetCommandLineArgs();
|
string[] args = Environment.GetCommandLineArgs();
|
||||||
if (args.Length > 1)
|
if (args.Length > 1)
|
||||||
@@ -119,14 +117,14 @@ namespace Perun_v1
|
|||||||
Properties.Settings.Default.Save();
|
Properties.Settings.Default.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void form_Main_DisableControls()
|
private void form_Main_SetControlsToConnected()
|
||||||
{
|
{
|
||||||
// Disables controls
|
// Disables controls
|
||||||
con_Button_Listen_ON.Enabled = false;
|
con_Button_Add_Marker.Enabled = true;
|
||||||
con_Button_Listen_OFF.Enabled = true;
|
con_Button_Listen_OFF.Enabled = true;
|
||||||
|
con_Button_Listen_ON.Enabled = false;
|
||||||
con_Button_Quit.Enabled = false;
|
con_Button_Quit.Enabled = false;
|
||||||
con_Button_Reset_Flags.Enabled = true;
|
con_Button_Reset_Flags.Enabled = true;
|
||||||
con_Button_Add_Marker.Enabled = true;
|
|
||||||
con_txt_mysql_database.Enabled = false;
|
con_txt_mysql_database.Enabled = false;
|
||||||
con_txt_mysql_username.Enabled = false;
|
con_txt_mysql_username.Enabled = false;
|
||||||
con_txt_mysql_password.Enabled = false;
|
con_txt_mysql_password.Enabled = false;
|
||||||
@@ -140,13 +138,13 @@ namespace Perun_v1
|
|||||||
con_txt_dcs_instance.Enabled = false;
|
con_txt_dcs_instance.Enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void form_Main_EnableControls()
|
private void form_Main_SetControlsToDisconnected()
|
||||||
{
|
{
|
||||||
// Enables controls
|
// Enables controls
|
||||||
con_Button_Listen_ON.Enabled = true;
|
|
||||||
con_Button_Listen_OFF.Enabled = false;
|
|
||||||
con_Button_Quit.Enabled = true;
|
|
||||||
con_Button_Reset_Flags.Enabled = false;
|
con_Button_Reset_Flags.Enabled = false;
|
||||||
|
con_Button_Listen_OFF.Enabled = false;
|
||||||
|
con_Button_Listen_ON.Enabled = true;
|
||||||
|
con_Button_Quit.Enabled = true;
|
||||||
con_Button_Add_Marker.Enabled = false;
|
con_Button_Add_Marker.Enabled = false;
|
||||||
con_txt_mysql_database.Enabled = true;
|
con_txt_mysql_database.Enabled = true;
|
||||||
con_txt_mysql_username.Enabled = true;
|
con_txt_mysql_username.Enabled = true;
|
||||||
@@ -169,29 +167,27 @@ namespace Perun_v1
|
|||||||
// Set globals
|
// Set globals
|
||||||
Globals.intInstanceId = Int32.Parse(con_txt_dcs_instance.Text);
|
Globals.intInstanceId = Int32.Parse(con_txt_dcs_instance.Text);
|
||||||
Globals.bStatusIconsForce = true;
|
Globals.bStatusIconsForce = true;
|
||||||
|
|
||||||
Globals.intMysqlErros = 0; // Reset error counter
|
Globals.intMysqlErros = 0; // Reset error counter
|
||||||
Globals.intGameErros = 0; // Reset error counter
|
Globals.intGameErros = 0; // Reset error counter
|
||||||
Globals.intSRSErros = 0; // Reset error counter
|
Globals.intSRSErros = 0; // Reset error counter
|
||||||
Globals.intLotATCErros = 0; // Reset error counter
|
Globals.intLotATCErros = 0; // Reset error counter
|
||||||
|
|
||||||
Globals.bClientConnected = false; // Reset connection status
|
Globals.bClientConnected = false; // Reset connection status
|
||||||
|
|
||||||
// Prepare GUI
|
// Prepare GUI
|
||||||
form_Main_DisableControls();
|
form_Main_SetControlsToConnected();
|
||||||
form_Main_SaveSettings();
|
form_Main_SaveSettings();
|
||||||
this.Text = "[#" + con_txt_dcs_instance.Text + "] " + Globals.strPerunTitleText; // Set title bar
|
this.Text = "[#" + con_txt_dcs_instance.Text + "] " + Globals.strPerunTitleText; // Set title bar
|
||||||
trayIconMain.Text = this.Text; // Set notification icon text
|
trayIconMain.Text = this.Text; // Set notification icon text
|
||||||
|
|
||||||
// Prepare MySQL connection string
|
// Prepare MySQL connection string
|
||||||
dcConnection.strMySQLConnectionString = "server=" + con_txt_mysql_server.Text + ";user=" + con_txt_mysql_username.Text + ";database=" + con_txt_mysql_database.Text + ";port=" + con_txt_mysql_port.Text + ";password=" + con_txt_mysql_password.Text;
|
DatabaseConnection.DatabaseConnectionString = "server=" + con_txt_mysql_server.Text + ";user=" + con_txt_mysql_username.Text + ";database=" + con_txt_mysql_database.Text + ";port=" + con_txt_mysql_port.Text + ";password=" + con_txt_mysql_password.Text;
|
||||||
|
|
||||||
// Start listening
|
// Start listening
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Opening connections",0,1);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Opening connections",0,1);
|
||||||
tcpServer.Create(Int32.Parse(con_txt_dcs_server_port.Text), ref Globals.arrGUILogHistory, ref arrMySQLSendBuffer);
|
TCPServer.Create(Int32.Parse(con_txt_dcs_server_port.Text), ref Globals.AppLogHistory, ref DatabaseSendBuffer);
|
||||||
tcpServer.thrTCPListener = new Thread(tcpServer.StartListen);
|
TCPServer.thrTCPListener = new Thread(TCPServer.StartListen);
|
||||||
tcpServer.thrTCPListener.Start();
|
TCPServer.thrTCPListener.Start();
|
||||||
tcpServer.thrTCPListener.Name = "TCPThread";
|
TCPServer.thrTCPListener.Name = "TCPThread";
|
||||||
|
|
||||||
// Start timmers
|
// Start timmers
|
||||||
tim_MySQL.Enabled = true;
|
tim_MySQL.Enabled = true;
|
||||||
@@ -207,7 +203,7 @@ namespace Perun_v1
|
|||||||
{
|
{
|
||||||
// Stop listening
|
// Stop listening
|
||||||
// Prepare GUI
|
// Prepare GUI
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Closing connections",0,1);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Closing connections",0,1);
|
||||||
con_Button_Listen_OFF.Enabled = false;
|
con_Button_Listen_OFF.Enabled = false;
|
||||||
Tim_GUI_Tick(null, null);
|
Tim_GUI_Tick(null, null);
|
||||||
this.Refresh();
|
this.Refresh();
|
||||||
@@ -218,29 +214,32 @@ namespace Perun_v1
|
|||||||
tim_3rdparties.Enabled = false;
|
tim_3rdparties.Enabled = false;
|
||||||
tim_MySQL.Enabled = false;
|
tim_MySQL.Enabled = false;
|
||||||
|
|
||||||
// Wait untill TCP server closed connection
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tcpServer.StopListen();
|
// Stop the server
|
||||||
|
TCPServer.StopListen();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "TCP ERROR, error: " + ex.Message, 2, 1, "?");
|
||||||
Console.WriteLine(ex.ToString());
|
Console.WriteLine(ex.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
while (tcpServer.thrTCPListener.IsAlive)
|
while (TCPServer.thrTCPListener.IsAlive)
|
||||||
{
|
{
|
||||||
Thread.Sleep(100); //ms
|
// Wait untill TCP server closed connection
|
||||||
|
Thread.Sleep(200); //ms
|
||||||
}
|
}
|
||||||
form_Main_EnableControls(); // Enable controls
|
form_Main_SetControlsToDisconnected(); // Enable controls
|
||||||
|
|
||||||
|
// Load status images
|
||||||
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
|
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
|
||||||
con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
|
con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
|
||||||
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
|
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
|
||||||
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
|
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
|
||||||
|
|
||||||
// Display information about closed connections
|
// Display information about closed connections
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Connections closed",0,1);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Connections closed",0,1);
|
||||||
Tim_GUI_Tick(null, null);
|
Tim_GUI_Tick(null, null);
|
||||||
|
|
||||||
// Set title bar
|
// Set title bar
|
||||||
@@ -249,8 +248,6 @@ namespace Perun_v1
|
|||||||
|
|
||||||
// Set globals
|
// Set globals
|
||||||
Globals.intInstanceId = 0;
|
Globals.intInstanceId = 0;
|
||||||
|
|
||||||
// Set helpers for updates
|
|
||||||
Globals.bGUILogHistoryUpdate = false;
|
Globals.bGUILogHistoryUpdate = false;
|
||||||
Globals.bdcConnection = false;
|
Globals.bdcConnection = false;
|
||||||
Globals.bTCPServer = false;
|
Globals.bTCPServer = false;
|
||||||
@@ -299,13 +296,13 @@ namespace Perun_v1
|
|||||||
// ################################ Form state ################################
|
// ################################ Form state ################################
|
||||||
private void con_Button_Quit_Click(object sender, EventArgs e)
|
private void con_Button_Quit_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Close app
|
// Try to close app
|
||||||
DialogResult dialogResult = MessageBox.Show("Are you sure to exit Perun?", "Question", MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
|
DialogResult dialogResult = MessageBox.Show("Are you sure to exit Perun?", "Question", MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
|
||||||
if (dialogResult == DialogResult.Yes)
|
if (dialogResult == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
form_Main_SaveSettings();
|
form_Main_SaveSettings();
|
||||||
|
|
||||||
bAllowAppClosure = true; // Save settings on exit
|
AppCanClose = true; // Save settings on exit
|
||||||
this.Close(); // Allow to exit application
|
this.Close(); // Allow to exit application
|
||||||
}
|
}
|
||||||
else if (dialogResult == DialogResult.No)
|
else if (dialogResult == DialogResult.No)
|
||||||
@@ -341,11 +338,10 @@ namespace Perun_v1
|
|||||||
TopMost = top;
|
TopMost = top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void form_Main_FormClosing(object sender, FormClosingEventArgs e)
|
private void form_Main_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
// Minimize to try on clicking "X"
|
// Minimize to try on clicking "X"
|
||||||
if (e.CloseReason == CloseReason.UserClosing && !bAllowAppClosure)
|
if (e.CloseReason == CloseReason.UserClosing && !AppCanClose)
|
||||||
{
|
{
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
form_Main_SendToTray(); // Send app to system tray
|
form_Main_SendToTray(); // Send app to system tray
|
||||||
@@ -367,7 +363,7 @@ namespace Perun_v1
|
|||||||
if (Globals.bGUILogHistoryUpdate)
|
if (Globals.bGUILogHistoryUpdate)
|
||||||
{
|
{
|
||||||
con_List_Received.Items.Clear();
|
con_List_Received.Items.Clear();
|
||||||
foreach (string i in Globals.arrGUILogHistory)
|
foreach (string i in Globals.AppLogHistory)
|
||||||
{
|
{
|
||||||
if (i != null)
|
if (i != null)
|
||||||
{
|
{
|
||||||
@@ -381,10 +377,10 @@ namespace Perun_v1
|
|||||||
// Do nothing , control does not require update
|
// Do nothing , control does not require update
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update status icons at main form
|
// Update status icons at main form - MySQL
|
||||||
if ((dcConnection.bStatus != Globals.bdcConnection) || Globals.bStatusIconsForce)
|
if ((DatabaseConnection.DatabaseStatus != Globals.bdcConnection) || Globals.bStatusIconsForce)
|
||||||
{
|
{
|
||||||
if (dcConnection.bStatus)
|
if (DatabaseConnection.DatabaseStatus)
|
||||||
{
|
{
|
||||||
if (Globals.intMysqlErros == 0)
|
if (Globals.intMysqlErros == 0)
|
||||||
{
|
{
|
||||||
@@ -399,9 +395,9 @@ namespace Perun_v1
|
|||||||
{
|
{
|
||||||
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
|
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
|
||||||
}
|
}
|
||||||
Globals.bdcConnection = dcConnection.bStatus;
|
Globals.bdcConnection = DatabaseConnection.DatabaseStatus;
|
||||||
}
|
}
|
||||||
|
// Update status icons at main form - DCS
|
||||||
if ((Globals.bClientConnected != Globals.bTCPServer) || Globals.bStatusIconsForce || Globals.intGameErros != Globals.intGameErrosHistory)
|
if ((Globals.bClientConnected != Globals.bTCPServer) || Globals.bStatusIconsForce || Globals.intGameErros != Globals.intGameErrosHistory)
|
||||||
{
|
{
|
||||||
if (Globals.bClientConnected)
|
if (Globals.bClientConnected)
|
||||||
@@ -422,9 +418,10 @@ namespace Perun_v1
|
|||||||
Globals.bTCPServer = Globals.bClientConnected;
|
Globals.bTCPServer = Globals.bClientConnected;
|
||||||
Globals.intGameErrosHistory = Globals.intGameErros;
|
Globals.intGameErrosHistory = Globals.intGameErros;
|
||||||
}
|
}
|
||||||
if ((bSRSStatus != Globals.bSRSStatus) || Globals.bStatusIconsForce)
|
// Update status icons at main form - SRS
|
||||||
|
if ((ExtSRSStatus != Globals.bSRSStatus) || Globals.bStatusIconsForce)
|
||||||
{
|
{
|
||||||
if (bSRSStatus && con_check_3rd_srs.Checked)
|
if (ExtSRSStatus && con_check_3rd_srs.Checked)
|
||||||
{
|
{
|
||||||
if (Globals.intSRSErros == 0)
|
if (Globals.intSRSErros == 0)
|
||||||
{
|
{
|
||||||
@@ -439,11 +436,12 @@ namespace Perun_v1
|
|||||||
{
|
{
|
||||||
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
|
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
|
||||||
}
|
}
|
||||||
Globals.bSRSStatus = bSRSStatus;
|
Globals.bSRSStatus = ExtSRSStatus;
|
||||||
}
|
}
|
||||||
if ((bLotATCStatus != Globals.bLotATCStatus) || Globals.bStatusIconsForce)
|
// Update status icons at main form - LotATC
|
||||||
|
if ((ExtLotATCStatus != Globals.bLotATCStatus) || Globals.bStatusIconsForce)
|
||||||
{
|
{
|
||||||
if (bLotATCStatus && con_check_3rd_lotatc.Checked)
|
if (ExtLotATCStatus && con_check_3rd_lotatc.Checked)
|
||||||
{
|
{
|
||||||
if (Globals.intLotATCErros == 0)
|
if (Globals.intLotATCErros == 0)
|
||||||
{
|
{
|
||||||
@@ -458,7 +456,7 @@ namespace Perun_v1
|
|||||||
{
|
{
|
||||||
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
|
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
|
||||||
}
|
}
|
||||||
Globals.bLotATCStatus = bLotATCStatus;
|
Globals.bLotATCStatus = ExtLotATCStatus;
|
||||||
}
|
}
|
||||||
Globals.bStatusIconsForce = false;
|
Globals.bStatusIconsForce = false;
|
||||||
}
|
}
|
||||||
@@ -466,12 +464,14 @@ namespace Perun_v1
|
|||||||
private void Tim_MySQL_Tick(object sender, EventArgs e)
|
private void Tim_MySQL_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Send buffer to MySQL
|
// Send buffer to MySQL
|
||||||
for (int i = 0; i < arrMySQLSendBuffer.Length - 1; i++)
|
for (int i = 0; i < DatabaseSendBuffer.Length - 1; i++)
|
||||||
{
|
{
|
||||||
if (arrMySQLSendBuffer[i] != null)
|
if (DatabaseSendBuffer[i] != null)
|
||||||
{
|
{
|
||||||
dcConnection.SendToMySql(arrMySQLSendBuffer[i]);
|
if (DatabaseConnection.SendToMySql(DatabaseSendBuffer[i]) > 0)
|
||||||
arrMySQLSendBuffer[i] = null;
|
{
|
||||||
|
DatabaseSendBuffer[i] = null; // If packet was send then delete it from send buffer
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -481,14 +481,14 @@ namespace Perun_v1
|
|||||||
// Main timer to check MySQL connection and send JSON files to MySQL
|
// Main timer to check MySQL connection and send JSON files to MySQL
|
||||||
|
|
||||||
// Send ping to check for possible connection issues
|
// Send ping to check for possible connection issues
|
||||||
dcConnection.SendToMySql("", true);
|
DatabaseConnection.SendToMySql("", true);
|
||||||
|
|
||||||
// Take care of 3rd party stuff
|
// Take care of 3rd party stuff
|
||||||
string strSRSJson = "";
|
string ExtSRSJson = "";
|
||||||
string strLotATCJson = "";
|
string ExtLotATCJson = "";
|
||||||
|
|
||||||
bool boolSRSdefault = true;
|
bool ExtSRSUseDefault = true;
|
||||||
bool boolLotATCdefault = true;
|
bool ExtLotATCUseDefault = true;
|
||||||
|
|
||||||
// Handle SRS
|
// Handle SRS
|
||||||
if (Globals.bClientConnected)
|
if (Globals.bClientConnected)
|
||||||
@@ -497,8 +497,8 @@ namespace Perun_v1
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
strSRSJson = System.IO.File.ReadAllText(con_txt_3rd_srs.Text);
|
ExtSRSJson = System.IO.File.ReadAllText(con_txt_3rd_srs.Text);
|
||||||
dynamic raw_lotatc = JsonConvert.DeserializeObject(strSRSJson);
|
dynamic raw_lotatc = JsonConvert.DeserializeObject(ExtSRSJson);
|
||||||
|
|
||||||
for (int i = 0; i < raw_lotatc.Count; i++)
|
for (int i = 0; i < raw_lotatc.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -533,31 +533,31 @@ namespace Perun_v1
|
|||||||
|
|
||||||
if (raw_lotatc.Count > 0)
|
if (raw_lotatc.Count > 0)
|
||||||
{
|
{
|
||||||
strSRSJson = JsonConvert.SerializeObject(raw_lotatc);
|
ExtSRSJson = JsonConvert.SerializeObject(raw_lotatc);
|
||||||
strSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + strSRSJson + "'}";
|
ExtSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + ExtSRSJson + "'}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'false'}}"; // No SRS clients connected
|
ExtSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'false'}}"; // No SRS clients connected
|
||||||
}
|
}
|
||||||
boolSRSdefault = false;
|
ExtSRSUseDefault = false;
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "SRS data loaded", 3, 0, "100", true);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "SRS data loaded", 3, 0, "100", true);
|
||||||
bSRSStatus = true;
|
ExtSRSStatus = true;
|
||||||
}
|
}
|
||||||
catch (Exception exc_srs)
|
catch (Exception exc_srs)
|
||||||
{
|
{
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "SRS data ERROR , error: " + exc_srs.Message, 3, 1, "100");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "SRS data ERROR , error: " + exc_srs.Message, 3, 1, "100");
|
||||||
bSRSStatus = false;
|
ExtSRSStatus = false;
|
||||||
Globals.intSRSErros++;
|
Globals.intSRSErros++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (boolSRSdefault)
|
if (ExtSRSUseDefault)
|
||||||
{
|
{
|
||||||
strSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'true'}}";
|
ExtSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'true'}}";
|
||||||
}
|
}
|
||||||
dcConnection.SendToMySql(strSRSJson);
|
DatabaseConnection.SendToMySql(ExtSRSJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle LotATC
|
// Handle LotATC
|
||||||
@@ -567,28 +567,28 @@ namespace Perun_v1
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
strLotATCJson = System.IO.File.ReadAllText(con_txt_3rd_lotatc.Text);
|
ExtLotATCJson = System.IO.File.ReadAllText(con_txt_3rd_lotatc.Text);
|
||||||
dynamic raw_srs = JsonConvert.DeserializeObject(strLotATCJson);
|
dynamic raw_srs = JsonConvert.DeserializeObject(ExtLotATCJson);
|
||||||
|
|
||||||
strLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + strLotATCJson + "'}";
|
ExtLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + ExtLotATCJson + "'}";
|
||||||
boolLotATCdefault = false;
|
ExtLotATCUseDefault = false;
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "LotATC data loaded", 3, 0, "101", true);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "LotATC data loaded", 3, 0, "101", true);
|
||||||
bLotATCStatus = true;
|
ExtLotATCStatus = true;
|
||||||
}
|
}
|
||||||
catch (Exception exc_lotatc)
|
catch (Exception exc_lotatc)
|
||||||
{
|
{
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "LotATC data ERROR, error: " + exc_lotatc.Message, 3, 1, "101");
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "LotATC data ERROR, error: " + exc_lotatc.Message, 3, 1, "101");
|
||||||
bLotATCStatus = false;
|
ExtLotATCStatus = false;
|
||||||
Globals.intLotATCErros++;
|
Globals.intLotATCErros++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (boolLotATCdefault)
|
if (ExtLotATCUseDefault)
|
||||||
{
|
{
|
||||||
strLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'true'}}"; // No LotATC controller connected
|
ExtLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'true'}}"; // No LotATC controller connected
|
||||||
}
|
}
|
||||||
dcConnection.SendToMySql(strLotATCJson);
|
DatabaseConnection.SendToMySql(ExtLotATCJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's do not risk int overload
|
// Let's do not risk int overload
|
||||||
@@ -599,12 +599,6 @@ namespace Perun_v1
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void con_List_Received_SelectedIndexChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void con_Button_Reset_Flags_Click(object sender, EventArgs e)
|
private void con_Button_Reset_Flags_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Reset error flags
|
// Reset error flags
|
||||||
@@ -622,20 +616,19 @@ namespace Perun_v1
|
|||||||
Globals.bStatusIconsForce = true;
|
Globals.bStatusIconsForce = true;
|
||||||
|
|
||||||
// Add information
|
// Add information
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Resetted error counter",0,1);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Resetted error counter",0,1);
|
||||||
}
|
}
|
||||||
else if (dialogResult == DialogResult.No)
|
else if (dialogResult == DialogResult.No)
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void con_Button_Add_Marker_Click(object sender, EventArgs e)
|
private void con_Button_Add_Marker_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Added user marker
|
// Added user marker
|
||||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "User Marker",0,1);
|
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "User Marker",0,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,14 +131,17 @@
|
|||||||
<Compile Include="01_Classes\PerunHelper.cs" />
|
<Compile Include="01_Classes\PerunHelper.cs" />
|
||||||
<Compile Include="02_Forms\form_Main.cs">
|
<Compile Include="02_Forms\form_Main.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="02_Forms\form_Main.Designer.cs">
|
<Compile Include="02_Forms\form_Main.Designer.cs">
|
||||||
<DependentUpon>form_Main.cs</DependentUpon>
|
<DependentUpon>form_Main.cs</DependentUpon>
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="01_Classes\Program.cs" />
|
<Compile Include="01_Classes\Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<EmbeddedResource Include="02_Forms\form_Main.resx">
|
<EmbeddedResource Include="02_Forms\form_Main.resx">
|
||||||
<DependentUpon>form_Main.cs</DependentUpon>
|
<DependentUpon>form_Main.cs</DependentUpon>
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
<EmbeddedResource Include="Properties\Resources.resx">
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
|||||||
Reference in New Issue
Block a user