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]); Console.WriteLine(rdrMySQL[0] + " -- " + rdrMySQL[1]);
} }
rdrMySQL.Close(); 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) catch (ArgumentException a_ex)
{ {
// General exception found // General exception found
Console.WriteLine(a_ex.ToString()); Console.WriteLine(a_ex.ToString());
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - package type: " + strUDPFrameType); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + 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 >" + a_ex.Message);
bStatus = false; bStatus = false;
} }
catch (MySqlException m_ex) catch (MySqlException m_ex)
{ {
// MySQL exception found // 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) switch (m_ex.Number)
{ {
case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port) 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; break;
case 0: // Access denied (Check DB name,username,password) 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; break;
default: default:
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL > " + m_ex.Number); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + 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.Message);
break; break;
} }
bStatus = false; bStatus = false;
@@ -137,7 +137,7 @@ public class DatabaseController
} }
catch (ArgumentException x_ex) 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 internal class Globals
{ {
public static string strPerunVersion = "DEBUG"; // Helper for pulling version definition public static string strPerunVersion = "DEBUG"; // Helper for pulling version definition
public static string[] arrLogHistory = new string[10]; // Log history for GUI public static string[] arrGUILogHistory = new string[10]; // Log history for GUI
public static bool bLogHistoryUpdate = true; // Flag if log control requires update public static bool bGUILogHistoryUpdate = true; // Flag if log control requires update
public static string strPerunTitleText = ""; // Helper to update title public static string strPerunTitleText = ""; // Helper to update title
public static int intInstanceId = 0; // Kepp the instance ID public static int intInstanceId = 0; // Kepp the instance ID
public static bool bStatusIconsForce = true; // Force main window icons reload public static bool bStatusIconsForce = true; // Force main window icons reload

View File

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

View File

@@ -110,7 +110,7 @@ public class TCPController
dynamic dynamicRawTCPFrame = JsonConvert.DeserializeObject(strReceivedData); // Deserialize received frame dynamic dynamicRawTCPFrame = JsonConvert.DeserializeObject(strReceivedData); // Deserialize received frame
string strRawTCPFrameType = dynamicRawTCPFrame.type; 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) // Add to mySQL send buffer (find first empty slot)
if (Int32.Parse(strRawTCPFrameType) != 0) if (Int32.Parse(strRawTCPFrameType) != 0)
@@ -133,7 +133,7 @@ public class TCPController
{ {
Globals.intGameErros++; Globals.intGameErros++;
Console.WriteLine(e.ToString()); 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; bTCPConnectionOnline = false;
} }
} }
@@ -146,7 +146,7 @@ public class TCPController
{ {
Globals.intGameErros++; Globals.intGameErros++;
Console.WriteLine(e.ToString()); 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; bTCPConnectionOnline = false;
} }

View File

