refactor(gui,api,logging): UI layout tweaks, cleanup, and improved diagnostics
- CbBxCamType now spans the full width of CbBxCameraModel - BtnTest_Click moved to the bottom of AiQ_GUI.cs for easier testing/navigation - Unused using directives removed across files - Login credentials factored out and reused in MobileAPI.cs - VLC.cs Capture function reviewed and superseded by TakeSnapshot - InsertCamTab implementation updated to avoid use of `var` - Misleading '// Non-ONVIF cameras' comment corrected - Added Level.Debug logging, accessible only to developers, for detailed diagnostics
This commit is contained in:
@@ -1,10 +1,4 @@
|
|||||||
using Renci.SshNet.Common;
|
namespace AiQ_GUI.AiQ_Tests
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace AiQ_GUI.AiQ_Tests
|
|
||||||
{
|
{
|
||||||
|
|
||||||
public class TestingFunctions
|
public class TestingFunctions
|
||||||
|
|||||||
2
AiQ_GUI.Designer.cs
generated
2
AiQ_GUI.Designer.cs
generated
@@ -1932,7 +1932,7 @@ namespace AiQ_GUI
|
|||||||
CbBxCamType.Margin = new Padding(4, 3, 4, 3);
|
CbBxCamType.Margin = new Padding(4, 3, 4, 3);
|
||||||
CbBxCamType.MaxDropDownItems = 20;
|
CbBxCamType.MaxDropDownItems = 20;
|
||||||
CbBxCamType.Name = "CbBxCamType";
|
CbBxCamType.Name = "CbBxCamType";
|
||||||
CbBxCamType.Size = new Size(233, 25);
|
CbBxCamType.Size = new Size(254, 25);
|
||||||
CbBxCamType.TabIndex = 241;
|
CbBxCamType.TabIndex = 241;
|
||||||
CbBxCamType.SelectedIndexChanged += CbBxCamType_SelectedIndexChanged;
|
CbBxCamType.SelectedIndexChanged += CbBxCamType_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
|
|||||||
112
AiQ_GUI.cs
112
AiQ_GUI.cs
@@ -1,16 +1,10 @@
|
|||||||
using AiQ_GUI.AiQ_Tests;
|
using AiQ_GUI.AiQ_Tests;
|
||||||
using AiQ_GUI.Mobile_Tests;
|
using AiQ_GUI.Mobile_Tests;
|
||||||
using DocumentFormat.OpenXml.Drawing.Diagrams;
|
|
||||||
using LibVLCSharp.Shared;
|
using LibVLCSharp.Shared;
|
||||||
using LibVLCSharp.WinForms;
|
|
||||||
using MigraDoc.DocumentObjectModel;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net.Http.Json;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using Color = System.Drawing.Color;
|
using Color = System.Drawing.Color;
|
||||||
|
|
||||||
namespace AiQ_GUI
|
namespace AiQ_GUI
|
||||||
@@ -20,7 +14,8 @@ namespace AiQ_GUI
|
|||||||
ERROR,
|
ERROR,
|
||||||
WARNING,
|
WARNING,
|
||||||
LOG,
|
LOG,
|
||||||
Success
|
Success,
|
||||||
|
DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class MainForm : Form
|
public partial class MainForm : Form
|
||||||
@@ -112,7 +107,6 @@ namespace AiQ_GUI
|
|||||||
await CheckHWOnline;
|
await CheckHWOnline;
|
||||||
Flags.Start = false;
|
Flags.Start = false;
|
||||||
CbBxCamType.Text = "AiQ"; // Default to AiQ cameras
|
CbBxCamType.Text = "AiQ"; // Default to AiQ cameras
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,11 +115,11 @@ namespace AiQ_GUI
|
|||||||
// Remove previous tabs
|
// Remove previous tabs
|
||||||
if (CurrentTabs != null)
|
if (CurrentTabs != null)
|
||||||
{
|
{
|
||||||
foreach (var tab in CurrentTabs)
|
foreach (TabPage tab in CurrentTabs)
|
||||||
TabImagesandSettings.TabPages.Remove(tab);
|
TabImagesandSettings.TabPages.Remove(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
var tabsToInsert = new List<TabPage>();
|
List<TabPage> tabsToInsert = new List<TabPage>();
|
||||||
|
|
||||||
if (camType == "Mobile")
|
if (camType == "Mobile")
|
||||||
tabsToInsert.AddRange([Video, Mobile]);
|
tabsToInsert.AddRange([Video, Mobile]);
|
||||||
@@ -134,7 +128,7 @@ namespace AiQ_GUI
|
|||||||
|
|
||||||
int idx = Math.Min(3, TabImagesandSettings.TabPages.Count);
|
int idx = Math.Min(3, TabImagesandSettings.TabPages.Count);
|
||||||
|
|
||||||
foreach (var tab in tabsToInsert)
|
foreach (TabPage tab in tabsToInsert)
|
||||||
{
|
{
|
||||||
if (!TabImagesandSettings.TabPages.Contains(tab))
|
if (!TabImagesandSettings.TabPages.Contains(tab))
|
||||||
TabImagesandSettings.TabPages.Insert(idx++, tab);
|
TabImagesandSettings.TabPages.Insert(idx++, tab);
|
||||||
@@ -563,7 +557,7 @@ namespace AiQ_GUI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Non-ONVIF cameras
|
// AiQ cameras
|
||||||
if (!await Network.PingIP(ipOnly))
|
if (!await Network.PingIP(ipOnly))
|
||||||
{
|
{
|
||||||
CbBxFoundCams.BackColor = Color.Red;
|
CbBxFoundCams.BackColor = Color.Red;
|
||||||
@@ -660,31 +654,37 @@ namespace AiQ_GUI
|
|||||||
// ***** Helper functions *****
|
// ***** Helper functions *****
|
||||||
public void AddToActionsList(string Mssg, Level Lvl = Level.LOG)
|
public void AddToActionsList(string Mssg, Level Lvl = Level.LOG)
|
||||||
{
|
{
|
||||||
if (Lvl == Level.ERROR)
|
// DEBUG messages only visible to Bradley
|
||||||
{
|
if (Lvl == Level.DEBUG && CbBxUserName.Text != "Bradley")
|
||||||
Logging.LogErrorMessage(Mssg);
|
return;
|
||||||
RhTxBxActions.SelectionColor = Color.IndianRed;
|
|
||||||
}
|
|
||||||
else if (Lvl == Level.WARNING)
|
|
||||||
{
|
|
||||||
Logging.LogWarningMessage(Mssg);
|
|
||||||
RhTxBxActions.SelectionColor = Color.Orange;
|
|
||||||
}
|
|
||||||
else if (Lvl == Level.LOG)
|
|
||||||
{
|
|
||||||
Logging.LogMessage(Mssg);
|
|
||||||
RhTxBxActions.SelectionColor = Color.White;
|
|
||||||
}
|
|
||||||
else if (Lvl == Level.Success)
|
|
||||||
{
|
|
||||||
Logging.LogMessage(Mssg);
|
|
||||||
RhTxBxActions.SelectionColor = Color.LightGreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
RhTxBxActions.AppendText(Mssg + Environment.NewLine);
|
if (Lvl == Level.ERROR)
|
||||||
RhTxBxActions.SelectionStart = RhTxBxActions.Text.Length;
|
Logging.LogErrorMessage(Mssg);
|
||||||
RhTxBxActions.SelectionColor = SystemColors.Control;
|
|
||||||
RhTxBxActions.ScrollToCaret();
|
else if (Lvl == Level.WARNING)
|
||||||
|
Logging.LogWarningMessage(Mssg);
|
||||||
|
|
||||||
|
else if (Lvl == Level.DEBUG)
|
||||||
|
Logging.LogMessage("[DEBUG]" + Mssg);
|
||||||
|
|
||||||
|
else
|
||||||
|
Logging.LogMessage(Mssg);
|
||||||
|
|
||||||
|
RhTxBxActions.SelectionColor = Lvl switch
|
||||||
|
{
|
||||||
|
Level.ERROR => Color.IndianRed,
|
||||||
|
Level.WARNING => Color.Orange,
|
||||||
|
Level.DEBUG => Color.LightBlue,
|
||||||
|
Level.Success => Color.LightGreen,
|
||||||
|
_ => Color.White
|
||||||
|
};
|
||||||
|
if (Lvl == Level.DEBUG)
|
||||||
|
RhTxBxActions.AppendText("[DEBUG] " + Mssg + Environment.NewLine);
|
||||||
|
else
|
||||||
|
RhTxBxActions.AppendText(Mssg + Environment.NewLine);
|
||||||
|
RhTxBxActions.SelectionStart = RhTxBxActions.Text.Length;
|
||||||
|
RhTxBxActions.SelectionColor = SystemColors.Control;
|
||||||
|
RhTxBxActions.ScrollToCaret();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1444,26 +1444,7 @@ namespace AiQ_GUI
|
|||||||
}
|
}
|
||||||
BtnFactoryDefault.BackColor = Color.Green;
|
BtnFactoryDefault.BackColor = Color.Green;
|
||||||
}
|
}
|
||||||
|
public static Label MakeNewLabel(string text, bool isRed, int yLoc)
|
||||||
// ***** Test & Debug *****
|
|
||||||
private async void BtnTest_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Stopwatch stopWatchTest = Stopwatch.StartNew();
|
|
||||||
|
|
||||||
//StatsExcel excelExporter = new();
|
|
||||||
//excelExporter.ExportDatabaseToExcel();
|
|
||||||
//await MobileTests.CheckFirmwareAsync();
|
|
||||||
//FlexiAPI.GetVersions(CamOnTest.IP).Wait();
|
|
||||||
//VLC.Play(VidView);
|
|
||||||
//await Task.Delay(5000);
|
|
||||||
//VLC.TakeSnapshot(VidView);
|
|
||||||
SSH.MobiletxtCheck("100.118.196.113");
|
|
||||||
|
|
||||||
// await MobileAPI.SetDayModeAsync();
|
|
||||||
|
|
||||||
AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"), Level.LOG);
|
|
||||||
}
|
|
||||||
public static Label MakeNewLabel(string text, bool isRed, int yLoc)
|
|
||||||
{
|
{
|
||||||
return new Label
|
return new Label
|
||||||
{
|
{
|
||||||
@@ -1504,6 +1485,25 @@ namespace AiQ_GUI
|
|||||||
VLC.Play(VidView);
|
VLC.Play(VidView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ***** Test & Debug *****
|
||||||
|
private async void BtnTest_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Stopwatch stopWatchTest = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
//StatsExcel excelExporter = new();
|
||||||
|
//excelExporter.ExportDatabaseToExcel();
|
||||||
|
//await MobileTests.CheckFirmwareAsync();
|
||||||
|
//FlexiAPI.GetVersions(CamOnTest.IP).Wait();
|
||||||
|
//VLC.Play(VidView);
|
||||||
|
//await Task.Delay(5000);
|
||||||
|
//VLC.TakeSnapshot(VidView);
|
||||||
|
SSH.MobiletxtCheck("100.118.196.113");
|
||||||
|
|
||||||
|
// await MobileAPI.SetDayModeAsync();
|
||||||
|
|
||||||
|
AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"), Level.DEBUG);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,9 +123,6 @@
|
|||||||
<metadata name="ToolTipClipboard.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="ToolTipClipboard.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>159, 17</value>
|
<value>159, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="ToolTipAvailable.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>17, 17</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="TimerDDC.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="TimerDDC.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>531, 18</value>
|
<value>531, 18</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ namespace AiQ_GUI.Mobile_Tests
|
|||||||
{
|
{
|
||||||
public static class MobileAPI
|
public static class MobileAPI
|
||||||
{
|
{
|
||||||
|
// Login credentials
|
||||||
|
private const string DefaultUsername = "ADMIN";
|
||||||
|
private const string DefaultPassword = "1234";
|
||||||
|
|
||||||
public static async Task CheckFirmwareAsync()
|
public static async Task CheckFirmwareAsync()
|
||||||
{
|
{
|
||||||
using HttpClient client = new HttpClient
|
using HttpClient client = new HttpClient
|
||||||
@@ -21,7 +25,7 @@ namespace AiQ_GUI.Mobile_Tests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Login and get JWT token
|
// Login and get JWT token
|
||||||
string token = await LoginAsync(client, "ADMIN", "1234");
|
string token = await LoginAsync(client, DefaultUsername, DefaultPassword);
|
||||||
|
|
||||||
// Attach JWT to all requests
|
// Attach JWT to all requests
|
||||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||||
@@ -87,7 +91,7 @@ namespace AiQ_GUI.Mobile_Tests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Login
|
// Login
|
||||||
string token = await LoginAsync(client, "ADMIN", "1234");
|
string token = await LoginAsync(client, DefaultUsername, DefaultPassword);
|
||||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||||
|
|
||||||
var payload = new
|
var payload = new
|
||||||
@@ -40,11 +40,4 @@ internal class VLC
|
|||||||
{
|
{
|
||||||
VLCVV.MediaPlayer.Stop();
|
VLCVV.MediaPlayer.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Capture(VideoView VLCVV)
|
|
||||||
{
|
|
||||||
var media = new Media(libVLC, $"rtsp://ADMIN:1234@{MainForm.Instance.CamOnTest.IP}:554/live/main", FromType.FromLocation);
|
|
||||||
media.AddOption(":rtsp-tcp");
|
|
||||||
VLCVV.MediaPlayer.Play(media);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ namespace AiQ_GUI
|
|||||||
byte[] discoveryPacket =
|
byte[] discoveryPacket =
|
||||||
[
|
[
|
||||||
0x50, 0x4f, 0x4c, 0x4c, 0xaf, 0xb0, 0xb3, 0xb3,
|
0x50, 0x4f, 0x4c, 0x4c, 0xaf, 0xb0, 0xb3, 0xb3,
|
||||||
0xb6, 0x01, 0xa8, 0xc0, 0x0b, 0x1a, 0x00, 0x00
|
0xb6, 0x01, 0xa8, 0xc0, 0x0b, 0x1a, 0x00, 0x00
|
||||||
];
|
];
|
||||||
|
|
||||||
async Task SendAndListen(IPAddress localIp)
|
async Task SendAndListen(IPAddress localIp)
|
||||||
|
|||||||
Reference in New Issue
Block a user