Code clean up

This commit is contained in:
szporowolik
2019-10-22 16:30:47 +02:00
parent 53aade262e
commit a0c9a249f6
5 changed files with 81 additions and 77 deletions

View File

@@ -38,7 +38,7 @@ public class DatabaseController
// Modify specific types // Modify specific types
if (TCPFrameType == "1") 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 // Specific SQL per each frame type
@@ -150,7 +150,7 @@ public class DatabaseController
// General exception found // General exception found
Console.WriteLine(a_ex.ToString()); Console.WriteLine(a_ex.ToString());
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - error: " + a_ex.Message,1,1, TCPFrameType); PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - error: " + a_ex.Message,1,1, TCPFrameType);
Globals.intGameErros++; Globals.ErrorsGame++;
DatabaseStatus = false; DatabaseStatus = false;
ReturnValue = 0; ReturnValue = 0;
} }
@@ -171,7 +171,7 @@ public class DatabaseController
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - error: " + m_ex.Message,1,1, TCPFrameType); PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - error: " + m_ex.Message,1,1, TCPFrameType);
break; break;
} }
Globals.intGameErros++; Globals.ErrorsGame++;
DatabaseStatus = false; DatabaseStatus = false;
ReturnValue = 0; 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); PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "ERROR MySQL - unable to connect, error: " + x_ex.Message,1,1, TCPFrameType);
ReturnValue = 0; ReturnValue = 0;
Globals.intGameErros++; Globals.ErrorsGame++;
} }
return ReturnValue; return ReturnValue;

View File

@@ -2,21 +2,25 @@
internal class Globals 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 string[] AppLogHistory = new string[10]; // Log history for GUI
public static bool bGUILogHistoryUpdate = true; // Flag if log control requires update public static bool AppUpdateGUI = true; // Flag if log control requires update
public static string strPerunTitleText = ""; // Helper to update title public static string AppTitle = ""; // Helper to update title
public static int intInstanceId = 0; // Kepp the instance ID public static int AppInstanceID = 0; // Kepp the instance ID
public static bool bStatusIconsForce = true; // Force main window icons reload public static bool AppForceIconReload = 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 StatusDatabase = false; // Historic db connection status
public static bool bSRSStatus = false; // Historic srs connection status public static bool StatusSRS = false; // Historic srs connection status
public static bool bLotATCStatus = false; // Historic lotatc connection status public static bool StatusLotATC = false; // Historic lotatc connection status
public static bool bClientConnected = false; // Flag if is TCP connectionstill alive public static bool StatusHistoryConnection = false; // Historic tcp connection status
public static int intMysqlErros = 0; // MySQL - Error counter public static bool StatusConnection = false; // Flag if is TCP connectionstill alive
public static int intGameErros = 0; // TCP connection - Error counter public static int ErrorsDatabase = 0; // MySQL - Error counter
public static int intGameErrosHistory = 0; // TCP connection - historic value of Error counter public static int ErrorsGame = 0; // TCP connection - Error counter
public static int intSRSErros = 0; // DCS SRS - error counter public static int ErrorsHistoryGame = 0; // TCP connection - historic value of Error counter
public static int intLotATCErros = 0; // LotATC - 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
} }

View File

@@ -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 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.AppUpdateGUI = 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 + " | " + 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) public static string GetAppVersion(string strBeginning)
{ {
// Gets build version // Gets build version
Globals.strPerunVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); Globals.VersionPerun = Assembly.GetExecutingAssembly().GetName().Version.ToString();
return strBeginning + "v" + Globals.strPerunVersion; return strBeginning + "v" + Globals.VersionPerun;
} }
} }

View File