@@ -34,7 +34,7 @@
this.con_Button_Listen_ON = new System.Windows.Forms.Button(); this.con_Button_Listen_ON = new System.Windows.Forms.Button();
this.con_Button_Listen_OFF = new System.Windows.Forms.Button(); this.con_Button_Listen_OFF = new System.Windows.Forms.Button();
this.con_GroupBox_1 = new System.Windows.Forms.GroupBox(); this.con_GroupBox_1 = new System.Windows.Forms.GroupBox();
this.tim_1000ms = new System.Windows.Forms.Timer(this.components); this.tim_GUI = new System.Windows.Forms.Timer(this.components);
this.con_GroupBox_2 = new System.Windows.Forms.GroupBox(); this.con_GroupBox_2 = new System.Windows.Forms.GroupBox();
this.label6 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label();
this.con_txt_mysql_port = new System.Windows.Forms.TextBox(); this.con_txt_mysql_port = new System.Windows.Forms.TextBox();
@@ -57,9 +57,8 @@
this.trayIconMain = new System.Windows.Forms.NotifyIcon(this.components); this.trayIconMain = new System.Windows.Forms.NotifyIcon(this.components);
this.openFileDialog_SRS = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog_SRS = new System.Windows.Forms.OpenFileDialog();
this.openFileDialog_LotATC = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog_LotATC = new System.Windows.Forms.OpenFileDialog();
this.tim_10000ms = new System.Windows.Forms.Timer(this.components); this.tim_3rdparties = new System.Windows.Forms.Timer(this.components);
this.tim_200ms = new System.Windows.Forms.Timer(this.components); this.tim_MySQL = new System.Windows.Forms.Timer(this.components);
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label8 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label();
this.con_txt_dcs_instance = new System.Windows.Forms.MaskedTextBox(); this.con_txt_dcs_instance = new System.Windows.Forms.MaskedTextBox();
@@ -126,10 +125,10 @@
this.con_GroupBox_1.TabStop = false; this.con_GroupBox_1.TabStop = false;
this.con_GroupBox_1.Text = "Data log"; this.con_GroupBox_1.Text = "Data log";
// //
// tim_1000ms // tim_GUI
// //
this.tim_1000ms.Interval = 1000; this.tim_GUI.Interval = 200;
this.tim_1000ms.Tick += new System.EventHandler(this.timer1_Tick); this.tim_GUI.Tick += new System.EventHandler(this.Tim_GUI_Tick);
// //
// con_GroupBox_2 // con_GroupBox_2
// //
@@ -328,19 +327,14 @@
// //
this.openFileDialog_LotATC.FileName = "openFileDialog1"; this.openFileDialog_LotATC.FileName = "openFileDialog1";
// //
// tim_10000ms // tim_3rdparties
// //
this.tim_10000ms.Interval = 30000; this.tim_3rdparties.Interval = 30000;
this.tim_10000ms.Tick += new System.EventHandler(this.tim_10000ms_Tick); this.tim_3rdparties.Tick += new System.EventHandler(this.tim_3rdparties_Tick);
// //
// tim_200ms // tim_MySQL
// //
this.tim_200ms.Tick += new System.EventHandler(this.tim_200ms_Tick); this.tim_MySQL.Tick += new System.EventHandler(this.Tim_MySQL_Tick);
//
// notifyIcon1
//
this.notifyIcon1.Text = "notifyIcon1";
this.notifyIcon1.Visible = true;
// //
// groupBox1 // groupBox1
// //
@@ -499,7 +493,7 @@
this.MaximizeBox = false; this.MaximizeBox = false;
this.Name = "form_Main"; this.Name = "form_Main";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Perun for DCS World"; this.Text = "Perun for DCS";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.form_Main_FormClosing); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.form_Main_FormClosing);
this.Load += new System.EventHandler(this.form_Main_Load); this.Load += new System.EventHandler(this.form_Main_Load);
this.con_GroupBox_1.ResumeLayout(false); this.con_GroupBox_1.ResumeLayout(false);
@@ -524,7 +518,7 @@
private System.Windows.Forms.Button con_Button_Listen_ON; private System.Windows.Forms.Button con_Button_Listen_ON;
private System.Windows.Forms.Button con_Button_Listen_OFF; private System.Windows.Forms.Button con_Button_Listen_OFF;
private System.Windows.Forms.GroupBox con_GroupBox_1; private System.Windows.Forms.GroupBox con_GroupBox_1;
private System.Windows.Forms.Timer tim_1000ms; private System.Windows.Forms.Timer tim_GUI;
private System.Windows.Forms.GroupBox con_GroupBox_2; private System.Windows.Forms.GroupBox con_GroupBox_2;
private System.Windows.Forms.GroupBox con_GroupBox_3; private System.Windows.Forms.GroupBox con_GroupBox_3;
private System.Windows.Forms.TextBox con_txt_mysql_database; private System.Windows.Forms.TextBox con_txt_mysql_database;
@@ -545,11 +539,10 @@
private System.Windows.Forms.NotifyIcon trayIconMain; private System.Windows.Forms.NotifyIcon trayIconMain;
private System.Windows.Forms.OpenFileDialog openFileDialog_SRS; private System.Windows.Forms.OpenFileDialog openFileDialog_SRS;
private System.Windows.Forms.OpenFileDialog openFileDialog_LotATC; private System.Windows.Forms.OpenFileDialog openFileDialog_LotATC;
private System.Windows.Forms.Timer tim_10000ms; private System.Windows.Forms.Timer tim_3rdparties;
private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox con_txt_mysql_port; private System.Windows.Forms.TextBox con_txt_mysql_port;
private System.Windows.Forms.Timer tim_200ms; private System.Windows.Forms.Timer tim_MySQL;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.MaskedTextBox con_txt_dcs_server_port; private System.Windows.Forms.MaskedTextBox con_txt_dcs_server_port;
private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label7;

View File

