• MobileTests.cs

- Pre test now checks firmware and adds the label dynamically to the panel

• AiQ_GUI.Designer.cs
  - Added CbBxCameraModel.SelectedIndexChanged to properly wire UI element.

• Microsoft/StatsExcel.cs
  - Improved workbook loading error handling to distinguish between corruption and file access issues.
This commit is contained in:
2026-01-09 15:49:54 +00:00
parent 693da58fcb
commit 90b3f7caff
6 changed files with 97 additions and 85 deletions

13
AiQ Tests/AiQLiteTests.cs Normal file
View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace AiQ_GUI.AiQ_Tests
{
internal class AiQLiteTests
{
// Tests to be written here later
}
}

View File

@@ -110,13 +110,23 @@ namespace AiQ_GUI.AiQ_Tests
bool modelIsRed = !RegexCache.ModelRegex().IsMatch(DiagsAPI.modelNumber); bool modelIsRed = !RegexCache.ModelRegex().IsMatch(DiagsAPI.modelNumber);
MainForm.Instance.AddLabelToPanel(modelText, modelIsRed); MainForm.Instance.AddLabelToPanel(modelText, modelIsRed);
string apiModel = DiagsAPI.modelNumber?.Trim();
string selectedModel = MainForm.Instance.CamOnTest.Model?.Trim();
if (string.IsNullOrWhiteSpace(selectedModel) && MainForm.Instance.CbBxCameraModel.SelectedItem != null)
selectedModel = MainForm.Instance.CbBxCameraModel.SelectedItem.ToString().Split('-')[0].Trim();
if (RegexCache.SerialRegex().IsMatch(DiagsAPI.serialNumber) && RegexCache.ModelRegex().IsMatch(DiagsAPI.modelNumber)) if (RegexCache.SerialRegex().IsMatch(DiagsAPI.serialNumber) && RegexCache.ModelRegex().IsMatch(DiagsAPI.modelNumber))
{ {
if (DiagsAPI.modelNumber != MainForm.Instance.CamOnTest.Model) // If nothing selected yet, do not warn (matches old logic)
if (!string.IsNullOrWhiteSpace(selectedModel)
&& !string.Equals(apiModel, selectedModel, StringComparison.OrdinalIgnoreCase))
{ {
MainForm.Instance.AddToActionsList("Model number in camera doesn't match what has been selected", Level.WARNING); MainForm.Instance.AddToActionsList(
"Model number in camera doesn't match what has been selected",
Level.WARNING);
} }
else if (!GoogleAPI.CheckWIP(DiagsAPI.serialNumber, CameraAccessInfo.SpreadsheetID)) // Check WIP column in serial number register, if not ticked then RMA else if (!string.IsNullOrWhiteSpace(CameraAccessInfo.SpreadsheetID)&& !GoogleAPI.CheckWIP(DiagsAPI.serialNumber, CameraAccessInfo.SpreadsheetID)) // Check WIP column in serial number register, if not ticked then RMA
{ {
MainForm.Instance.CamOnTest.RMANum = GoogleAPI.CheckRMANum(DiagsAPI.serialNumber, DiagsAPI.modelNumber); // Corrected by qualifying with the type name MainForm.Instance.CamOnTest.RMANum = GoogleAPI.CheckRMANum(DiagsAPI.serialNumber, DiagsAPI.modelNumber); // Corrected by qualifying with the type name
@@ -127,7 +137,6 @@ namespace AiQ_GUI.AiQ_Tests
if (MainForm.Instance.CamOnTest.RMANum == -1) // Means they chose the 'I don't know' option if (MainForm.Instance.CamOnTest.RMANum == -1) // Means they chose the 'I don't know' option
await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Please get RMA number from operations team before continuing"); await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Please get RMA number from operations team before continuing");
} }
// Found RMA num and want to verify it with user
else if (!await MainForm.Instance.DisplayQuestion($"Is {MainForm.Instance.CamOnTest.RMANum} the RMA Number?")) // '!' because if its not the right RMA number let the user to it manually else if (!await MainForm.Instance.DisplayQuestion($"Is {MainForm.Instance.CamOnTest.RMANum} the RMA Number?")) // '!' because if its not the right RMA number let the user to it manually
{ {
MainForm.Instance.CamOnTest.RMANum = Convert.ToInt32(await MainForm.Instance.DisplayInput("What is the RMA number?")); MainForm.Instance.CamOnTest.RMANum = Convert.ToInt32(await MainForm.Instance.DisplayInput("What is the RMA number?"));
@@ -139,7 +148,9 @@ namespace AiQ_GUI.AiQ_Tests
} }
else else
{ {
MainForm.Instance.AddToActionsList("Camera has not been given a valid serial and model number, suggest you run through pre test again and check serial number register for any issues.", Level.ERROR); MainForm.Instance.AddToActionsList(
"Camera has not been given a valid serial and model number, suggest you run through pre test again and check serial number register for any issues.",
Level.ERROR);
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -148,45 +159,36 @@ namespace AiQ_GUI.AiQ_Tests
} }
// Check licenses // Check licenses
List<string> licensesOnCam = []; // Temporary list for licenses on camera List<string> licensesOnCam = new List<string>(); // Temporary list for licenses on camera
if (DiagsAPI.licenses.saf1) if (DiagsAPI.licenses.saf1) licensesOnCam.Add("SAF1");
licensesOnCam.Add("SAF1"); if (DiagsAPI.licenses.saf2) licensesOnCam.Add("SAF2");
if (DiagsAPI.licenses.saf2) if (DiagsAPI.licenses.saf3) licensesOnCam.Add("SAF3");
licensesOnCam.Add("SAF2"); if (DiagsAPI.licenses.saf4) licensesOnCam.Add("SAF4");
if (DiagsAPI.licenses.saf3) if (DiagsAPI.licenses.audit) licensesOnCam.Add("Audit");
licensesOnCam.Add("SAF3"); if (DiagsAPI.licenses.stream) licensesOnCam.Add("Stream");
if (DiagsAPI.licenses.saf4) if (MainForm.Instance.sshData != null && MainForm.Instance.sshData.tailscale) licensesOnCam.Add("Tailscale");
licensesOnCam.Add("SAF4");
if (DiagsAPI.licenses.audit)
licensesOnCam.Add("Audit");
if (DiagsAPI.licenses.stream)
licensesOnCam.Add("Stream");
if (MainForm.Instance.sshData != null && MainForm.Instance.sshData.tailscale)
licensesOnCam.Add("Tailscale");
string licText = "Licenses = " + (licensesOnCam.Count == 0 ? "None" : string.Join(", ", licensesOnCam)); MainForm.Instance.AddLabelToPanel(
MainForm.Instance.AddLabelToPanel(licText, false); "Licenses = " + (licensesOnCam.Count == 0 ? "None" : string.Join(", ", licensesOnCam)),
false);
double CPUround = Math.Round(DiagsAPI.CPUusage); // Check CPU usage isn't near max double CPUround = Math.Round(DiagsAPI.CPUusage); // Check CPU usage isn't near max
string cpuText = "CPU Usage = " + CPUround + "%"; MainForm.Instance.AddLabelToPanel(
bool cpuIsRed = CPUround <= 50 || CPUround >= 98; "CPU Usage = " + CPUround + "%",
MainForm.Instance.AddLabelToPanel(cpuText, cpuIsRed); CPUround <= 50 || CPUround >= 98);
// Check Vaxtor if it doesn't need or have license OR has and wants one then pass // Check Vaxtor license
bool vaxtorIsRed = false; bool vaxtorIsRed = false;
string vaxtorText = "Vaxtor Key ID = " + DiagsAPI.licenses.raptorKeyID; string vaxtorText = "Vaxtor Key ID = " + DiagsAPI.licenses.raptorKeyID;
if (CameraAccessInfo.VaxtorLic == false && DiagsAPI.licenses.raptorKeyID == "Not Licensed" || CameraAccessInfo.VaxtorLic == true && DiagsAPI.licenses.raptorKeyID != "Not Licensed") if (DiagsAPI.licenses.raptorKeyID != "Not Licensed") vaxtorIsRed = false;
{ else if (CameraAccessInfo.VaxtorLic == false) vaxtorIsRed = false;
// OK - passes condition
vaxtorIsRed = false;
}
else if (await MainForm.Instance.DisplayQuestion("Was this camera licensed manually?")) else if (await MainForm.Instance.DisplayQuestion("Was this camera licensed manually?"))
{ {
string ProdcutKeyID = await MainForm.Instance.DisplayInput("What is the Key ID?", false); string ProdcutKeyID = await MainForm.Instance.DisplayInput("What is the Key ID?", false);
if (RegexCache.VaxtorRegex().IsMatch(ProdcutKeyID)) // Valid Key ID if (RegexCache.VaxtorRegex().IsMatch(ProdcutKeyID))
{ {
Access.Stats("Please Get A Valid Vaxtor Product Key Before Continuing", MainForm.Instance.CamOnTest.Model); Access.Stats("Please Get A Valid Vaxtor Product Key Before Continuing", MainForm.Instance.CamOnTest.Model);
await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Please get a valid Vaxtor Product Key before continuing"); await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Please get a valid Vaxtor Product Key before continuing");
@@ -196,22 +198,17 @@ namespace AiQ_GUI.AiQ_Tests
vaxtorText = "Vaxtor Key ID = " + DiagsAPI.licenses.raptorKeyID; vaxtorText = "Vaxtor Key ID = " + DiagsAPI.licenses.raptorKeyID;
vaxtorIsRed = false; vaxtorIsRed = false;
} }
else // Should have license but doesn't OR shouldn't have but does + any other unforeseen circumstance then fail else vaxtorIsRed = true;
{
vaxtorIsRed = true;
}
MainForm.Instance.AddLabelToPanel(vaxtorText, vaxtorIsRed); MainForm.Instance.AddLabelToPanel(vaxtorText, vaxtorIsRed);
// Check trim is within 10% both horizontally and vertically, from auto set done earlier in the test // Check trim is within 10% both horizontally and vertically
string trimText = "Trim = H: " + DiagsAPI.trim[0] + " V: " + DiagsAPI.trim[1];
// Offset accounted for in the SetTrim function, so value should be close to 0,0.
const int HMax = 96; // 5% of 1920 each way = ±96 const int HMax = 96; // 5% of 1920 each way = ±96
const int VMax = 54; // 5% of 1080 each way = ±54 const int VMax = 54; // 5% of 1080 each way = ±54
bool trimIsRed = Math.Abs(DiagsAPI.trim[0]) > HMax || Math.Abs(DiagsAPI.trim[1]) > VMax; MainForm.Instance.AddLabelToPanel(
MainForm.Instance.AddLabelToPanel(trimText, trimIsRed); "Trim = H: " + DiagsAPI.trim[0] + " V: " + DiagsAPI.trim[1],
Math.Abs(DiagsAPI.trim[0]) > HMax || Math.Abs(DiagsAPI.trim[1]) > VMax);
} }
} }
} }

