diff --git a/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs b/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs index 496699f..3cee1c7 100644 --- a/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs +++ b/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs @@ -103,31 +103,31 @@ public class DatabaseController Console.WriteLine(rdrMySQL[0] + " -- " + rdrMySQL[1]); } 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) { // General exception found Console.WriteLine(a_ex.ToString()); - PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - package type: " + strUDPFrameType); - PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL >" + a_ex.Message); + PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - package type: " + strUDPFrameType,1,1); + PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - error: " + a_ex.Message,1,1); bStatus = false; } catch (MySqlException m_ex) { // 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) { 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; 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; default: - PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL > " + m_ex.Number); - PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL > " + m_ex.Message); + PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - error id: " + m_ex.Number,1,1); + PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "ERROR MySQL - error: " + m_ex.Message,1,1); break; } bStatus = false; @@ -137,7 +137,7 @@ public class DatabaseController } 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); } diff --git a/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs b/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs index 4760e3f..d34b93a 100644 --- a/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs +++ b/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs @@ -4,8 +4,31 @@ using System.Reflection; 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 for (int i = 0; i < arrLogHistory.Length - 1; i++) { @@ -13,10 +36,10 @@ internal class PerunHelper } // 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 - 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 Globals.bGUILogHistoryUpdate = true; diff --git a/02_Windows_App/Perun_v1/01_Classes/TCPController.cs b/02_Windows_App/Perun_v1/01_Classes/TCPController.cs index 4e8ce88..f781268 100644 --- a/02_Windows_App/Perun_v1/01_Classes/TCPController.cs +++ b/02_Windows_App/Perun_v1/01_Classes/TCPController.cs @@ -122,7 +122,7 @@ public class TCPController dynamic dynamicRawTCPFrame = JsonConvert.DeserializeObject(strReceivedData); // Deserialize received frame 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) if (Int32.Parse(strRawTCPFrameType) != 0) @@ -146,7 +146,7 @@ public class TCPController { Globals.intGameErros++; 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; } @@ -158,7 +158,7 @@ public class TCPController catch (SocketException e) { 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++; 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; } diff --git a/02_Windows_App/Perun_v1/02_Forms/form_Main.cs b/02_Windows_App/Perun_v1/02_Forms/form_Main.cs index 633fabd..61c8a66 100644 --- a/02_Windows_App/Perun_v1/02_Forms/form_Main.cs +++ b/02_Windows_App/Perun_v1/02_Forms/form_Main.cs @@ -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; // 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.thrTCPListener = new Thread(tcpServer.StartListen); tcpServer.thrTCPListener.Start(); @@ -207,7 +207,7 @@ namespace Perun_v1 { // Stop listening // 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; Tim_GUI_Tick(null, null); this.Refresh(); @@ -240,7 +240,7 @@ namespace Perun_v1 con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected"); // 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); // 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 } 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; } 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; Globals.intSRSErros++; } @@ -562,12 +562,12 @@ namespace Perun_v1 strLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + strLotATCJson + "'}"; 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; } 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; Globals.intLotATCErros++; } @@ -611,7 +611,7 @@ namespace Perun_v1 Globals.bStatusIconsForce = true; // 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) { @@ -624,7 +624,7 @@ namespace Perun_v1 private void con_Button_Add_Marker_Click(object sender, EventArgs e) { // Added user marker - PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Globals.intInstanceId + " > " + "User marker"); + PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "User Marker",0,1); } } }