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
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;

View File

@@ -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
}

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
// 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;
}
}

View File

@@ -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;