Log file and GUI improvment

This commit is contained in:
szporowolik
2019-10-21 16:41:10 +02:00
parent 1a73404c4c
commit 49495ba9c4
4 changed files with 48 additions and 25 deletions

View File

@@ -103,31 +103,31 @@ public class DatabaseController
Console.WriteLine(rdrMySQL[0] + " -- " + rdrMySQL[1]); Console.WriteLine(rdrMySQL[0] + " -- " + rdrMySQL[1]);
} }
rdrMySQL.Close(); rdrMySQL.Close();
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > MySQL updated, package type: " + strUDPFrameType); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "MySQL updated, package type: " + strUDPFrameType,1);
} }
catch (ArgumentException a_ex) catch (ArgumentException a_ex)
{ {
// General exception found // General exception found
Console.WriteLine(a_ex.ToString()); Console.WriteLine(a_ex.ToString());
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - package type: " + strUDPFrameType); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - package type: " + strUDPFrameType,1,1);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL >" + a_ex.Message); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - error: " + a_ex.Message,1,1);
bStatus = false; bStatus = false;
} }
catch (MySqlException m_ex) catch (MySqlException m_ex)
{ {
// MySQL exception found // MySQL exception found
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - package type: " + strUDPFrameType); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - package type: " + strUDPFrameType,1,1);
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, "#" + strUDPFrameInstance + " > ERROR MySQL - unable to connect >" + m_ex.Message); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - unable to connect, error: " + m_ex.Message,1,1);
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, "#" + strUDPFrameInstance + " > ERROR MySQL - access denied > " + m_ex.Message); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - access denied, error: " + m_ex.Message,1,1);
break; break;
default: default:
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL > " + m_ex.Number); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - error id: " + m_ex.Number,1,1);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL > " + m_ex.Message); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - error: " + m_ex.Message,1,1);
break; break;
} }
bStatus = false; bStatus = false;
@@ -137,7 +137,7 @@ public class DatabaseController
} }
catch (ArgumentException x_ex) catch (ArgumentException x_ex)
{ {
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - unable to connect > " + x_ex.Message); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - unable to connect, error: " + x_ex.Message,1,1);
} }

View File

@@ -4,8 +4,31 @@ using System.Reflection;
internal class PerunHelper internal class PerunHelper
{ {
public static void GUILogHistoryAdd(ref string[] arrLogHistory, string strEntryToAdd) public static void GUILogHistoryAdd(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0)
{ {
// Declare values
string strDirection;
string strMarker;
// Set direction marker
switch (intDirection)
{
case 1:
strDirection = ">";
break;
case 2:
strDirection = "<";
break;
case 3:
strDirection = "^";
break;
default:
strDirection = " ";
break;
}
// Set marker for user flags (markers)
strMarker = (intMarker>0) ? "X" : " ";
// Rotate log history // Rotate log history
for (int i = 0; i < arrLogHistory.Length - 1; i++) for (int i = 0; i < arrLogHistory.Length - 1; i++)
{ {
@@ -13,10 +36,10 @@ internal class PerunHelper
} }
// Add new entry // Add new entry
arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("HH:mm:ss") + " > " + strEntryToAdd; // Add entry at the last position arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("HH:mm:ss") + " " + strDirection + " " + strEntryToAdd; // Add entry at the last position
// Add the entry to log file // Add the entry to log file
LogController.WriteLog(DateTime.Now.ToString("yyyy-dd-MM ") + arrLogHistory[arrLogHistory.Length - 1]); LogController.WriteLog(DateTime.Now.ToString("yyyy-dd-MM ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.intInstanceId + " | " + strMarker + " | " + strDirection + " | " + strEntryToAdd);
// Update control at my window // Update control at my window
Globals.bGUILogHistoryUpdate = true; Globals.bGUILogHistoryUpdate = true;

View File

@@ -122,7 +122,7 @@ public class TCPController
dynamic dynamicRawTCPFrame = JsonConvert.DeserializeObject(strReceivedData); // Deserialize received frame dynamic dynamicRawTCPFrame = JsonConvert.DeserializeObject(strReceivedData); // Deserialize received frame
string strRawTCPFrameType = dynamicRawTCPFrame.type; string strRawTCPFrameType = dynamicRawTCPFrame.type;
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "#" + Globals.intInstanceId + "> TCP packet received, type: " + strRawTCPFrameType); PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "TCP packet received, type: " + strRawTCPFrameType,2);
// Add to mySQL send buffer (find first empty slot) // Add to mySQL send buffer (find first empty slot)
if (Int32.Parse(strRawTCPFrameType) != 0) if (Int32.Parse(strRawTCPFrameType) != 0)
@@ -146,7 +146,7 @@ public class TCPController
{ {
Globals.intGameErros++; Globals.intGameErros++;
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "#" + Globals.intInstanceId + " > TCP ERROR incorrect JSON > " + e.Message); PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "ERROR while message parsing , error: " + e.Message,2,1);
bTCPConnectionOnline = false; bTCPConnectionOnline = false;
} }
@@ -158,7 +158,7 @@ public class TCPController
catch (SocketException e) catch (SocketException e)
{ {
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "#" + Globals.intInstanceId + " > TCP ERROR cannot send > " + e.Message); PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "TCP ERROR cannot check connection, error: " + e.Message,2,1);
} }
} }
@@ -172,7 +172,7 @@ public class TCPController
{ {
Globals.intGameErros++; Globals.intGameErros++;
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "#" + Globals.intInstanceId + " > TCP error - connection closed or port in use > " + e.Message); PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "TCP error - connection closed or port in use, error: " + e.Message,1,1);
bTCPConnectionOnline = false; bTCPConnectionOnline = false;
} }

View File

@@ -187,7 +187,7 @@ namespace Perun_v1
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; 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;
// Start listening // Start listening
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Globals.intInstanceId + " > " + "Opening connections"); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "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.arrGUILogHistory, ref arrMySQLSendBuffer);
tcpServer.thrTCPListener = new Thread(tcpServer.StartListen); tcpServer.thrTCPListener = new Thread(tcpServer.StartListen);
tcpServer.thrTCPListener.Start(); tcpServer.thrTCPListener.Start();
@@ -207,7 +207,7 @@ namespace Perun_v1
{ {
// Stop listening // Stop listening
// Prepare GUI // Prepare GUI
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Globals.intInstanceId + " > " + "Closing connections"); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "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();
@@ -240,7 +240,7 @@ namespace Perun_v1
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, "#" + Globals.intInstanceId + " > " + "Connections closed"); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Connections closed",0,1);
Tim_GUI_Tick(null, null); Tim_GUI_Tick(null, null);
// Set title bar // Set title bar
@@ -534,12 +534,12 @@ namespace Perun_v1
strSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'false'}}"; // No SRS clients connected strSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'false'}}"; // No SRS clients connected
} }
boolSRSdefault = false; boolSRSdefault = false;
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > SRS data loaded"); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "SRS data loaded",3);
bSRSStatus = true; bSRSStatus = true;
} }
catch (Exception exc_srs) catch (Exception exc_srs)
{ {
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > SRS data ERROR > " + exc_srs.Message); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "SRS data ERROR , error: " + exc_srs.Message,3,1);
bSRSStatus = false; bSRSStatus = false;
Globals.intSRSErros++; Globals.intSRSErros++;
} }
@@ -562,12 +562,12 @@ namespace Perun_v1
strLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + strLotATCJson + "'}"; strLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + strLotATCJson + "'}";
boolLotATCdefault = false; boolLotATCdefault = false;
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data loaded"); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "LotATC data loaded",3);
bLotATCStatus = true; bLotATCStatus = true;
} }
catch (Exception exc_lotatc) catch (Exception exc_lotatc)
{ {
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data ERROR > " + exc_lotatc.Message); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "LotATC data ERROR, error: " + exc_lotatc.Message,3,1);
bLotATCStatus = false; bLotATCStatus = false;
Globals.intLotATCErros++; Globals.intLotATCErros++;
} }
@@ -611,7 +611,7 @@ namespace Perun_v1
Globals.bStatusIconsForce = true; Globals.bStatusIconsForce = true;
// Add information // Add information
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Globals.intInstanceId + " > " + "Resetted error counter"); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "Resetted error counter",0,1);
} }
else if (dialogResult == DialogResult.No) else if (dialogResult == DialogResult.No)
{ {
@@ -624,7 +624,7 @@ namespace Perun_v1
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, "#" + Globals.intInstanceId + " > " + "User marker"); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "User Marker",0,1);
} }
} }
} }