diff --git a/AiQ Tests/AiQLiteTests.cs b/AiQ Tests/AiQLiteTests.cs new file mode 100644 index 0000000..624801a --- /dev/null +++ b/AiQ Tests/AiQLiteTests.cs @@ -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 + + } +} diff --git a/AiQ Tests/Diagnostics.cs b/AiQ Tests/Diagnostics.cs index 9e040b7..053e9df 100644 --- a/AiQ Tests/Diagnostics.cs +++ b/AiQ Tests/Diagnostics.cs @@ -110,13 +110,23 @@ namespace AiQ_GUI.AiQ_Tests bool modelIsRed = !RegexCache.ModelRegex().IsMatch(DiagsAPI.modelNumber); 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 (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 @@ -127,7 +137,6 @@ namespace AiQ_GUI.AiQ_Tests 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"); } - // 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 { 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 { - 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) @@ -148,45 +159,36 @@ namespace AiQ_GUI.AiQ_Tests } // Check licenses - List licensesOnCam = []; // Temporary list for licenses on camera + List licensesOnCam = new List(); // Temporary list for licenses on camera - if (DiagsAPI.licenses.saf1) - licensesOnCam.Add("SAF1"); - if (DiagsAPI.licenses.saf2) - licensesOnCam.Add("SAF2"); - if (DiagsAPI.licenses.saf3) - licensesOnCam.Add("SAF3"); - if (DiagsAPI.licenses.saf4) - 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"); + if (DiagsAPI.licenses.saf1) licensesOnCam.Add("SAF1"); + if (DiagsAPI.licenses.saf2) licensesOnCam.Add("SAF2"); + if (DiagsAPI.licenses.saf3) licensesOnCam.Add("SAF3"); + if (DiagsAPI.licenses.saf4) 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(licText, false); + MainForm.Instance.AddLabelToPanel( + "Licenses = " + (licensesOnCam.Count == 0 ? "None" : string.Join(", ", licensesOnCam)), + false); double CPUround = Math.Round(DiagsAPI.CPUusage); // Check CPU usage isn't near max - string cpuText = "CPU Usage = " + CPUround + "%"; - bool cpuIsRed = CPUround <= 50 || CPUround >= 98; - MainForm.Instance.AddLabelToPanel(cpuText, cpuIsRed); + MainForm.Instance.AddLabelToPanel( + "CPU Usage = " + CPUround + "%", + 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; 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") - { - // OK - passes condition - vaxtorIsRed = false; - } + if (DiagsAPI.licenses.raptorKeyID != "Not Licensed") vaxtorIsRed = false; + else if (CameraAccessInfo.VaxtorLic == false) vaxtorIsRed = false; else if (await MainForm.Instance.DisplayQuestion("Was this camera licensed manually?")) { 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); 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; vaxtorIsRed = false; } - else // Should have license but doesn't OR shouldn't have but does + any other unforeseen circumstance then fail - { - vaxtorIsRed = true; - } + else vaxtorIsRed = true; MainForm.Instance.AddLabelToPanel(vaxtorText, vaxtorIsRed); - // Check trim is within 10% both horizontally and vertically, from auto set done earlier in the test - 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. + // Check trim is within 10% both horizontally and vertically const int HMax = 96; // 5% of 1920 each way = ±96 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(trimText, trimIsRed); + MainForm.Instance.AddLabelToPanel( + "Trim = H: " + DiagsAPI.trim[0] + " V: " + DiagsAPI.trim[1], + Math.Abs(DiagsAPI.trim[0]) > HMax || Math.Abs(DiagsAPI.trim[1]) > VMax); } } } diff --git a/AiQ_GUI.Designer.cs b/AiQ_GUI.Designer.cs index 2cf50b3..dfaa612 100644 --- a/AiQ_GUI.Designer.cs +++ b/AiQ_GUI.Designer.cs @@ -182,7 +182,7 @@ namespace AiQ_GUI CbBxCameraModel.Name = "CbBxCameraModel"; CbBxCameraModel.Size = new Size(494, 25); CbBxCameraModel.TabIndex = 188; - CbBxCameraModel.SelectedIndexChanged += CbBxCamTypSelectedIndexChanged; + CbBxCameraModel.SelectedIndexChanged += CbBxCameraModel_SelectedIndexChanged; // // BtnStartTest // @@ -1815,7 +1815,6 @@ namespace AiQ_GUI CbBxCamType.Name = "CbBxCamType"; CbBxCamType.Size = new Size(233, 25); CbBxCamType.TabIndex = 241; - CbBxCamType.Text = "AiQ"; CbBxCamType.SelectedIndexChanged += CbBxCamType_SelectedIndexChanged; // // MainForm diff --git a/AiQ_GUI.cs b/AiQ_GUI.cs index 904378f..9d11fc5 100644 --- a/AiQ_GUI.cs +++ b/AiQ_GUI.cs @@ -99,6 +99,7 @@ namespace AiQ_GUI await CheckHWOnline; Flags.Start = false; + CbBxCamType.Text = "AiQ"; // Default to AiQ cameras } @@ -139,7 +140,6 @@ namespace AiQ_GUI CbBxCameraModel.Items.AddRange(models); } - private void PopulateUIWithLDS(LocalDataStore lds) { CbBxUserName.Text = lds.User; @@ -202,7 +202,7 @@ namespace AiQ_GUI } else if (CbBxCamType.Text == "Mobile") { - + await MobilePreTest.RunPreTestAsync(); 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(); } @@ -1434,34 +1434,9 @@ namespace AiQ_GUI { Stopwatch stopWatchTest = Stopwatch.StartNew(); - - await MobilePreTest.CheckFirmwareAsync(); - //AddLabelToPanel("Test Complete", false); - //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); + //StatsExcel excelExporter = new(); + //excelExporter.ExportDatabaseToExcel(); + //await MobilePreTest.CheckFirmwareAsync(); AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"), Level.LOG); } diff --git a/Microsoft/StatsExcel.cs b/Microsoft/StatsExcel.cs index 5c1549d..f95586b 100644 --- a/Microsoft/StatsExcel.cs +++ b/Microsoft/StatsExcel.cs @@ -40,7 +40,7 @@ namespace AiQ_GUI const string selectColumns = @" ModelNumber, [Total Tests Run], - [Pre Tests Passed] + [Pre Tests Passed], [Pre Tests Failed], [Final Tests Passed], [Final Tests Failed], @@ -84,8 +84,28 @@ namespace AiQ_GUI XLWorkbook workbook; if (File.Exists(exportPath)) { - workbook = new XLWorkbook(exportPath); - MainForm.Instance.AddToActionsList("Opened existing workbook."); + try + { + 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 { diff --git a/Mobile Tests/MobilePreTest.cs b/Mobile Tests/MobileTests.cs similarity index 80% rename from Mobile Tests/MobilePreTest.cs rename to Mobile Tests/MobileTests.cs index 7f44db3..8ee8c6b 100644 --- a/Mobile Tests/MobilePreTest.cs +++ b/Mobile Tests/MobileTests.cs @@ -1,21 +1,23 @@ using AiQ_GUI; using System; +using System.IO; using System.Net.Http; using System.Net.Http.Json; using System.Security.Cryptography; using System.Text; using System.Text.Json; using System.Threading.Tasks; +using System.Windows.Forms; +using System.Diagnostics; public static class MobilePreTest { public static async Task CheckFirmwareAsync() { - const string cameraIp = "192.168.0.112"; using HttpClient client = new HttpClient { - BaseAddress = new Uri($"http://{cameraIp}") + BaseAddress = new Uri($"http://{MainForm.Instance.CamOnTest.IP}") }; try @@ -31,32 +33,32 @@ public static class MobilePreTest string body = await response.Content.ReadAsStringAsync(); - MainForm.Instance.AddToActionsList($"Firmware check response: {(int)response.StatusCode} {response.StatusCode} | {body}",Level.LOG); - response.EnsureSuccessStatusCode(); JsonElement json = JsonSerializer.Deserialize(body); string version = json.GetProperty("version").GetString()?.Trim(); - // Compare against expected SRZFirmware from UniversalData if (string.IsNullOrEmpty(UniversalData.SRZFirmware)) { 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) { - MainForm.Instance.AddToActionsList($"Firmware match successful: {version}",Level.Success); + MainForm.Instance.AddLabelToPanel($"Firmware = {version}", false); } else { - MainForm.Instance.AddToActionsList($"Firmware mismatch: Camera has {version}, expected {UniversalData.SRZFirmware}",Level.ERROR); + MainForm.Instance.AddLabelToPanel($"Firmware = {version}", true); } + } catch (Exception ex) { 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)); return BitConverter.ToString(bytes).Replace("-", "").ToLower(); } + public static async Task RunPreTestAsync() + { + await CheckFirmwareAsync(); + + } } +