Added status icons and better connection handling

This commit is contained in:
szporowolik
2019-10-19 23:00:54 +02:00
parent 48f60abbfa
commit 2f7d2d07bb
14 changed files with 224 additions and 152 deletions

View File

@@ -65,14 +65,14 @@
this.con_txt_dcs_instance = new System.Windows.Forms.MaskedTextBox();
this.label7 = new System.Windows.Forms.Label();
this.con_txt_dcs_server_port = new System.Windows.Forms.MaskedTextBox();
this.con_img_lotATC = new System.Windows.Forms.PictureBox();
this.con_img_srs = new System.Windows.Forms.PictureBox();
this.con_img_dcs = new System.Windows.Forms.PictureBox();
this.con_img_db = new System.Windows.Forms.PictureBox();
this.label9 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.con_img_lotATC = new System.Windows.Forms.PictureBox();
this.con_img_srs = new System.Windows.Forms.PictureBox();
this.con_img_dcs = new System.Windows.Forms.PictureBox();
this.con_img_db = new System.Windows.Forms.PictureBox();
this.con_GroupBox_1.SuspendLayout();
this.con_GroupBox_2.SuspendLayout();
this.con_GroupBox_3.SuspendLayout();
@@ -89,10 +89,11 @@
this.con_List_Received.FormattingEnabled = true;
this.con_List_Received.Items.AddRange(new object[] {
"Not connected"});
this.con_List_Received.Location = new System.Drawing.Point(6, 19);
this.con_List_Received.Location = new System.Drawing.Point(11, 19);
this.con_List_Received.Name = "con_List_Received";
this.con_List_Received.Size = new System.Drawing.Size(307, 147);
this.con_List_Received.Size = new System.Drawing.Size(307, 134);
this.con_List_Received.TabIndex = 0;
this.con_List_Received.SelectedIndexChanged += new System.EventHandler(this.con_List_Received_SelectedIndexChanged);
//
// con_Button_Listen_ON
//
@@ -118,9 +119,9 @@
// con_GroupBox_1
//
this.con_GroupBox_1.Controls.Add(this.con_List_Received);
this.con_GroupBox_1.Location = new System.Drawing.Point(12, 369);
this.con_GroupBox_1.Location = new System.Drawing.Point(12, 385);
this.con_GroupBox_1.Name = "con_GroupBox_1";
this.con_GroupBox_1.Size = new System.Drawing.Size(324, 176);
this.con_GroupBox_1.Size = new System.Drawing.Size(324, 162);
this.con_GroupBox_1.TabIndex = 4;
this.con_GroupBox_1.TabStop = false;
this.con_GroupBox_1.Text = "Data log";
@@ -386,8 +387,53 @@
this.con_txt_dcs_server_port.Size = new System.Drawing.Size(207, 20);
this.con_txt_dcs_server_port.TabIndex = 3;
//
// label9
//
this.label9.AutoSize = true;
this.label9.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label9.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label9.Location = new System.Drawing.Point(21, 369);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(61, 13);
this.label9.TabIndex = 1;
this.label9.Text = "Database";
//
// label10
//
this.label10.AutoSize = true;
this.label10.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label10.Location = new System.Drawing.Point(117, 369);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(39, 13);
this.label10.TabIndex = 14;
this.label10.Text = "Game";
//
// label11
//
this.label11.AutoSize = true;
this.label11.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label11.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label11.Location = new System.Drawing.Point(205, 369);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(32, 13);
this.label11.TabIndex = 15;
this.label11.Text = "SRS";
//
// label12
//
this.label12.AutoSize = true;
this.label12.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label12.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label12.Location = new System.Drawing.Point(282, 369);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(49, 13);
this.label12.TabIndex = 16;
this.label12.Text = "LotATC";
//
// con_img_lotATC
//
this.con_img_lotATC.Image = global::Perun_v1.Properties.Resources.status_disconnected;
this.con_img_lotATC.Location = new System.Drawing.Point(292, 335);
this.con_img_lotATC.Name = "con_img_lotATC";
this.con_img_lotATC.Size = new System.Drawing.Size(29, 28);
@@ -397,7 +443,8 @@
//
// con_img_srs
//
this.con_img_srs.Location = new System.Drawing.Point(208, 335);
this.con_img_srs.Image = global::Perun_v1.Properties.Resources.status_disconnected;
this.con_img_srs.Location = new System.Drawing.Point(207, 335);
this.con_img_srs.Name = "con_img_srs";
this.con_img_srs.Size = new System.Drawing.Size(29, 28);
this.con_img_srs.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
@@ -406,7 +453,8 @@
//
// con_img_dcs
//
this.con_img_dcs.Location = new System.Drawing.Point(135, 335);
this.con_img_dcs.Image = global::Perun_v1.Properties.Resources.status_disconnected;
this.con_img_dcs.Location = new System.Drawing.Point(122, 335);
this.con_img_dcs.Name = "con_img_dcs";
this.con_img_dcs.Size = new System.Drawing.Size(29, 28);
this.con_img_dcs.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
@@ -416,49 +464,14 @@
// con_img_db
//
this.con_img_db.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.con_img_db.Location = new System.Drawing.Point(69, 335);
this.con_img_db.Image = global::Perun_v1.Properties.Resources.status_disconnected;
this.con_img_db.Location = new System.Drawing.Point(37, 335);
this.con_img_db.Name = "con_img_db";
this.con_img_db.Size = new System.Drawing.Size(29, 28);
this.con_img_db.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.con_img_db.TabIndex = 10;
this.con_img_db.TabStop = false;
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(15, 335);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(56, 13);
this.label9.TabIndex = 1;
this.label9.Text = "Database:";
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(101, 335);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(38, 13);
this.label10.TabIndex = 14;
this.label10.Text = "Game:";
//
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(170, 335);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(32, 13);
this.label11.TabIndex = 15;
this.label11.Text = "SRS:";
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(243, 335);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(46, 13);
this.label12.TabIndex = 16;
this.label12.Text = "LotATC:";
//
// form_Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@@ -157,8 +157,15 @@ namespace Perun_v1
Globals.intInstanceId= Int32.Parse(con_txt_dcs_instance.Text);
Globals.bStatusIconsForce = true;
// Start listening
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Globals.intInstanceId + " > " + "Opening connections");
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; //no connection
// Start listening
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Globals.intInstanceId + " > " + "Opening connections");
tcpcServer.Create(Int32.Parse(con_txt_dcs_server_port.Text), ref Globals.arrLogHistory, ref arrSendBuffer);
tcpcServer.thrTCPListener = new Thread(tcpcServer.StartListen);
tcpcServer.thrTCPListener.Start();
@@ -209,10 +216,10 @@ namespace Perun_v1
}
form_Main_EnableControls(); // Enable controls
con_img_db.Image = null;
con_img_dcs.Image = null;
con_img_lotATC.Image = null;
con_img_srs.Image = null;
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
con_img_dcs.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");
// Stop timmers
tim_1000ms.Enabled = false;
@@ -232,9 +239,10 @@ namespace Perun_v1
// Set helpers for updates
Globals.bLogHistoryUpdate = false;
Globals.bdcConnection = false;
Globals.btcpcServer = false;
Globals.bTCPServer = false;
Globals.bSRSStatus = false;
Globals.bLotATCStatus = false;
Globals.bClientConnected = false;
}
private void con_lab_github_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
@@ -384,45 +392,70 @@ namespace Perun_v1
if ((dcConnection.bStatus != Globals.bdcConnection) || Globals.bStatusIconsForce) {
if (dcConnection.bStatus)
{
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_db");
if (Globals.intMysqlErros == 0)
{
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected");
} else
{
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_game");
}
} else
{
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_error");
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
}
Globals.bdcConnection = dcConnection.bStatus;
}
if ((tcpcServer.bStatus != Globals.btcpcServer) || Globals.bStatusIconsForce) {
if (tcpcServer.bStatus)
if ((Globals.bClientConnected != Globals.bTCPServer) || Globals.bStatusIconsForce || Globals.intGameErros != Globals.intGameErrosHistory) {
if(Globals.bClientConnected)
{
con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_game");
if (Globals.intGameErros == 0 )
{
con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected");
} else
{
con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_game");
}
}
else
{
con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_error");
con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
}
Globals.btcpcServer = tcpcServer.bStatus;
Globals.bTCPServer = Globals.bClientConnected;
Globals.intGameErrosHistory = Globals.intGameErros;
}
if ((bSRSStatus != Globals.bSRSStatus) || Globals.bStatusIconsForce) {
if (bSRSStatus)
if (bSRSStatus && con_check_3rd_srs.Checked)
{
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_srs");
if (Globals.intSRSErros == 0)
{
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected");
} else
{
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_game");
}
}
else
{;
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_error");
{
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
}
Globals.bSRSStatus = bSRSStatus;
}
if ((bLotATCStatus != Globals.bLotATCStatus) || Globals.bStatusIconsForce)
{
if (bLotATCStatus)
if (bLotATCStatus && con_check_3rd_lotatc.Checked)
{
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_lotatc");
if (Globals.intLotATCErros == 0)
{
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_connected");
} else
{
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_game");
}
}
else
{
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_error");
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected_error");
}
Globals.bLotATCStatus = bLotATCStatus;
}
@@ -490,10 +523,11 @@ namespace Perun_v1
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > SRS data loaded");
bSRSStatus = true;
}
catch
catch (Exception exc_srs)
{
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > SRS data ERROR");
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > SRS data ERROR > " + exc_srs.Message);
bSRSStatus = false;
Globals.intSRSErros++;
}
@@ -517,10 +551,11 @@ namespace Perun_v1
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data loaded");
bLotATCStatus = true;
}
catch
catch(Exception exc_lotatc)
{
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data ERROR");
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data ERROR > " + exc_lotatc.Message);
bLotATCStatus = false;
Globals.intLotATCErros++;
}
@@ -530,7 +565,19 @@ namespace Perun_v1
strLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'true'}}"; // No LotATC controller connected
}
dcConnection.SendToMySql(strLotATCJson);
// 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;
}
private void con_List_Received_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}