Added a "log level" and a "close to tray" settings for the Windows application

This commit is contained in:
David Pierron
2021-02-05 15:01:21 +01:00
parent da2f4345ac
commit a7a45e6fa2
10 changed files with 250 additions and 79 deletions

View File

@@ -34,6 +34,9 @@
this.con_Button_Listen_ON = 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.label15 = new System.Windows.Forms.Label();
this.cboLogLevel = new System.Windows.Forms.ComboBox();
this.con_Button_Add_Marker = new System.Windows.Forms.Button();
this.tim_GUI = new System.Windows.Forms.Timer(this.components);
this.con_GroupBox_2 = new System.Windows.Forms.GroupBox();
this.label6 = new System.Windows.Forms.Label();
@@ -76,8 +79,8 @@
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_Button_Add_Marker = new System.Windows.Forms.Button();
this.TIM_Autostart = new System.Windows.Forms.Timer(this.components);
this.chkCloseToTray = new System.Windows.Forms.CheckBox();
this.con_GroupBox_1.SuspendLayout();
this.con_GroupBox_2.SuspendLayout();
this.con_GroupBox_3.SuspendLayout();
@@ -95,7 +98,7 @@
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(11, 19);
this.con_List_Received.Location = new System.Drawing.Point(8, 44);
this.con_List_Received.Name = "con_List_Received";
this.con_List_Received.Size = new System.Drawing.Size(307, 134);
this.con_List_Received.TabIndex = 0;
@@ -123,14 +126,56 @@
//
// con_GroupBox_1
//
this.con_GroupBox_1.Controls.Add(this.label15);
this.con_GroupBox_1.Controls.Add(this.cboLogLevel);
this.con_GroupBox_1.Controls.Add(this.con_List_Received);
this.con_GroupBox_1.Location = new System.Drawing.Point(12, 434);
this.con_GroupBox_1.Controls.Add(this.con_Button_Add_Marker);
this.con_GroupBox_1.Location = new System.Drawing.Point(12, 412);
this.con_GroupBox_1.Name = "con_GroupBox_1";
this.con_GroupBox_1.Size = new System.Drawing.Size(324, 162);
this.con_GroupBox_1.Size = new System.Drawing.Size(324, 184);
this.con_GroupBox_1.TabIndex = 4;
this.con_GroupBox_1.TabStop = false;
this.con_GroupBox_1.Text = "Data log";
//
// label15
//
this.label15.AutoSize = true;
this.label15.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label15.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label15.Location = new System.Drawing.Point(9, 21);
this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(50, 13);
this.label15.TabIndex = 22;
this.label15.Text = "Log level";
//
// cboLogLevel
//
this.cboLogLevel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboLogLevel.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F);
this.cboLogLevel.FormattingEnabled = true;
this.cboLogLevel.Items.AddRange(new object[] {
"Error",
"Warning",
"Info",
"Debug"});
this.cboLogLevel.Location = new System.Drawing.Point(65, 18);
this.cboLogLevel.Name = "cboLogLevel";
this.cboLogLevel.Size = new System.Drawing.Size(102, 20);
this.cboLogLevel.TabIndex = 23;
this.cboLogLevel.SelectedIndexChanged += new System.EventHandler(this.cboLogLevel_SelectedIndexChanged);
//
// con_Button_Add_Marker
//
this.con_Button_Add_Marker.Enabled = false;
this.con_Button_Add_Marker.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.con_Button_Add_Marker.Location = new System.Drawing.Point(229, 17);
this.con_Button_Add_Marker.Name = "con_Button_Add_Marker";
this.con_Button_Add_Marker.Size = new System.Drawing.Size(86, 20);
this.con_Button_Add_Marker.TabIndex = 21;
this.con_Button_Add_Marker.Text = "Add log marker";
this.con_Button_Add_Marker.UseVisualStyleBackColor = true;
this.con_Button_Add_Marker.Click += new System.EventHandler(this.con_Button_Add_Marker_Click);
//
// tim_GUI
//
this.tim_GUI.Interval = 200;
@@ -394,7 +439,7 @@
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, 396);
this.label9.Location = new System.Drawing.Point(20, 393);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(61, 13);
this.label9.TabIndex = 1;
@@ -405,7 +450,7 @@
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, 396);
this.label10.Location = new System.Drawing.Point(88, 393);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(39, 13);
this.label10.TabIndex = 14;
@@ -416,7 +461,7 @@
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, 396);
this.label11.Location = new System.Drawing.Point(149, 393);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(32, 13);
this.label11.TabIndex = 15;
@@ -427,7 +472,7 @@
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, 396);
this.label12.Location = new System.Drawing.Point(198, 393);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(49, 13);
this.label12.TabIndex = 16;
@@ -437,9 +482,9 @@
//
this.con_Button_Reset_Flags.Enabled = false;
this.con_Button_Reset_Flags.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.con_Button_Reset_Flags.Location = new System.Drawing.Point(224, 414);
this.con_Button_Reset_Flags.Location = new System.Drawing.Point(266, 362);
this.con_Button_Reset_Flags.Name = "con_Button_Reset_Flags";
this.con_Button_Reset_Flags.Size = new System.Drawing.Size(114, 20);
this.con_Button_Reset_Flags.Size = new System.Drawing.Size(61, 36);
this.con_Button_Reset_Flags.TabIndex = 17;
this.con_Button_Reset_Flags.Text = "Reset error flags";
this.con_Button_Reset_Flags.UseVisualStyleBackColor = true;
@@ -478,7 +523,7 @@
//
// con_img_lotATC
//
this.con_img_lotATC.Location = new System.Drawing.Point(292, 362);
this.con_img_lotATC.Location = new System.Drawing.Point(207, 362);
this.con_img_lotATC.Name = "con_img_lotATC";
this.con_img_lotATC.Size = new System.Drawing.Size(29, 28);
this.con_img_lotATC.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
@@ -487,7 +532,7 @@
//
// con_img_srs
//
this.con_img_srs.Location = new System.Drawing.Point(207, 362);
this.con_img_srs.Location = new System.Drawing.Point(150, 362);
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;
@@ -496,7 +541,7 @@
//
// con_img_dcs
//
this.con_img_dcs.Location = new System.Drawing.Point(122, 362);
this.con_img_dcs.Location = new System.Drawing.Point(93, 362);
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;
@@ -506,39 +551,42 @@
// con_img_db
//
this.con_img_db.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.con_img_db.Location = new System.Drawing.Point(37, 362);
this.con_img_db.Location = new System.Drawing.Point(36, 362);
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;
//
// con_Button_Add_Marker
//
this.con_Button_Add_Marker.Enabled = false;
this.con_Button_Add_Marker.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.con_Button_Add_Marker.Location = new System.Drawing.Point(12, 414);
this.con_Button_Add_Marker.Name = "con_Button_Add_Marker";
this.con_Button_Add_Marker.Size = new System.Drawing.Size(114, 20);
this.con_Button_Add_Marker.TabIndex = 21;
this.con_Button_Add_Marker.Text = "Add log marker";
this.con_Button_Add_Marker.UseVisualStyleBackColor = true;
this.con_Button_Add_Marker.Click += new System.EventHandler(this.con_Button_Add_Marker_Click);
//
// TIM_Autostart
//
this.TIM_Autostart.Interval = 500;
this.TIM_Autostart.Tick += new System.EventHandler(this.TIM_Autostart_Tick);
//
// chkCloseToTray
//
this.chkCloseToTray.AutoSize = true;
this.chkCloseToTray.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.chkCloseToTray.Checked = true;
this.chkCloseToTray.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkCloseToTray.Location = new System.Drawing.Point(236, 7);
this.chkCloseToTray.Name = "chkCloseToTray";
this.chkCloseToTray.Size = new System.Drawing.Size(98, 17);
this.chkCloseToTray.TabIndex = 24;
this.chkCloseToTray.Text = "Minimize to tray";
this.chkCloseToTray.UseVisualStyleBackColor = true;
this.chkCloseToTray.Validated += new System.EventHandler(this.chkCloseToTray_Validated);
//
// form_Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(349, 653);
this.Controls.Add(this.con_Button_Add_Marker);
this.ClientSize = new System.Drawing.Size(346, 652);
this.Controls.Add(this.chkCloseToTray);
this.Controls.Add(this.con_Button_Reset_Flags);
this.Controls.Add(this.label14);
this.Controls.Add(this.label13);
this.Controls.Add(this.con_img_logo);
this.Controls.Add(this.con_Button_Reset_Flags);
this.Controls.Add(this.label12);
this.Controls.Add(this.label11);
this.Controls.Add(this.label10);
@@ -565,6 +613,7 @@
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.form_Main_FormClosing);
this.Load += new System.EventHandler(this.form_Main_Load);
this.con_GroupBox_1.ResumeLayout(false);
this.con_GroupBox_1.PerformLayout();
this.con_GroupBox_2.ResumeLayout(false);
this.con_GroupBox_2.PerformLayout();
this.con_GroupBox_3.ResumeLayout(false);
@@ -578,10 +627,7 @@
((System.ComponentModel.ISupportInitialize)(this.con_img_db)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
// TIM_Autostart
//
this.TIM_Autostart.Tick += new System.EventHandler(this.TIM_Autostart_Tick);
//
}
#endregion
@@ -634,6 +680,9 @@
private System.Windows.Forms.Label label14;
private System.Windows.Forms.Button con_Button_Add_Marker;
private System.Windows.Forms.Timer TIM_Autostart;
private System.Windows.Forms.Label label15;
private System.Windows.Forms.ComboBox cboLogLevel;
private System.Windows.Forms.CheckBox chkCloseToTray;
}
}