3
AiQ_GUI.Designer.cs generated
View File

@@ -182,7 +182,7 @@ namespace AiQ_GUI
CbBxCameraModel.Name = "CbBxCameraModel"; CbBxCameraModel.Name = "CbBxCameraModel";
CbBxCameraModel.Size = new Size(494, 25); CbBxCameraModel.Size = new Size(494, 25);
CbBxCameraModel.TabIndex = 188; CbBxCameraModel.TabIndex = 188;
CbBxCameraModel.SelectedIndexChanged += CbBxCamTypSelectedIndexChanged; CbBxCameraModel.SelectedIndexChanged += CbBxCameraModel_SelectedIndexChanged;
// //
// BtnStartTest // BtnStartTest
// //
@@ -1815,7 +1815,6 @@ namespace AiQ_GUI
CbBxCamType.Name = "CbBxCamType"; CbBxCamType.Name = "CbBxCamType";
CbBxCamType.Size = new Size(233, 25); CbBxCamType.Size = new Size(233, 25);
CbBxCamType.TabIndex = 241; CbBxCamType.TabIndex = 241;
CbBxCamType.Text = "AiQ";
CbBxCamType.SelectedIndexChanged += CbBxCamType_SelectedIndexChanged; CbBxCamType.SelectedIndexChanged += CbBxCamType_SelectedIndexChanged;
// //
// MainForm // MainForm