@@ -10,11 +10,11 @@ namespace Perun_v1
public partial class form_Main : Form public partial class form_Main : Form
{ {
// Variable definitions // Variable definitions
public string[] arrSendBuffer = new string[65534]; // MySQL send buffer public string[] arrMySQLSendBuffer = new string[65534]; // MySQL send buffer
public bool bLetMeOut = false; // Helper to handle system tray public bool bAllowAppClosure = false; // Helper to handle system tray
public DatabaseController dcConnection = new DatabaseController(); // MySQL controller public DatabaseController dcConnection = new DatabaseController(); // MySQL controller
public TCPController tcpcServer=new TCPController(); // TCP controller public TCPController tcpServer=new TCPController(); // TCP controller
public bool bSRSStatus; // Use empty/default SRS status public bool bSRSStatus; // Use empty/default SRS status
public bool bLotATCStatus; // Use empty/default LotATC status public bool bLotATCStatus; // Use empty/default LotATC status
@@ -23,49 +23,51 @@ namespace Perun_v1
private void form_Main_Load(object sender, EventArgs e) private void form_Main_Load(object sender, EventArgs e)
{ {
// Form loaded - fill controls with default values // Form loaded - fill controls with default values
Globals.arrLogHistory[0] = DateTime.Now.ToString("HH:mm:ss") + " > " + "Perun started"; Globals.arrGUILogHistory[0] = DateTime.Now.ToString("HH:mm:ss") + " > " + "Perun started";
Globals.strPerunTitleText = PerunHelper.GetAppVersion(this.Text + " - "); // Display build version in title bar // Display build version in title bar
Globals.strPerunTitleText = PerunHelper.GetAppVersion(this.Text + " - ");
this.Text = Globals.strPerunTitleText; this.Text = Globals.strPerunTitleText;
form_Main_LoadSettings(); // Load settings // Load settings from registry
form_Main_LoadSettings();
// Use command line parameters // Use command line parameters
string[] args = Environment.GetCommandLineArgs(); string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1) if (args.Length > 1)
{
// server port
if (args[1] != null)
{ {
con_txt_dcs_server_port.Text = args[1]; // Get argument server port
if (args[1] != null)
{
con_txt_dcs_server_port.Text = args[1];
}
} }
} if (args.Length > 2)
if (args.Length > 2)
{
// instance id
if (args[2] != null)
{ {
con_txt_dcs_instance.Text = args[2]; // Get argument instance id
if (args[2] != null)
{
con_txt_dcs_instance.Text = args[2];
}
} }
} if (args.Length > 3)
if (args.Length > 3)
{
// srs
if (args[3] != null)
{ {
con_txt_3rd_srs.Text = args[3]; // Get argument DCS SRS file path
con_check_3rd_srs.Checked = true; if (args[3] != null)
{
con_txt_3rd_srs.Text = args[3];
con_check_3rd_srs.Checked = true;
}
} }
} if (args.Length > 4)
if (args.Length > 4)
{
// lotatc
if (args[4] != null)
{ {
con_txt_3rd_lotatc.Text = args[4]; // Get argument lotATC file path
con_check_3rd_lotatc.Checked = true; if (args[4] != null)
{
con_txt_3rd_lotatc.Text = args[4];
con_check_3rd_lotatc.Checked = true;
}
} }
}
} }
public form_Main() public form_Main()
@@ -77,7 +79,7 @@ namespace Perun_v1
// ################################ Helpers ################################ // ################################ Helpers ################################
private void form_Main_LoadSettings() private void form_Main_LoadSettings()
{ {
// Loads settings // Loads registry settings
con_txt_mysql_database.Text = Properties.Settings.Default.MYSQL_DB; con_txt_mysql_database.Text = Properties.Settings.Default.MYSQL_DB;
con_txt_mysql_username.Text = Properties.Settings.Default.MYSQL_User; con_txt_mysql_username.Text = Properties.Settings.Default.MYSQL_User;
con_txt_mysql_password.Text = Properties.Settings.Default.MYSQL_Password; con_txt_mysql_password.Text = Properties.Settings.Default.MYSQL_Password;
@@ -89,12 +91,11 @@ namespace Perun_v1
con_check_3rd_srs.Checked = Properties.Settings.Default.OTHER_SRS_USE; con_check_3rd_srs.Checked = Properties.Settings.Default.OTHER_SRS_USE;
con_txt_dcs_server_port.Text = Properties.Settings.Default.DCS_Server_Port.ToString(); con_txt_dcs_server_port.Text = Properties.Settings.Default.DCS_Server_Port.ToString();
con_txt_dcs_instance.Text = Properties.Settings.Default.DCS_Instance.ToString(); con_txt_dcs_instance.Text = Properties.Settings.Default.DCS_Instance.ToString();
} }
private void form_Main_SaveSettings() private void form_Main_SaveSettings()
{ {
// Saves settings // Saves registry settings
Properties.Settings.Default.MYSQL_Server = con_txt_mysql_database.Text; Properties.Settings.Default.MYSQL_Server = con_txt_mysql_database.Text;
Properties.Settings.Default.MYSQL_DB = con_txt_mysql_database.Text; Properties.Settings.Default.MYSQL_DB = con_txt_mysql_database.Text;
Properties.Settings.Default.MYSQL_User = con_txt_mysql_username.Text; Properties.Settings.Default.MYSQL_User = con_txt_mysql_username.Text;
@@ -153,6 +154,7 @@ namespace Perun_v1
// ################################ User input ################################ // ################################ User input ################################
private void con_Button_Listen_ON_Click(object sender, EventArgs e) private void con_Button_Listen_ON_Click(object sender, EventArgs e)
{ {
// Start listening
// Set globals // Set globals
Globals.intInstanceId= Int32.Parse(con_txt_dcs_instance.Text); Globals.intInstanceId= Int32.Parse(con_txt_dcs_instance.Text);
Globals.bStatusIconsForce = true; Globals.bStatusIconsForce = true;
@@ -160,62 +162,64 @@ namespace Perun_v1
Globals.intMysqlErros = 0; // Reset error counter Globals.intMysqlErros = 0; // Reset error counter
Globals.intGameErros = 0; // Reset error counter Globals.intGameErros = 0; // Reset error counter
Globals.intSRSErros = 0; // Reset error counter Globals.intSRSErros = 0; // Reset error counter
Globals.intLotATCErros = 0; // Reset error counter Globals.intLotATCErros = 0; // Reset error counter
Globals.bClientConnected = false; //no connection Globals.bClientConnected = false; // Reset connection status
// Start listening // Prepare GUI
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Globals.intInstanceId + " > " + "Opening connections"); form_Main_DisableControls();
tcpcServer.Create(Int32.Parse(con_txt_dcs_server_port.Text), ref Globals.arrLogHistory, ref arrSendBuffer); form_Main_SaveSettings();
tcpcServer.thrTCPListener = new Thread(tcpcServer.StartListen); this.Text = "[#" + con_txt_dcs_instance.Text + "] " + Globals.strPerunTitleText; // Set title bar
tcpcServer.thrTCPListener.Start(); trayIconMain.Text = this.Text; // Set notification icon text
tcpcServer.thrTCPListener.Name = "TCPThread";
form_Main_DisableControls(); // Disable controlls // Prepare MySQL connection string
form_Main_SaveSettings(); // Save settings
// Prepare connection string
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; 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");
tcpServer.Create(Int32.Parse(con_txt_dcs_server_port.Text), ref Globals.arrGUILogHistory, ref arrMySQLSendBuffer);
tcpServer.thrTCPListener = new Thread(tcpServer.StartListen);
tcpServer.thrTCPListener.Start();
tcpServer.thrTCPListener.Name = "TCPThread";
// Start timmers // Start timmers
tim_200ms.Enabled = true; tim_MySQL.Enabled = true;
tim_1000ms.Enabled = true; tim_GUI.Enabled = true;
tim_10000ms.Enabled = true; tim_3rdparties.Enabled = true;
// Send initial data // Send initial data
tim_10000ms_Tick(null, null); Tim_MySQL_Tick(null, null);
tim_3rdparties_Tick(null, null);
// Set title bar
this.Text = "[#"+ con_txt_dcs_instance.Text + "] " + Globals.strPerunTitleText;
// Set notification icon text
trayIconMain.Text = this.Text;
} }
private void con_Button_Listen_OFF_Click(object sender, EventArgs e) private void con_Button_Listen_OFF_Click(object sender, EventArgs e)
{ {
// Stop listening // Stop listening
// Prepare GUI
// Display information PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Globals.intInstanceId +" > " + "Closing connections");
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Globals.intInstanceId +" > " + "Closing connections");
con_Button_Listen_OFF.Enabled = false; con_Button_Listen_OFF.Enabled = false;
timer1_Tick(null, null); Tim_GUI_Tick(null, null);
this.Refresh(); this.Refresh();
Application.DoEvents(); Application.DoEvents();
// Stop timmers
tim_GUI.Enabled = false;
tim_3rdparties.Enabled = false;
tim_MySQL.Enabled = false;
// Wait untill TCP server closed connection
try try
{ {
tcpcServer.StopListen(); tcpServer.StopListen();
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex.ToString()); Console.WriteLine(ex.ToString());
} }
while (tcpcServer.thrTCPListener.IsAlive) while (tcpServer.thrTCPListener.IsAlive)
{ {
Thread.Sleep(10); //ms Thread.Sleep(100); //ms
} }
form_Main_EnableControls(); // Enable controls form_Main_EnableControls(); // Enable controls
@@ -224,14 +228,9 @@ namespace Perun_v1
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected"); con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected"); con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
// Stop timmers
tim_1000ms.Enabled = false;
tim_10000ms.Enabled = false;
tim_200ms.Enabled = false;
// Display information about closed connections // Display information about closed connections
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Globals.intInstanceId +" > " + "Connections closed"); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Globals.intInstanceId +" > " + "Connections closed");
timer1_Tick(null, null); Tim_GUI_Tick(null, null);
// Set title bar // Set title bar
this.Text = Globals.strPerunTitleText; this.Text = Globals.strPerunTitleText;
@@ -241,7 +240,7 @@ namespace Perun_v1
Globals.intInstanceId = 0; Globals.intInstanceId = 0;
// Set helpers for updates // Set helpers for updates
Globals.bLogHistoryUpdate = false; Globals.bGUILogHistoryUpdate = false;
Globals.bdcConnection = false; Globals.bdcConnection = false;
Globals.bTCPServer = false; Globals.bTCPServer = false;
Globals.bSRSStatus = false; Globals.bSRSStatus = false;
@@ -295,7 +294,7 @@ namespace Perun_v1
{ {
form_Main_SaveSettings(); form_Main_SaveSettings();
bLetMeOut = true; // Save settings on exit bAllowAppClosure = true; // Save settings on exit
this.Close(); // Allow to exit application this.Close(); // Allow to exit application
} }
else if (dialogResult == DialogResult.No) else if (dialogResult == DialogResult.No)
@@ -335,7 +334,7 @@ namespace Perun_v1
private void form_Main_FormClosing(object sender, FormClosingEventArgs e) private void form_Main_FormClosing(object sender, FormClosingEventArgs e)
{ {
// Minimize to try on clicking "X" // Minimize to try on clicking "X"
if (e.CloseReason == CloseReason.UserClosing && !bLetMeOut) if (e.CloseReason == CloseReason.UserClosing && !bAllowAppClosure)
{ {
e.Cancel = true; e.Cancel = true;
form_Main_SendToTray(); // Send app to system tray form_Main_SendToTray(); // Send app to system tray
@@ -349,64 +348,57 @@ namespace Perun_v1
} }
// ################################ Timers ################################ // ################################ Timers ################################
private void timer1_Tick(object sender, EventArgs e) private void Tim_GUI_Tick(object sender, EventArgs e)
{ {
// 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.bLogHistoryUpdate) if (Globals.bGUILogHistoryUpdate)
{ {
con_List_Received.Items.Clear(); con_List_Received.Items.Clear();
foreach (string i in Globals.arrLogHistory) foreach (string i in Globals.arrGUILogHistory)
{ {
if (i != null) if (i != null)
{ {
con_List_Received.Items.Add(i); con_List_Received.Items.Add(i);
} }
} }
Globals.bLogHistoryUpdate = false; Globals.bGUILogHistoryUpdate = false;
} else } else
{ {
// Do nothing , control does not require update // Do nothing , control does not require update
} }
}
private void tim_200ms_Tick(object sender, EventArgs e)
{
// Send buffer to MySQL
for (int i = 0; i < arrSendBuffer.Length - 1; i++)
{
if (arrSendBuffer[i] != null)
{
dcConnection.SendToMySql(arrSendBuffer[i]);
arrSendBuffer[i] = null;
}
}
// Update status icons at main form // Update status icons at main form
if ((dcConnection.bStatus != Globals.bdcConnection) || Globals.bStatusIconsForce) { if ((dcConnection.bStatus != Globals.bdcConnection) || Globals.bStatusIconsForce)
{
if (dcConnection.bStatus) if (dcConnection.bStatus)
{ {
if (Globals.intMysqlErros == 0) if (Globals.intMysqlErros == 0)
{ {
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected"); con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected");
} else }
else
{ {
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected_error"); con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected_error");
} }
} else }
else
{ {
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 = dcConnection.bStatus; Globals.bdcConnection = dcConnection.bStatus;
} }
if ((Globals.bClientConnected != Globals.bTCPServer) || Globals.bStatusIconsForce || Globals.intGameErros != Globals.intGameErrosHistory) { if ((Globals.bClientConnected != Globals.bTCPServer) || Globals.bStatusIconsForce || Globals.intGameErros != Globals.intGameErrosHistory)
if(Globals.bClientConnected) {
if (Globals.bClientConnected)
{ {
if (Globals.intGameErros == 0 ) if (Globals.intGameErros == 0)
{ {
con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected"); con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected");
} else }
else
{ {
con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected_error"); con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected_error");
} }
@@ -418,13 +410,15 @@ namespace Perun_v1
Globals.bTCPServer = Globals.bClientConnected; Globals.bTCPServer = Globals.bClientConnected;
Globals.intGameErrosHistory = Globals.intGameErros; Globals.intGameErrosHistory = Globals.intGameErros;
} }
if ((bSRSStatus != Globals.bSRSStatus) || Globals.bStatusIconsForce) { if ((bSRSStatus != Globals.bSRSStatus) || Globals.bStatusIconsForce)
{
if (bSRSStatus && con_check_3rd_srs.Checked) if (bSRSStatus && con_check_3rd_srs.Checked)
{ {
if (Globals.intSRSErros == 0) if (Globals.intSRSErros == 0)
{ {
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected"); con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected");
} else }
else
{ {
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected_error"); con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected_error");
} }
@@ -442,7 +436,8 @@ namespace Perun_v1
if (Globals.intLotATCErros == 0) if (Globals.intLotATCErros == 0)
{ {
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected"); con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected");
} else }
else
{ {
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected_error"); con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected_error");
} }
@@ -456,7 +451,20 @@ namespace Perun_v1
Globals.bStatusIconsForce = false; Globals.bStatusIconsForce = false;
} }
private void tim_10000ms_Tick(object sender, EventArgs e) private void Tim_MySQL_Tick(object sender, EventArgs e)
{
// Send buffer to MySQL
for (int i = 0; i < arrMySQLSendBuffer.Length - 1; i++)
{
if (arrMySQLSendBuffer[i] != null)
{
dcConnection.SendToMySql(arrMySQLSendBuffer[i]);
arrMySQLSendBuffer[i] = null;
}
}
}
private void tim_3rdparties_Tick(object sender, EventArgs e)
{ {
// Main timer to send JSON files to MySQL // Main timer to send JSON files to MySQL
string strSRSJson = ""; string strSRSJson = "";
@@ -514,12 +522,12 @@ namespace Perun_v1
strSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'false'}}"; // No SRS clients connected strSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'false'}}"; // No SRS clients connected
} }
boolSRSdefault = false; boolSRSdefault = false;
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > SRS data loaded"); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > SRS data loaded");
bSRSStatus = true; bSRSStatus = true;
} }
catch (Exception exc_srs) catch (Exception exc_srs)
{ {
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > SRS data ERROR > " + exc_srs.Message); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > SRS data ERROR > " + exc_srs.Message);
bSRSStatus = false; bSRSStatus = false;
Globals.intSRSErros++; Globals.intSRSErros++;
} }
@@ -542,12 +550,12 @@ namespace Perun_v1
strLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + strLotATCJson + "'}"; strLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + strLotATCJson + "'}";
boolLotATCdefault = false; boolLotATCdefault = false;
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data loaded"); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data loaded");
bLotATCStatus = true; bLotATCStatus = true;
} }
catch(Exception exc_lotatc) catch(Exception exc_lotatc)
{ {
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data ERROR > " + exc_lotatc.Message); PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data ERROR > " + exc_lotatc.Message);
bLotATCStatus = false; bLotATCStatus = false;
Globals.intLotATCErros++; Globals.intLotATCErros++;
} }

View File

@@ -117,7 +117,7 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="tim_1000ms.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="tim_GUI.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="trayIconMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="trayIconMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
@@ -413,15 +413,12 @@
<metadata name="openFileDialog_LotATC.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="openFileDialog_LotATC.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>397, 17</value> <value>397, 17</value>
</metadata> </metadata>
<metadata name="tim_10000ms.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="tim_3rdparties.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>563, 19</value> <value>563, 19</value>
</metadata> </metadata>
<metadata name="tim_200ms.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="tim_MySQL.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>687, 19</value> <value>687, 19</value>
</metadata> </metadata>
<metadata name="notifyIcon1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>797, 19</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
AAABAAEAQD8AAAEAIAAgQQAAFgAAACgAAABAAAAAfgAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAABAAEAQD8AAAEAIAAgQQAAFgAAACgAAABAAAAAfgAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA