diff --git a/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs b/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs index 4733bd1..c49e76f 100644 --- a/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs +++ b/02_Windows_App/Perun_v1/01_Classes/DatabaseController.cs @@ -38,7 +38,7 @@ public class DatabaseController // Modify specific types if (TCPFrameType == "1") { - TCPFrame.payload["v_win"] = "v" + Globals.strPerunVersion; // Inject app version information + TCPFrame.payload["v_win"] = "v" + Globals.VersionPerun; // Inject app version information } // Specific SQL per each frame type @@ -150,7 +150,7 @@ public class DatabaseController // General exception found Console.WriteLine(a_ex.ToString()); PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - error: " + a_ex.Message,1,1, TCPFrameType); - Globals.intGameErros++; + Globals.ErrorsGame++; DatabaseStatus = false; ReturnValue = 0; } @@ -171,7 +171,7 @@ public class DatabaseController PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - error: " + m_ex.Message,1,1, TCPFrameType); break; } - Globals.intGameErros++; + Globals.ErrorsGame++; DatabaseStatus = false; ReturnValue = 0; } @@ -182,7 +182,7 @@ public class DatabaseController { PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - unable to connect, error: " + x_ex.Message,1,1, TCPFrameType); ReturnValue = 0; - Globals.intGameErros++; + Globals.ErrorsGame++; } return ReturnValue; diff --git a/02_Windows_App/Perun_v1/01_Classes/Globals.cs b/02_Windows_App/Perun_v1/01_Classes/Globals.cs index 1553d30..1dcab73 100644 --- a/02_Windows_App/Perun_v1/01_Classes/Globals.cs +++ b/02_Windows_App/Perun_v1/01_Classes/Globals.cs @@ -2,21 +2,25 @@ internal class Globals { - public static string strPerunVersion = "DEBUG"; // Helper for pulling version definition - public static string[] AppLogHistory = new string[10]; // Log history for GUI - public static bool bGUILogHistoryUpdate = true; // Flag if log control requires update - public static string strPerunTitleText = ""; // Helper to update title - public static int intInstanceId = 0; // Kepp the instance ID - public static bool bStatusIconsForce = true; // Force main window icons reload - public static bool bdcConnection = false; // Historic db connection status - public static bool bTCPServer = false; // Historic tcp connection status - public static bool bSRSStatus = false; // Historic srs connection status - public static bool bLotATCStatus = false; // Historic lotatc connection status - public static bool bClientConnected = false; // Flag if is TCP connectionstill alive - public static int intMysqlErros = 0; // MySQL - Error counter - public static int intGameErros = 0; // TCP connection - Error counter - public static int intGameErrosHistory = 0; // TCP connection - historic value of Error counter - public static int intSRSErros = 0; // DCS SRS - error counter - public static int intLotATCErros = 0; // LotATC - error counter + public static string[] AppLogHistory = new string[10]; // Log history for GUI + public static bool AppUpdateGUI = true; // Flag if log control requires update + public static string AppTitle = ""; // Helper to update title + public static int AppInstanceID = 0; // Kepp the instance ID + public static bool AppForceIconReload = true; // Force main window icons reload + + public static bool StatusDatabase = false; // Historic db connection status + public static bool StatusSRS = false; // Historic srs connection status + public static bool StatusLotATC = false; // Historic lotatc connection status + public static bool StatusHistoryConnection = false; // Historic tcp connection status + public static bool StatusConnection = false; // Flag if is TCP connectionstill alive + public static int ErrorsDatabase = 0; // MySQL - Error counter + public static int ErrorsGame = 0; // TCP connection - Error counter + public static int ErrorsHistoryGame = 0; // TCP connection - historic value of Error counter + public static int ErrorsSRS = 0; // DCS SRS - error counter + public static int ErrorsLotATC = 0; // LotATC - error counter + + public static string VersionDCSHook = ""; // Version - DCS hook + public static string VersionDatabase = ""; // Version - Database + public static string VersionPerun = "DEBUG"; // Version - Perun } diff --git a/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs b/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs index 6f3a56b..462d0d1 100644 --- a/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs +++ b/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs @@ -44,16 +44,16 @@ internal class PerunHelper arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("HH:mm:ss") + " " + LogDirection + " " + strEntryToAdd; // Add entry at the last position // Update control at my window - Globals.bGUILogHistoryUpdate = true; + Globals.AppUpdateGUI = true; } // Add the entry to log file - LogController.WriteLog(DateTime.Now.ToString("yyyy-dd-MM ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.intInstanceId + " | " + LogMarker + " | "+ LogDirection + " | "+ strType + " | " + strEntryToAdd); + LogController.WriteLog(DateTime.Now.ToString("yyyy-dd-MM ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.AppInstanceID + " | " + LogMarker + " | "+ LogDirection + " | "+ strType + " | " + strEntryToAdd); } public static string GetAppVersion(string strBeginning) { // Gets build version - Globals.strPerunVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); - return strBeginning + "v" + Globals.strPerunVersion; + Globals.VersionPerun = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + return strBeginning + "v" + Globals.VersionPerun; } } \ No newline at end of file diff --git a/02_Windows_App/Perun_v1/01_Classes/TCPController.cs b/02_Windows_App/Perun_v1/01_Classes/TCPController.cs index 6b348e6..3450b81 100644 --- a/02_Windows_App/Perun_v1/01_Classes/TCPController.cs +++ b/02_Windows_App/Perun_v1/01_Classes/TCPController.cs @@ -64,7 +64,7 @@ public class TCPController { // Start listening Console.WriteLine("TCP: Waiting for connection"); - Globals.bClientConnected = false; + Globals.StatusConnection = false; // Wait for pending connection if (tcpServer.Pending()) @@ -80,7 +80,7 @@ public class TCPController while (tcpClient.Connected && !bCloseConnection && bTCPConnectionOnline) //while the client is connected, we look for incoming messages { StringBuilder CompleteMessage = new StringBuilder(); - Globals.bClientConnected = true; + Globals.StatusConnection = true; if (nsReadStream.CanRead) { @@ -154,7 +154,7 @@ public class TCPController } catch (Exception e) { - Globals.intGameErros++; + Globals.ErrorsGame++; Console.WriteLine(e.ToString()); PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "ERROR while message parsing , error: " + e.Message,2,1,"?"); bTCPConnectionOnline = false; @@ -180,7 +180,7 @@ public class TCPController } catch (Exception e) { - Globals.intGameErros++; + Globals.ErrorsGame++; Console.WriteLine(e.ToString()); 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 c2fb6de..96ea7a7 100644 --- a/02_Windows_App/Perun_v1/02_Forms/form_Main.cs +++ b/02_Windows_App/Perun_v1/02_Forms/form_Main.cs @@ -27,8 +27,8 @@ namespace Perun_v1 form_Main_LoadSettings(); // Load settings from registry // Display build version in title bar - Globals.strPerunTitleText = PerunHelper.GetAppVersion(this.Text + " - "); - this.Text = Globals.strPerunTitleText; + Globals.AppTitle = PerunHelper.GetAppVersion(this.Text + " - "); + this.Text = Globals.AppTitle; // Use command line parameters string[] args = Environment.GetCommandLineArgs(); @@ -165,18 +165,18 @@ namespace Perun_v1 { // Start listening // Set globals - Globals.intInstanceId = Int32.Parse(con_txt_dcs_instance.Text); - Globals.bStatusIconsForce = true; - Globals.intMysqlErros = 0; // Reset error counter - Globals.intGameErros = 0; // Reset error counter - Globals.intSRSErros = 0; // Reset error counter - Globals.intLotATCErros = 0; // Reset error counter - Globals.bClientConnected = false; // Reset connection status + Globals.AppInstanceID = Int32.Parse(con_txt_dcs_instance.Text); + Globals.AppForceIconReload = true; + Globals.ErrorsDatabase = 0; // Reset error counter + Globals.ErrorsGame = 0; // Reset error counter + Globals.ErrorsSRS = 0; // Reset error counter + Globals.ErrorsLotATC = 0; // Reset error counter + Globals.StatusConnection = false; // Reset connection status // Prepare GUI form_Main_SetControlsToConnected(); form_Main_SaveSettings(); - this.Text = "[#" + con_txt_dcs_instance.Text + "] " + Globals.strPerunTitleText; // Set title bar + this.Text = "[#" + con_txt_dcs_instance.Text + "] " + Globals.AppTitle; // Set title bar trayIconMain.Text = this.Text; // Set notification icon text // Prepare MySQL connection string @@ -243,17 +243,17 @@ namespace Perun_v1 Tim_GUI_Tick(null, null); // Set title bar - this.Text = Globals.strPerunTitleText; + this.Text = Globals.AppTitle; trayIconMain.Text = this.Text; // Set globals - Globals.intInstanceId = 0; - Globals.bGUILogHistoryUpdate = false; - Globals.bdcConnection = false; - Globals.bTCPServer = false; - Globals.bSRSStatus = false; - Globals.bLotATCStatus = false; - Globals.bClientConnected = false; + Globals.AppInstanceID = 0; + Globals.AppUpdateGUI = false; + Globals.StatusDatabase = false; + Globals.StatusHistoryConnection = false; + Globals.StatusSRS = false; + Globals.StatusLotATC = false; + Globals.StatusConnection = false; } private void con_lab_github_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) @@ -360,7 +360,7 @@ namespace Perun_v1 // Main timer to sync GUI with background tasks and flush buffers // Refresh Log Window - if (Globals.bGUILogHistoryUpdate) + if (Globals.AppUpdateGUI) { con_List_Received.Items.Clear(); foreach (string i in Globals.AppLogHistory) @@ -370,7 +370,7 @@ namespace Perun_v1 con_List_Received.Items.Add(i); } } - Globals.bGUILogHistoryUpdate = false; + Globals.AppUpdateGUI = false; } else { @@ -378,11 +378,11 @@ namespace Perun_v1 } // Update status icons at main form - MySQL - if ((DatabaseConnection.DatabaseStatus != Globals.bdcConnection) || Globals.bStatusIconsForce) + if ((DatabaseConnection.DatabaseStatus != Globals.StatusDatabase) || Globals.AppForceIconReload) { if (DatabaseConnection.DatabaseStatus) { - if (Globals.intMysqlErros == 0) + if (Globals.ErrorsDatabase == 0) { con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected"); } @@ -395,14 +395,14 @@ namespace Perun_v1 { con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error"); } - Globals.bdcConnection = DatabaseConnection.DatabaseStatus; + Globals.StatusDatabase = DatabaseConnection.DatabaseStatus; } // Update status icons at main form - DCS - if ((Globals.bClientConnected != Globals.bTCPServer) || Globals.bStatusIconsForce || Globals.intGameErros != Globals.intGameErrosHistory) + if ((Globals.StatusConnection != Globals.StatusHistoryConnection) || Globals.AppForceIconReload || Globals.ErrorsGame != Globals.ErrorsHistoryGame) { - if (Globals.bClientConnected) + if (Globals.StatusConnection) { - if (Globals.intGameErros == 0) + if (Globals.ErrorsGame == 0) { con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected"); } @@ -415,15 +415,15 @@ namespace Perun_v1 { con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error"); } - Globals.bTCPServer = Globals.bClientConnected; - Globals.intGameErrosHistory = Globals.intGameErros; + Globals.StatusHistoryConnection = Globals.StatusConnection; + Globals.ErrorsHistoryGame = Globals.ErrorsGame; } // Update status icons at main form - SRS - if ((ExtSRSStatus != Globals.bSRSStatus) || Globals.bStatusIconsForce) + if ((ExtSRSStatus != Globals.StatusSRS) || Globals.AppForceIconReload) { if (ExtSRSStatus && con_check_3rd_srs.Checked) { - if (Globals.intSRSErros == 0) + if (Globals.ErrorsSRS == 0) { con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected"); } @@ -436,14 +436,14 @@ namespace Perun_v1 { con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error"); } - Globals.bSRSStatus = ExtSRSStatus; + Globals.StatusSRS = ExtSRSStatus; } // Update status icons at main form - LotATC - if ((ExtLotATCStatus != Globals.bLotATCStatus) || Globals.bStatusIconsForce) + if ((ExtLotATCStatus != Globals.StatusLotATC) || Globals.AppForceIconReload) { if (ExtLotATCStatus && con_check_3rd_lotatc.Checked) { - if (Globals.intLotATCErros == 0) + if (Globals.ErrorsLotATC == 0) { con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected"); } @@ -456,9 +456,9 @@ namespace Perun_v1 { con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error"); } - Globals.bLotATCStatus = ExtLotATCStatus; + Globals.StatusLotATC = ExtLotATCStatus; } - Globals.bStatusIconsForce = false; + Globals.AppForceIconReload = false; } private void Tim_MySQL_Tick(object sender, EventArgs e) @@ -491,7 +491,7 @@ namespace Perun_v1 bool ExtLotATCUseDefault = true; // Handle SRS - if (Globals.bClientConnected) + if (Globals.StatusConnection) { if (con_check_3rd_srs.Checked) { @@ -548,7 +548,7 @@ namespace Perun_v1 { PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "SRS data ERROR , error: " + exc_srs.Message, 3, 1, "100"); ExtSRSStatus = false; - Globals.intSRSErros++; + Globals.ErrorsSRS++; } @@ -561,7 +561,7 @@ namespace Perun_v1 } // Handle LotATC - if (Globals.bClientConnected) + if (Globals.StatusConnection) { if (con_check_3rd_lotatc.Checked) { @@ -579,7 +579,7 @@ namespace Perun_v1 { PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "LotATC data ERROR, error: " + exc_lotatc.Message, 3, 1, "101"); ExtLotATCStatus = false; - Globals.intLotATCErros++; + Globals.ErrorsLotATC++; } @@ -592,10 +592,10 @@ namespace Perun_v1 } // Let's do not risk int overload - Globals.intMysqlErros = (Globals.intMysqlErros > 999) ? 999 : Globals.intMysqlErros; - Globals.intGameErros = (Globals.intGameErros > 999) ? 999 : Globals.intGameErros; - Globals.intSRSErros = (Globals.intSRSErros > 999) ? 999 : Globals.intSRSErros; - Globals.intLotATCErros = (Globals.intLotATCErros > 999) ? 999 : Globals.intLotATCErros; + Globals.ErrorsDatabase = (Globals.ErrorsDatabase > 999) ? 999 : Globals.ErrorsDatabase; + Globals.ErrorsGame = (Globals.ErrorsGame > 999) ? 999 : Globals.ErrorsGame; + Globals.ErrorsSRS = (Globals.ErrorsSRS > 999) ? 999 : Globals.ErrorsSRS; + Globals.ErrorsLotATC = (Globals.ErrorsLotATC > 999) ? 999 : Globals.ErrorsLotATC; } @@ -606,14 +606,14 @@ namespace Perun_v1 if (dialogResult == DialogResult.Yes) { // Reset errors counter - Globals.intMysqlErros = 0; // MySQL - Error counter - Globals.intGameErros = 0; // TCP connection - Error counter - Globals.intGameErrosHistory = 0; // TCP connection - historic value of Error counter - Globals.intSRSErros = 0; // DCS SRS - error counter - Globals.intLotATCErros = 0; // LotATC - error counter + Globals.ErrorsDatabase = 0; // MySQL - Error counter + Globals.ErrorsGame = 0; // TCP connection - Error counter + Globals.ErrorsHistoryGame = 0; // TCP connection - historic value of Error counter + Globals.ErrorsSRS = 0; // DCS SRS - error counter + Globals.ErrorsLotATC = 0; // LotATC - error counter // Force icons reload - Globals.bStatusIconsForce = true; + Globals.AppForceIconReload = true; // Add information PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Resetted error counter",0,1);