View File

@@ -99,6 +99,7 @@ namespace AiQ_GUI
await CheckHWOnline; await CheckHWOnline;
Flags.Start = false; Flags.Start = false;
CbBxCamType.Text = "AiQ"; // Default to AiQ cameras
} }
@@ -139,7 +140,6 @@ namespace AiQ_GUI
CbBxCameraModel.Items.AddRange(models); CbBxCameraModel.Items.AddRange(models);
} }
private void PopulateUIWithLDS(LocalDataStore lds) private void PopulateUIWithLDS(LocalDataStore lds)
{ {
CbBxUserName.Text = lds.User; CbBxUserName.Text = lds.User;
@@ -202,7 +202,7 @@ namespace AiQ_GUI
} }
else if (CbBxCamType.Text == "Mobile") else if (CbBxCamType.Text == "Mobile")
{ {
await MobilePreTest.RunPreTestAsync();
await PreTestPassed(); await PreTestPassed();
} }
} }
@@ -672,7 +672,7 @@ namespace AiQ_GUI
} }
private void CbBxCamTypSelectedIndexChanged(object sender, EventArgs e) private void CbBxCameraModel_SelectedIndexChanged(object sender, EventArgs e)
{ {
TestStartConditions(); TestStartConditions();
} }
@@ -1434,34 +1434,9 @@ namespace AiQ_GUI
{ {
Stopwatch stopWatchTest = Stopwatch.StartNew(); Stopwatch stopWatchTest = Stopwatch.StartNew();
//StatsExcel excelExporter = new();
await MobilePreTest.CheckFirmwareAsync(); //excelExporter.ExportDatabaseToExcel();
//AddLabelToPanel("Test Complete", false); //await MobilePreTest.CheckFirmwareAsync();
//FakeCamera fakeCamera = new FakeCamera(80); // Create an instance of FakeCamera
//CamOnTest.IP = CbBxFoundCams.Text;
//_ = fakeCamera.StartAsync(CAMTYPE.GOOD).ContinueWith(task =>
//{
// //Network.Initialize("developer", "Pass123");
// if (task.IsFaulted)
// {
// AddToActionsList("Error starting FakeCamera: " + task.Exception?.Message);
// }
// else
// {
// AddToActionsList($"FakeCamera started successfully. IP: {fakeCamera}");
// }
//});
//await Task.Delay(3000); // Wait for server to start
//CbBxFoundCams.Text = "localhost"; // Should force update in creds an network reinit
//CmBoFoundCams_TextChanged(sender, e);
//CbBxCameraModel.SelectedIndex = CbBxCameraModel.Items.Count - 1; // Selects AB12CD as model number
//await Task.Delay(3000); // Wait for server to start
//BtnStartTest_Click(sender, e);
AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"), Level.LOG); AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"), Level.LOG);
} }

