Code cleanup

This commit is contained in:
szporowolik
2019-10-20 14:58:04 +02:00
parent 732f8b5fce
commit fc009892f2
7 changed files with 151 additions and 153 deletions

View File

@@ -103,31 +103,31 @@ public class DatabaseController
Console.WriteLine(rdrMySQL[0] + " -- " + rdrMySQL[1]);
}
rdrMySQL.Close();
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > MySQL updated, package type: " + strUDPFrameType);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > MySQL updated, package type: " + strUDPFrameType);
}
catch (ArgumentException a_ex)
{
// General exception found
Console.WriteLine(a_ex.ToString());
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - package type: " + strUDPFrameType);
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL >" + a_ex.Message);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - package type: " + strUDPFrameType);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL >" + a_ex.Message);
bStatus = false;
}
catch (MySqlException m_ex)
{
// MySQL exception found
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - package type: " + strUDPFrameType);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - package type: " + strUDPFrameType);
switch (m_ex.Number)
{
case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port)
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - unable to connect >" + m_ex.Message);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - unable to connect >" + m_ex.Message);
break;
case 0: // Access denied (Check DB name,username,password)
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - access denied > " + m_ex.Message);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - access denied > " + m_ex.Message);
break;
default:
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL > " + m_ex.Number);
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL > " + m_ex.Message);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL > " + m_ex.Number);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL > " + m_ex.Message);
break;
}
bStatus = false;
@@ -137,7 +137,7 @@ public class DatabaseController
}
catch (ArgumentException x_ex)
{
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - unable to connect > " + x_ex.Message);
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - unable to connect > " + x_ex.Message);
}

View File

@@ -4,8 +4,8 @@ using MySql.Data.MySqlClient;
internal class Globals
{
public static string strPerunVersion = "DEBUG"; // Helper for pulling version definition
public static string[] arrLogHistory = new string[10]; // Log history for GUI
public static bool bLogHistoryUpdate = true; // Flag if log control requires update
public static string[] arrGUILogHistory = 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

View File

@@ -4,7 +4,7 @@ using System.Reflection;
internal class PerunHelper
{
public static void LogHistoryAdd(ref string[] arrLogHistory, string strEntryToAdd)
public static void GUILogHistoryAdd(ref string[] arrLogHistory, string strEntryToAdd)
{
// Rotate log history
for (int i = 0; i < arrLogHistory.Length - 1; i++)
@@ -19,7 +19,7 @@ internal class PerunHelper
LogController.WriteLog(arrLogHistory[arrLogHistory.Length - 1]);
// Update control at my window
Globals.bLogHistoryUpdate = true;
Globals.bGUILogHistoryUpdate = true;
}
public static string GetAppVersion(string strBeginning)
{

View File

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