@@ -64,7 +64,7 @@ public class TCPController
{ {
// Start listening // Start listening
Console.WriteLine("TCP: Waiting for connection"); Console.WriteLine("TCP: Waiting for connection");
Globals.bClientConnected = false; Globals.StatusConnection = false;
// Wait for pending connection // Wait for pending connection
if (tcpServer.Pending()) 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 while (tcpClient.Connected && !bCloseConnection && bTCPConnectionOnline) //while the client is connected, we look for incoming messages
{ {
StringBuilder CompleteMessage = new StringBuilder(); StringBuilder CompleteMessage = new StringBuilder();
Globals.bClientConnected = true; Globals.StatusConnection = true;
if (nsReadStream.CanRead) if (nsReadStream.CanRead)
{ {
@@ -154,7 +154,7 @@ public class TCPController
} }
catch (Exception e) catch (Exception e)
{ {
Globals.intGameErros++; Globals.ErrorsGame++;
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "ERROR while message parsing , error: " + e.Message,2,1,"?"); PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "ERROR while message parsing , error: " + e.Message,2,1,"?");
bTCPConnectionOnline = false; bTCPConnectionOnline = false;
@@ -180,7 +180,7 @@ public class TCPController
} }
catch (Exception e) catch (Exception e)
{ {
Globals.intGameErros++; Globals.ErrorsGame++;
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "TCP error - connection closed or port in use, error: " + e.Message,1,1,"?"); PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "TCP error - connection closed or port in use, error: " + e.Message,1,1,"?");
bTCPConnectionOnline = false; bTCPConnectionOnline = false;

View File

@@ -27,8 +27,8 @@ namespace Perun_v1
form_Main_LoadSettings(); // Load settings from registry 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.AppTitle = PerunHelper.GetAppVersion(this.Text + " - ");
this.Text = Globals.strPerunTitleText; this.Text = Globals.AppTitle;
// Use command line parameters // Use command line parameters
string[] args = Environment.GetCommandLineArgs(); string[] args = Environment.GetCommandLineArgs();
@@ -165,18 +165,18 @@ namespace Perun_v1
{ {
// Start listening // Start listening
// Set globals // Set globals
Globals.intInstanceId = Int32.Parse(con_txt_dcs_instance.Text); Globals.AppInstanceID = Int32.Parse(con_txt_dcs_instance.Text);
Globals.bStatusIconsForce = true; Globals.AppForceIconReload = true;
Globals.intMysqlErros = 0; // Reset error counter Globals.ErrorsDatabase = 0; // Reset error counter
Globals.intGameErros = 0; // Reset error counter Globals.ErrorsGame = 0; // Reset error counter
Globals.intSRSErros = 0; // Reset error counter Globals.ErrorsSRS = 0; // Reset error counter
Globals.intLotATCErros = 0; // Reset error counter Globals.ErrorsLotATC = 0; // Reset error counter
Globals.bClientConnected = false; // Reset connection status Globals.StatusConnection = false; // Reset connection status
// Prepare GUI // Prepare GUI
form_Main_SetControlsToConnected(); 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.AppTitle; // 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
@@ -243,17 +243,17 @@ namespace Perun_v1
Tim_GUI_Tick(null, null); Tim_GUI_Tick(null, null);
// Set title bar // Set title bar
this.Text = Globals.strPerunTitleText; this.Text = Globals.AppTitle;
trayIconMain.Text = this.Text; trayIconMain.Text = this.Text;
// Set globals // Set globals
Globals.intInstanceId = 0; Globals.AppInstanceID = 0;
Globals.bGUILogHistoryUpdate = false; Globals.AppUpdateGUI = false;
Globals.bdcConnection = false; Globals.StatusDatabase = false;
Globals.bTCPServer = false; Globals.StatusHistoryConnection = false;
Globals.bSRSStatus = false; Globals.StatusSRS = false;
Globals.bLotATCStatus = false; Globals.StatusLotATC = false;
Globals.bClientConnected = false; Globals.StatusConnection = false;
} }
private void con_lab_github_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 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 // Main timer to sync GUI with background tasks and flush buffers
// Refresh Log Window // Refresh Log Window
if (Globals.bGUILogHistoryUpdate) if (Globals.AppUpdateGUI)
{ {
con_List_Received.Items.Clear(); con_List_Received.Items.Clear();
foreach (string i in Globals.AppLogHistory) foreach (string i in Globals.AppLogHistory)
@@ -370,7 +370,7 @@ namespace Perun_v1
con_List_Received.Items.Add(i); con_List_Received.Items.Add(i);
} }
} }
Globals.bGUILogHistoryUpdate = false; Globals.AppUpdateGUI = false;
} }
else else
{ {
@@ -378,11 +378,11 @@ namespace Perun_v1
} }
// Update status icons at main form - MySQL // 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 (DatabaseConnection.DatabaseStatus)
{ {
if (Globals.intMysqlErros == 0) if (Globals.ErrorsDatabase == 0)
{ {
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected"); 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"); 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 // 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"); 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"); con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
} }
Globals.bTCPServer = Globals.bClientConnected; Globals.StatusHistoryConnection = Globals.StatusConnection;
Globals.intGameErrosHistory = Globals.intGameErros; Globals.ErrorsHistoryGame = Globals.ErrorsGame;
} }
// Update status icons at main form - SRS // 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 (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"); 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"); 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 // 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 (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"); 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"); 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) private void Tim_MySQL_Tick(object sender, EventArgs e)
@@ -491,7 +491,7 @@ namespace Perun_v1
bool ExtLotATCUseDefault = true; bool ExtLotATCUseDefault = true;
// Handle SRS // Handle SRS
if (Globals.bClientConnected) if (Globals.StatusConnection)
{ {
if (con_check_3rd_srs.Checked) 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"); PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "SRS data ERROR , error: " + exc_srs.Message, 3, 1, "100");
ExtSRSStatus = false; ExtSRSStatus = false;
Globals.intSRSErros++; Globals.ErrorsSRS++;
} }
@@ -561,7 +561,7 @@ namespace Perun_v1
} }
// Handle LotATC // Handle LotATC
if (Globals.bClientConnected) if (Globals.StatusConnection)
{ {
if (con_check_3rd_lotatc.Checked) 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"); PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "LotATC data ERROR, error: " + exc_lotatc.Message, 3, 1, "101");
ExtLotATCStatus = false; ExtLotATCStatus = false;
Globals.intLotATCErros++; Globals.ErrorsLotATC++;
} }
@@ -592,10 +592,10 @@ namespace Perun_v1
} }
// Let's do not risk int overload // Let's do not risk int overload
Globals.intMysqlErros = (Globals.intMysqlErros > 999) ? 999 : Globals.intMysqlErros; Globals.ErrorsDatabase = (Globals.ErrorsDatabase > 999) ? 999 : Globals.ErrorsDatabase;
Globals.intGameErros = (Globals.intGameErros > 999) ? 999 : Globals.intGameErros; Globals.ErrorsGame = (Globals.ErrorsGame > 999) ? 999 : Globals.ErrorsGame;
Globals.intSRSErros = (Globals.intSRSErros > 999) ? 999 : Globals.intSRSErros; Globals.ErrorsSRS = (Globals.ErrorsSRS > 999) ? 999 : Globals.ErrorsSRS;
Globals.intLotATCErros = (Globals.intLotATCErros > 999) ? 999 : Globals.intLotATCErros; Globals.ErrorsLotATC = (Globals.ErrorsLotATC > 999) ? 999 : Globals.ErrorsLotATC;
} }
@@ -606,14 +606,14 @@ namespace Perun_v1
if (dialogResult == DialogResult.Yes) if (dialogResult == DialogResult.Yes)
{ {
// Reset errors counter // Reset errors counter
Globals.intMysqlErros = 0; // MySQL - Error counter Globals.ErrorsDatabase = 0; // MySQL - Error counter
Globals.intGameErros = 0; // TCP connection - Error counter Globals.ErrorsGame = 0; // TCP connection - Error counter
Globals.intGameErrosHistory = 0; // TCP connection - historic value of Error counter Globals.ErrorsHistoryGame = 0; // TCP connection - historic value of Error counter
Globals.intSRSErros = 0; // DCS SRS - error counter Globals.ErrorsSRS = 0; // DCS SRS - error counter
Globals.intLotATCErros = 0; // LotATC - error counter Globals.ErrorsLotATC = 0; // LotATC - error counter
// Force icons reload // Force icons reload
Globals.bStatusIconsForce = true; Globals.AppForceIconReload = true;
// Add information // Add information
PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Resetted error counter",0,1); PerunHelper.GUILogHistoryAdd(ref Globals.AppLogHistory, "Resetted error counter",0,1);