View File

@@ -40,7 +40,7 @@ namespace AiQ_GUI
const string selectColumns = @" const string selectColumns = @"
ModelNumber, ModelNumber,
[Total Tests Run], [Total Tests Run],
[Pre Tests Passed] [Pre Tests Passed],
[Pre Tests Failed], [Pre Tests Failed],
[Final Tests Passed], [Final Tests Passed],
[Final Tests Failed], [Final Tests Failed],
@@ -84,8 +84,28 @@ namespace AiQ_GUI
XLWorkbook workbook; XLWorkbook workbook;
if (File.Exists(exportPath)) if (File.Exists(exportPath))
{ {
workbook = new XLWorkbook(exportPath); try
MainForm.Instance.AddToActionsList("Opened existing workbook."); {
workbook = new XLWorkbook(exportPath);
MainForm.Instance.AddToActionsList("Opened existing workbook.");
}
catch (Exception loadEx)
{
// Workbook is corrupted, backup the old file and create a new one
string backupPath = exportPath + ".corrupted_" + DateTime.Now.ToString("yyyyMMdd_HHmmss");
try
{
File.Move(exportPath, backupPath, overwrite: true);
MainForm.Instance.AddToActionsList($"WARNING: Existing workbook was corrupted. Backed up to: {backupPath}");
}
catch (Exception backupEx)
{
MainForm.Instance.AddToActionsList($"WARNING: Could not backup corrupted workbook. Details: {backupEx.Message}");
}
workbook = new XLWorkbook();
MainForm.Instance.AddToActionsList("Created new workbook (previous file was corrupted).");
}
} }
else else
{ {

View File

@@ -1,21 +1,23 @@
using AiQ_GUI; using AiQ_GUI;
using System; using System;
using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Json; using System.Net.Http.Json;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
public static class MobilePreTest public static class MobilePreTest
{ {
public static async Task CheckFirmwareAsync() public static async Task CheckFirmwareAsync()
{ {
const string cameraIp = "192.168.0.112";
using HttpClient client = new HttpClient using HttpClient client = new HttpClient
{ {
BaseAddress = new Uri($"http://{cameraIp}") BaseAddress = new Uri($"http://{MainForm.Instance.CamOnTest.IP}")
}; };
try try
@@ -31,32 +33,32 @@ public static class MobilePreTest
string body = await response.Content.ReadAsStringAsync(); string body = await response.Content.ReadAsStringAsync();
MainForm.Instance.AddToActionsList($"Firmware check response: {(int)response.StatusCode} {response.StatusCode} | {body}",Level.LOG);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
JsonElement json = JsonSerializer.Deserialize<JsonElement>(body); JsonElement json = JsonSerializer.Deserialize<JsonElement>(body);
string version = json.GetProperty("version").GetString()?.Trim(); string version = json.GetProperty("version").GetString()?.Trim();
// Compare against expected SRZFirmware from UniversalData // Compare against expected SRZFirmware from UniversalData
if (string.IsNullOrEmpty(UniversalData.SRZFirmware)) if (string.IsNullOrEmpty(UniversalData.SRZFirmware))
{ {
MainForm.Instance.AddToActionsList($"Firmware check failed: Expected SRZFirmware not loaded in UniversalData",Level.ERROR); MainForm.Instance.AddToActionsList($"Firmware check failed: Expected SRZFirmware not loaded in UniversalData",Level.ERROR);
MainForm.Instance.AddLabelToPanel($"Firmware = {version}", true);
} }
else if (version == UniversalData.SRZFirmware) else if (version == UniversalData.SRZFirmware)
{ {
MainForm.Instance.AddToActionsList($"Firmware match successful: {version}",Level.Success); MainForm.Instance.AddLabelToPanel($"Firmware = {version}", false);
} }
else else
{ {
MainForm.Instance.AddToActionsList($"Firmware mismatch: Camera has {version}, expected {UniversalData.SRZFirmware}",Level.ERROR); MainForm.Instance.AddLabelToPanel($"Firmware = {version}", true);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
MainForm.Instance.AddToActionsList($"Firmware check failed: {ex.Message}",Level.ERROR); MainForm.Instance.AddToActionsList($"Firmware check failed: {ex.Message}",Level.ERROR);
MainForm.Instance.AddLabelToPanel("Firmware = Unknown", true);
} }
} }
@@ -83,4 +85,10 @@ public static class MobilePreTest
byte[] bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(input)); byte[] bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(input));
return BitConverter.ToString(bytes).Replace("-", "").ToLower(); return BitConverter.ToString(bytes).Replace("-", "").ToLower();
} }
public static async Task RunPreTestAsync()
{
await CheckFirmwareAsync();
}
} }