View File

@@ -54,7 +54,7 @@ namespace Perun_v1
}
}
}
if (args.Length > 3)
{
// Get argument DCS SRS file path
@@ -90,7 +90,7 @@ namespace Perun_v1
if (args[5] != "-1")
{
TIM_Autostart.Enabled = true;
PerunHelper.AddLog(ref Globals.AppLogHistory, "Autostart parameter provided", 0, 1);
PerunHelper.LogInfo(ref Globals.AppLogHistory, "Autostart parameter provided", 0, 1);
}
}
}
@@ -124,6 +124,8 @@ namespace Perun_v1
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_instance.Text = Properties.Settings.Default.DCS_Instance.ToString();
cboLogLevel.SelectedIndex = Properties.Settings.Default.LOG_LEVEL;
chkCloseToTray.Checked = Properties.Settings.Default.CLOSE_TO_TRAY;
}
private void form_Main_SaveSettings()
@@ -142,6 +144,8 @@ namespace Perun_v1
Properties.Settings.Default.OTHER_SRS_USE = con_check_3rd_srs.Checked;
Properties.Settings.Default.DCS_Server_Port = Int32.Parse(con_txt_dcs_server_port.Text);
Properties.Settings.Default.DCS_Instance = Int32.Parse(con_txt_dcs_instance.Text);
Properties.Settings.Default.LOG_LEVEL = cboLogLevel.SelectedIndex;
Properties.Settings.Default.CLOSE_TO_TRAY = chkCloseToTray.Checked;
Properties.Settings.Default.Save();
}
@@ -165,6 +169,7 @@ namespace Perun_v1
con_check_3rd_srs.Enabled = false;
con_txt_dcs_server_port.Enabled = false;
con_txt_dcs_instance.Enabled = false;
cboLogLevel.Enabled = true;
}
private void form_Main_SetControlsToDisconnected()
@@ -186,6 +191,7 @@ namespace Perun_v1
con_check_3rd_srs.Enabled = true;
con_txt_dcs_server_port.Enabled = true;
con_txt_dcs_instance.Enabled = true;
cboLogLevel.Enabled = true;
}
@@ -212,7 +218,7 @@ namespace Perun_v1
DatabaseConnection.DatabaseConnectionString = "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.AddLog(ref Globals.AppLogHistory, "Opening connections", 0, 1);
PerunHelper.LogInfo(ref Globals.AppLogHistory, "Opening connections", 0, 1);
TCPServer.Create(Int32.Parse(con_txt_dcs_server_port.Text), ref Globals.AppLogHistory, ref DatabaseSendBuffer);
TCPServer.thrTCPListener = new Thread(TCPServer.StartListen);
TCPServer.thrTCPListener.Start();
@@ -233,7 +239,7 @@ namespace Perun_v1
{
// Stop listening
// Prepare GUI
PerunHelper.AddLog(ref Globals.AppLogHistory, "Closing connections", 0, 1);
PerunHelper.LogInfo(ref Globals.AppLogHistory, "Closing connections", 0, 1);
con_Button_Listen_OFF.Enabled = false;
Tim_GUI_Tick(null, null);
this.Refresh();
@@ -251,7 +257,7 @@ namespace Perun_v1
}
catch (Exception ex)
{
PerunHelper.AddLog(ref Globals.AppLogHistory, "TCP ERROR, error: " + ex.Message, 2, 1, "?");
PerunHelper.LogError(ref Globals.AppLogHistory, "TCP ERROR, error: " + ex.Message, 2, 1, "?");
Console.WriteLine(ex.ToString());
}
@@ -269,7 +275,7 @@ namespace Perun_v1
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
// Display information about closed connections
PerunHelper.AddLog(ref Globals.AppLogHistory, "Connections closed", 0, 1);
PerunHelper.LogInfo(ref Globals.AppLogHistory, "Connections closed", 0, 1);
Tim_GUI_Tick(null, null);
// Set title bar
@@ -374,7 +380,13 @@ namespace Perun_v1
if (e.CloseReason == CloseReason.UserClosing && !AppCanClose)
{
e.Cancel = true;
form_Main_SendToTray(); // Send app to system tray
if (Properties.Settings.Default.CLOSE_TO_TRAY)
{
form_Main_SendToTray(); // Send app to system tray
} else
{
con_Button_Quit_Click(sender, e);
}
}
}
@@ -558,12 +570,12 @@ namespace Perun_v1
ExtSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + ExtSRSJson + "'}";
ExtSRSUseDefault = false;
PerunHelper.AddLog(ref Globals.AppLogHistory, "SRS data loaded", 3, 0, "100", true);
PerunHelper.LogInfo(ref Globals.AppLogHistory, "SRS data loaded", 3, 0, "100", true);
ExtSRSStatus = true;
}
catch (Exception exc_srs)
{
PerunHelper.AddLog(ref Globals.AppLogHistory, "SRS data ERROR , error: " + exc_srs.Message, 3, 1, "100");
PerunHelper.LogError(ref Globals.AppLogHistory, "SRS data ERROR , error: " + exc_srs.Message, 3, 1, "100");
ExtSRSStatus = false;
Globals.ErrorsSRS++;
}
@@ -592,12 +604,12 @@ namespace Perun_v1
ExtLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':'" + ExtLotATCJson + "'}";
ExtLotATCUseDefault = false;
PerunHelper.AddLog(ref Globals.AppLogHistory, "LotATC data loaded", 3, 0, "101", true);
PerunHelper.LogInfo(ref Globals.AppLogHistory, "LotATC data loaded", 3, 0, "101", true);
ExtLotATCStatus = true;
}
catch (Exception exc_lotatc)
{
PerunHelper.AddLog(ref Globals.AppLogHistory, "LotATC data ERROR, error: " + exc_lotatc.Message, 3, 1, "101");
PerunHelper.LogError(ref Globals.AppLogHistory, "LotATC data ERROR, error: " + exc_lotatc.Message, 3, 1, "101");
ExtLotATCStatus = false;
Globals.ErrorsLotATC++;
}
@@ -639,7 +651,7 @@ namespace Perun_v1
Globals.AppForceIconReload = true;
// Add information
PerunHelper.AddLog(ref Globals.AppLogHistory, "Resetted error counter", 0, 1);
PerunHelper.LogInfo(ref Globals.AppLogHistory, "Resetted error counter", 0, 1);
}
else if (dialogResult == DialogResult.No)
{
@@ -651,7 +663,7 @@ namespace Perun_v1
private void con_Button_Add_Marker_Click(object sender, EventArgs e)
{
// Added user marker
PerunHelper.AddLog(ref Globals.AppLogHistory, "User Marker", 0, 1);
PerunHelper.LogInfo(ref Globals.AppLogHistory, "User Marker", 0, 1);
}
private void TIM_Autostart_Tick(object sender, EventArgs e)
@@ -660,5 +672,15 @@ namespace Perun_v1
TIM_Autostart.Enabled = false; // Disable timer
con_Button_Listen_ON_Click(sender,e); // Simulate button click
}
private void cboLogLevel_SelectedIndexChanged(object sender, EventArgs e)
{
LogController.instance.level = cboLogLevel.SelectedIndex;
}
private void chkCloseToTray_Validated(object sender, EventArgs e)
{
Properties.Settings.Default.CLOSE_TO_TRAY = chkCloseToTray.Checked;
}
}
}