Add project files.
This commit is contained in:
125
Microsoft/Access.cs
Normal file
125
Microsoft/Access.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using System.Data.OleDb;
|
||||
|
||||
namespace AiQ_GUI
|
||||
{
|
||||
class Access
|
||||
{
|
||||
const string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\Shared drives\MAV Production GUI's\AiQ\GUI's\AiQ_Final_Test.accdb;Persist Security Info=False;OLE DB Services=-1;";
|
||||
|
||||
// Reads camera model numbers and descriptions from the database, sorts them alphabetically by model number (except "AB12CD", which appears last), and formats each entry as "ModelNumber - Description".
|
||||
public static string[] ReadCamTypes()
|
||||
{
|
||||
List<Tuple<string, string>> modelTuples = new List<Tuple<string, string>>(30); // Preallocate list with estimated capacity to reduce internal resizing
|
||||
using OleDbConnection conn = new(connString);
|
||||
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Could not access Access in google drive. Is it running?");
|
||||
return null;
|
||||
}
|
||||
|
||||
const string query = "SELECT ModelNumber, Description FROM AiQ WHERE MarkNumber > 1";
|
||||
|
||||
using OleDbCommand cmd = new(query, conn);
|
||||
using OleDbDataReader reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
// Extract each model number and description, using empty string if null
|
||||
string modelNumber = reader["ModelNumber"] as string ?? string.Empty;
|
||||
string description = reader["Description"] as string ?? string.Empty;
|
||||
modelTuples.Add(Tuple.Create(modelNumber.Trim(), description.Trim()));
|
||||
}
|
||||
|
||||
// Sort: push "AB12CD" to the bottom, then sort remaining items alphabetically
|
||||
IOrderedEnumerable<Tuple<string, string>> sorted = modelTuples.OrderBy(t => t.Item1.Equals("AB12CD", StringComparison.OrdinalIgnoreCase) ? 1 : 0)
|
||||
.ThenBy(t => t.Item1, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// Format the sorted tuples as "ModelNumber - Description" strings and return as array
|
||||
return sorted.Select(t => $"{t.Item1} - {t.Item2}").ToArray();
|
||||
}
|
||||
|
||||
// Read the universal data table from the database and populate the UniversalData class with the values.
|
||||
public static void ReadUniData()
|
||||
{
|
||||
using OleDbConnection conn = new(connString);
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Could not access Access in google drive. Is it running?");
|
||||
return;
|
||||
}
|
||||
|
||||
const string query = "SELECT FlexiVersion, FlexiRevision, WonwooFirmware, AiQGUIVersion, PowerConsumption, LicencingServerURL FROM UniversalData"; // Grab the universal data
|
||||
|
||||
using OleDbCommand cmd = new(query, conn);
|
||||
using OleDbDataReader reader = cmd.ExecuteReader();
|
||||
reader.Read();
|
||||
UniversalData.ExpFlexiVer = Convert.ToString(reader["FlexiVersion"]);
|
||||
UniversalData.ExpFlexiRev = Convert.ToString(reader["FlexiRevision"]);
|
||||
UniversalData.WonwooFirmware = Convert.ToString(reader["WonwooFirmware"]);
|
||||
UniversalData.LatestVersion = Convert.ToString(reader["AiQGUIVersion"]);
|
||||
UniversalData.PowerConsumption = Convert.ToInt16(reader["PowerConsumption"]);
|
||||
UniversalData.LicencingServerURL = Convert.ToString(reader["LicencingServerURL"]);
|
||||
}
|
||||
|
||||
// Knowing the model number on test, this function reads the database and populates the Camera class with the values.
|
||||
public static void ReadModelRow(string ModelOnTest)
|
||||
{
|
||||
using OleDbConnection conn = new(connString);
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Could not access Access in google drive. Is it running?");
|
||||
return;
|
||||
}
|
||||
|
||||
string query = $"SELECT * FROM AiQ WHERE ModelNumber = '{ModelOnTest}';"; // Grab all the info for specified model
|
||||
|
||||
using OleDbCommand cmd = new(query, conn);
|
||||
using OleDbDataReader reader = cmd.ExecuteReader();
|
||||
reader.Read();
|
||||
|
||||
// Populate the CameraAccessInfo class with the values from the database
|
||||
CameraAccessInfo.Processor = Convert.ToString(reader["Processor"]);
|
||||
CameraAccessInfo.VaxtorLic = Convert.ToBoolean(reader["Vaxtor"]);
|
||||
CameraAccessInfo.HardwareExtras = Convert.ToString(reader["HardwareExtras"]);
|
||||
CameraAccessInfo.PowerType = Convert.ToString(reader["PowerType"]);
|
||||
CameraAccessInfo.LED_V = Convert.ToDouble(reader["LEDVoltage"]);
|
||||
CameraAccessInfo.LED_I = Convert.ToInt32(reader["LEDCurrent"]);
|
||||
CameraAccessInfo.SpreadsheetID = Convert.ToString(reader["SSID"]);
|
||||
}
|
||||
}
|
||||
|
||||
// Expected universal data for the GUI, read from the database
|
||||
public class UniversalData
|
||||
{
|
||||
public static string ExpFlexiVer { get; set; } = string.Empty;
|
||||
public static string ExpFlexiRev { get; set; } = string.Empty;
|
||||
public static string WonwooFirmware { get; set; } = string.Empty;
|
||||
public static string LatestVersion { get; set; } = string.Empty;
|
||||
public static int PowerConsumption { get; set; } = 0;
|
||||
public static string LicencingServerURL { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
// One object to contain all the camera info from the model info access database
|
||||
public class CameraAccessInfo
|
||||
{
|
||||
public static string Processor { get; set; } = string.Empty;
|
||||
public static bool VaxtorLic { get; set; } = false;
|
||||
public static string HardwareExtras { get; set; } = string.Empty;
|
||||
public static string PowerType { get; set; } = string.Empty;
|
||||
public static double LED_V { get; set; } = 0;
|
||||
public static int LED_I { get; set; } = 0;
|
||||
public static string SpreadsheetID { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
436
Microsoft/Excel.cs
Normal file
436
Microsoft/Excel.cs
Normal file
@@ -0,0 +1,436 @@
|
||||
using ClosedXML.Excel;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace AiQ_GUI
|
||||
{
|
||||
internal class Excel
|
||||
{
|
||||
public static void WriteTo(string FilePath)
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
XLWorkbook workbook = new(FilePath); // Open existing file
|
||||
IXLWorksheet worksheet = workbook.Worksheets.First();
|
||||
worksheet.Cell("A1").Value = "Hello World!";
|
||||
worksheet.Cell("A2").FormulaA1 = "=MID(A1, 7, 5)";
|
||||
workbook.SaveAs(FilePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not find spreadsheet :(");
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReadFrom(string FilePath)
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
XLWorkbook workbook = new(FilePath); // Open existing file
|
||||
IXLWorksheet worksheet = workbook.Worksheets.First();
|
||||
return worksheet.Cell("A1").GetString();
|
||||
}
|
||||
else
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not find spreadsheet :(");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int GetNextBlankRow(string FilePath)
|
||||
{
|
||||
if (!File.Exists(FilePath))
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not find spreadsheet :(");
|
||||
return -1;
|
||||
}
|
||||
|
||||
using XLWorkbook workbook = new XLWorkbook(FilePath);
|
||||
IXLWorksheet worksheet = workbook.Worksheets.First();
|
||||
|
||||
// Start from row 1 and check downwards
|
||||
int row = 1;
|
||||
while (!worksheet.Cell(row, 1).IsEmpty())
|
||||
{
|
||||
row++;
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
public static string UpdateSpreadSheetPreTest(string FilePath, Versions Vers, string CamDesc, string ModelOnTest)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(FilePath))
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not find spreadsheet :(");
|
||||
return "Spreadsheet not found";
|
||||
}
|
||||
|
||||
using XLWorkbook workbook = new XLWorkbook(FilePath);
|
||||
IXLWorksheet worksheet = workbook.Worksheets.First();
|
||||
|
||||
// Start from row 1 and check downwards to find next empty row in column B
|
||||
int row = 1;
|
||||
while (!worksheet.Cell(row, 2).IsEmpty()) // Column B = Serial numbers
|
||||
{
|
||||
row++;
|
||||
}
|
||||
|
||||
// Safety check to avoid invalid index
|
||||
if (row <= 1)
|
||||
{
|
||||
return "Last serial number not found";
|
||||
}
|
||||
|
||||
// Generate new serial number from previous
|
||||
string lastSerialNumber = worksheet.Cell(row - 1, 2).GetString(); // Column B
|
||||
if (string.IsNullOrWhiteSpace(lastSerialNumber) || !lastSerialNumber.StartsWith("K"))
|
||||
{
|
||||
return "Invalid last serial number format";
|
||||
}
|
||||
|
||||
int NewSerialNumberInt = Convert.ToInt32(lastSerialNumber.Substring(1)) + 1;
|
||||
string newSerialNumber = "K" + NewSerialNumberInt;
|
||||
|
||||
// Write values to the corresponding columns
|
||||
worksheet.Cell(row, 1).Value = ModelOnTest; // Column A
|
||||
worksheet.Cell(row, 2).Value = newSerialNumber; // Column B
|
||||
worksheet.Cell(row, 3).Value = CamDesc; // Column C
|
||||
worksheet.Cell(row, 4).Value = "Pre Test: " + DateTime.Now.ToString("dd/MM/yyyy"); // Column D
|
||||
worksheet.Cell(row, 5).Value = Vers.version + " - " + Vers.revision + Environment.NewLine +
|
||||
Vers.buildtime + Environment.NewLine + Vers.proquint; // Column E
|
||||
worksheet.Cell(row, 8).Value = Vers.MAC; // Column H
|
||||
worksheet.Cell(row, 14).Value = $"GUI Version: {GUIUpdate.GUIVerShort}"; // Column N
|
||||
worksheet.Cell(row, 19).Value = "TRUE"; // Column S
|
||||
|
||||
workbook.SaveAs(FilePath);
|
||||
|
||||
return newSerialNumber;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Error updating spreadsheet: " + ex.Message);
|
||||
return $"ERROR: {ex.Message}";
|
||||
}
|
||||
}
|
||||
|
||||
public static string UpdateSpreadSheetRePreTest(string filePath, Versions Vers)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not find spreadsheet :(");
|
||||
return "Spreadsheet not found";
|
||||
}
|
||||
|
||||
using XLWorkbook workbook = new XLWorkbook(filePath);
|
||||
IXLWorksheet worksheet = workbook.Worksheets.First();
|
||||
|
||||
// Find the row with the matching serial number in column B
|
||||
int row = 1;
|
||||
while (!worksheet.Cell(row, 2).IsEmpty())
|
||||
{
|
||||
string cellSerial = worksheet.Cell(row, 2).GetString();
|
||||
if (cellSerial.Contains(Vers.Serial))
|
||||
{
|
||||
// Update columns D-E
|
||||
worksheet.Cell(row, 4).Value = "Pre Test: " + DateTime.Now.ToString("dd/MM/yyyy");
|
||||
worksheet.Cell(row, 5).Value = Vers.version + " - " + Vers.revision + Environment.NewLine +
|
||||
Vers.buildtime + Environment.NewLine + Vers.proquint;
|
||||
// Update MAC to column H
|
||||
worksheet.Cell(row, 8).Value = Vers.MAC;
|
||||
|
||||
// Update GUI Version to column N
|
||||
worksheet.Cell(row, 14).Value = $"GUI Version: {GUIUpdate.GUIVerShort}";
|
||||
|
||||
// Write TRUE to WIP checkbox in column S
|
||||
worksheet.Cell(row, 19).Value = "TRUE";
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
return "OK";
|
||||
}
|
||||
row++;
|
||||
}
|
||||
|
||||
return "Serial number not found";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Error updating spreadsheet: " + ex.Message);
|
||||
return $"ERROR: {ex.Message}";
|
||||
}
|
||||
}
|
||||
|
||||
public static string UpdateSpreadSheetFinalTest(string FilePath, Diags DiagsAPI, SSHData sshData, int RMANum)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(FilePath))
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not find spreadsheet :(");
|
||||
return "Spreadsheet not found";
|
||||
}
|
||||
|
||||
using XLWorkbook workbook = new XLWorkbook(FilePath);
|
||||
IXLWorksheet worksheet = workbook.Worksheets.First();
|
||||
|
||||
// Find the row with the matching serial number in column B
|
||||
int row = 1;
|
||||
while (!worksheet.Cell(row, 2).IsEmpty())
|
||||
{
|
||||
string serial = worksheet.Cell(row, 2).GetString();
|
||||
if (serial == DiagsAPI.serialNumber)
|
||||
{
|
||||
// Update column D with test date
|
||||
string existingDate = worksheet.Cell(row, 4).GetString(); // Column D
|
||||
string newDate = (RMANum != 0 ? "RMA Test: " : "Final Test: ") + DateTime.Now.ToString("dd/MM/yyyy");
|
||||
worksheet.Cell(row, 4).Value = existingDate + Environment.NewLine + newDate;
|
||||
|
||||
// Update columns F-G
|
||||
worksheet.Cell(row, 6).Value = DiagsAPI.licenses.raptorKeyID; // Column F
|
||||
worksheet.Cell(row, 7).Value = sshData.packages; // Column G
|
||||
|
||||
// Update columns N-S
|
||||
worksheet.Cell(row, 14).Value = $"GUI Version: {GUIUpdate.GUIVerShort}"; // Column N
|
||||
worksheet.Cell(row, 15).Value = DiagsAPI.licenses.saf1; // Column O
|
||||
worksheet.Cell(row, 16).Value = DiagsAPI.licenses.audit; // Column P
|
||||
worksheet.Cell(row, 17).Value = DiagsAPI.licenses.stream; // Column Q
|
||||
worksheet.Cell(row, 18).Value = sshData.tailscale; // Column R
|
||||
worksheet.Cell(row, 19).Value = "FALSE"; // Column S (WIP checkbox)
|
||||
|
||||
workbook.SaveAs(FilePath);
|
||||
return "OK";
|
||||
}
|
||||
row++;
|
||||
}
|
||||
|
||||
return "Serial number not found";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Error updating spreadsheet: " + ex.Message);
|
||||
return "Failed to update spreadsheet data, please check manually: " + ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
public static string UpdateSpreadSheetVaxtor(string FilePath, VaxtorLic VaxtorLicResp, string serial, string model)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(FilePath))
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not find spreadsheet :(");
|
||||
return "Spreadsheet not found";
|
||||
}
|
||||
|
||||
using XLWorkbook workbook = new XLWorkbook(FilePath);
|
||||
IXLWorksheet worksheet = workbook.Worksheets.First();
|
||||
|
||||
// Find next free row by checking column C
|
||||
int row = 2;
|
||||
while (!worksheet.Cell(row, 3).IsEmpty()) // Column C
|
||||
{
|
||||
row++;
|
||||
}
|
||||
|
||||
// Write model, serial, date, and protectionKeyId to columns C–F
|
||||
worksheet.Cell(row, 3).Value = model; // Column C
|
||||
worksheet.Cell(row, 4).Value = serial; // Column D
|
||||
worksheet.Cell(row, 5).Value = DateTime.Now.ToString("dd/MM/yyyy"); // Column E
|
||||
worksheet.Cell(row, 6).Value = VaxtorLicResp.protectionKeyId; // Column F
|
||||
|
||||
// Write "PROD" to column H
|
||||
worksheet.Cell(row, 8).Value = "PROD"; // Column H
|
||||
|
||||
workbook.SaveAs(FilePath);
|
||||
return string.Empty;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Error updating Vaxtor spreadsheet: " + ex.Message);
|
||||
return "Failed to update spreadsheet data, please check manually: " + ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
public static int CheckRMANum(string filePath, string serial, string model)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not find RMA Control spreadsheet :(");
|
||||
return 0;
|
||||
}
|
||||
|
||||
using XLWorkbook workbook = new XLWorkbook(filePath);
|
||||
IXLWorksheet worksheet = workbook.Worksheets.First();
|
||||
|
||||
int row = 2; // Start from row 2
|
||||
while (!worksheet.Cell(row, 8).IsEmpty() || !worksheet.Cell(row, 9).IsEmpty()) // Columns H (8) and I (9)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sheetSerial = worksheet.Cell(row, 8).GetString();
|
||||
string sheetModel = worksheet.Cell(row, 9).GetString();
|
||||
|
||||
if (sheetSerial.Contains(serial) && sheetModel.Contains(model))
|
||||
{
|
||||
string rmaStr = worksheet.Cell(row, 1).GetString(); // Column A
|
||||
if (int.TryParse(rmaStr, out int rmaNumber))
|
||||
{
|
||||
return rmaNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { /* Safe to ignore bad row */ }
|
||||
|
||||
row++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Error reading RMA Control spreadsheet: " + ex.Message);
|
||||
}
|
||||
|
||||
return 0; // Default if not found
|
||||
}
|
||||
|
||||
public static int CheckSerialNumRow(string filePath, string serial)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not find spreadsheet :(");
|
||||
return 0;
|
||||
}
|
||||
|
||||
using XLWorkbook workbook = new XLWorkbook(filePath);
|
||||
IXLWorksheet worksheet = workbook.Worksheets.First();
|
||||
|
||||
int row = 1;
|
||||
while (!worksheet.Cell(row, 2).IsEmpty()) // Column B = 2
|
||||
{
|
||||
try
|
||||
{
|
||||
string cellSerial = worksheet.Cell(row, 2).GetString();
|
||||
if (cellSerial.Contains(serial))
|
||||
{
|
||||
return row;
|
||||
}
|
||||
}
|
||||
catch { /* Ignore malformed rows */ }
|
||||
|
||||
row++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Error checking serial number row: " + ex.Message);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int CheckNextFree(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not find spreadsheet :(");
|
||||
return -1;
|
||||
}
|
||||
|
||||
using XLWorkbook workbook = new XLWorkbook(filePath);
|
||||
IXLWorksheet worksheet = workbook.Worksheets.First();
|
||||
|
||||
int row = 2; // Start from C2
|
||||
while (!worksheet.Cell(row, 3).IsEmpty()) // Column C = 3
|
||||
{
|
||||
row++;
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Error checking next free row: " + ex.Message);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
//***** TESTING *****\\
|
||||
public static void TestAllExcelFunctions()
|
||||
{
|
||||
string filePath = @"C:\Users\BradleyRelyea\OneDrive - MAV Systems Ltd\MAV R&D - General\ModelsInfo.xlsx";
|
||||
// 1. Ensure spreadsheet exists and has valid starting data
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
XLWorkbook workbook = new XLWorkbook();
|
||||
IXLWorksheet ws = workbook.Worksheets.Add("Sheet1");
|
||||
|
||||
// Pre-fill first row with dummy data for serial
|
||||
ws.Cell("A1").Value = "InitialModel";
|
||||
ws.Cell("B1").Value = "K1000"; // Starting serial
|
||||
ws.Cell("C2").Value = "Existing"; // Simulate used row in Vaxtor (for CheckNextFree)
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
// 2. Run Pre-Test update
|
||||
Versions fakeVersion = new Versions
|
||||
{
|
||||
version = "1.6.4",
|
||||
revision = "bf16134",
|
||||
buildtime = "2025-07-21 10:00",
|
||||
proquint = "bexog-ludeg-zokud-huqer",
|
||||
MAC = "00:1A:2B:3C:4D:5E"
|
||||
};
|
||||
|
||||
string preTestResult = Excel.UpdateSpreadSheetPreTest(filePath, fakeVersion, "Fake Cam", "TestModel");
|
||||
Debug.WriteLine("Pre-Test Result: " + preTestResult);
|
||||
|
||||
// 3. Run Final Test update
|
||||
Diags fakeDiags = new Diags
|
||||
{
|
||||
serialNumber = preTestResult, // Newly generated serial
|
||||
licenses = new Licenses
|
||||
{
|
||||
raptorKeyID = "9999999999",
|
||||
saf1 = true,
|
||||
audit = true,
|
||||
stream = true
|
||||
}
|
||||
};
|
||||
|
||||
SSHData fakeSSH = new SSHData
|
||||
{
|
||||
packages = "\r\nlibvaxtorocr10 - 8.4.20-1\r\nvaxtorocrdatacpu3 - 8.4.20-1",
|
||||
tailscale = true
|
||||
};
|
||||
|
||||
string finalTestResult = Excel.UpdateSpreadSheetFinalTest(filePath, fakeDiags, fakeSSH, 0);
|
||||
Debug.WriteLine("Final-Test Result: " + finalTestResult);
|
||||
|
||||
// // 4. Run Vaxtor update
|
||||
// var fakeVaxtorLic = new VaxtorLic
|
||||
// {
|
||||
// protectionKeyId = "VKID-555-ALPHA"
|
||||
// };
|
||||
|
||||
// string vaxtorResult = Excel.UpdateSpreadSheetVaxtor(filePath, fakeVaxtorLic, "VX-999", "VXModel");
|
||||
// Debug.WriteLine("Vaxtor Result: " + vaxtorResult);
|
||||
|
||||
// // 5. Check Serial Row
|
||||
// int serialRow = Excel.CheckSerialNumRow(filePath, preTestResult);
|
||||
// Debug.WriteLine("Serial row found at: " + serialRow);
|
||||
|
||||
// // 6. Check Next Free Vaxtor Row
|
||||
// int nextFree = Excel.CheckNextFree(filePath);
|
||||
// Debug.WriteLine("Next free row in Vaxtor sheet (Column C): " + nextFree);
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
29
Microsoft/Teams.cs
Normal file
29
Microsoft/Teams.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Text;
|
||||
|
||||
namespace AiQ_GUI
|
||||
{
|
||||
internal class Teams
|
||||
{
|
||||
const string webhookUrl = "https://default71bd136a1c65418fb59e927135629c.ac.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/b27c5192e83f4f48b20c1b115985b0b3/triggers/manual/paths/invoke/?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=1-eCbYXms6xInRKHwz3tgAcdQ9x7CSjl3Yzw2V_1MlA";
|
||||
|
||||
public static async Task SendMssg(string ApprovalRow, string User)
|
||||
{
|
||||
using HttpClient client = new HttpClient();
|
||||
|
||||
string link = $"https://docs.google.com/spreadsheets/d/1bCcCr4OYqfjmydt6UqtmN4FQETezXmZRSStJdCCcqZM/edit#gid=1931079354&range=A{ApprovalRow}"; // Has to be parsed like this as teams doesnt hyperlink otherwise
|
||||
|
||||
var payload = new
|
||||
{
|
||||
text = $"🔔 Camera approval required!\n\n" +
|
||||
$"{link}\n\n" +
|
||||
$"Thanks,\n{User}"
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(payload);
|
||||
StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response = await client.PostAsync(webhookUrl, content);
|
||||
}
|
||||
}
|
||||
}
|
137
Microsoft/Windows.cs
Normal file
137
Microsoft/Windows.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace AiQ_GUI
|
||||
{
|
||||
internal class Windows
|
||||
{
|
||||
private static readonly string[] targetProcesses = ["IP_Tool", "Rapier", "IPConfig", "BackdoorGUI"];
|
||||
|
||||
// Closes other MAV and Rudstone tools.
|
||||
public static async Task CloseProcesses()
|
||||
{
|
||||
IEnumerable<Task> tasks = Process.GetProcesses()
|
||||
.Where(p => targetProcesses.Any(tp => p.ProcessName.Contains(tp)))
|
||||
.Select(clsProcess =>
|
||||
{
|
||||
using (clsProcess)
|
||||
{
|
||||
try
|
||||
{
|
||||
clsProcess.CloseMainWindow();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false); // Run all tasks concurrently
|
||||
}
|
||||
|
||||
public static void StartAsAdmin(string ExeLoc)
|
||||
{
|
||||
Logging.LogMessage($"Starting exe from {ExeLoc}");
|
||||
|
||||
ProcessStartInfo processInfo = new ProcessStartInfo(ExeLoc)
|
||||
{
|
||||
UseShellExecute = true,
|
||||
Verb = "runas"
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(processInfo);
|
||||
Properties.Settings.Default.FirstRun = false;
|
||||
Properties.Settings.Default.Save();
|
||||
Application.Exit(); // Exit now that we have admin rights version
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.LogErrorMessage("Failed to restart with admin rights. " + ex.Message);
|
||||
MessageBox.Show("Sorry, but I don't seem to be able to start this program with administrator rights!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateFirewall()
|
||||
{
|
||||
WindowsPrincipal wp = new(WindowsIdentity.GetCurrent());
|
||||
bool runAsAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
string ExeLoc = Assembly.GetEntryAssembly().Location.Replace("dll", "exe"); // Sometimes trys to open the dll instead of exe
|
||||
|
||||
if (Properties.Settings.Default.FirstRun && !runAsAdmin) // On first run, put into admin mode to allow defender.
|
||||
{
|
||||
StartAsAdmin(ExeLoc);
|
||||
}
|
||||
else if (runAsAdmin)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Use dynamic for COM interop
|
||||
Type ruleType = Type.GetTypeFromProgID("HNetCfg.FWRule");
|
||||
Type policyType = Type.GetTypeFromProgID("HNetCfg.FwPolicy2");
|
||||
dynamic firewallRule = Activator.CreateInstance(ruleType);
|
||||
dynamic firewallPolicy = Activator.CreateInstance(policyType);
|
||||
|
||||
firewallRule.ApplicationName = ExeLoc;
|
||||
firewallRule.Action = 1; // NET_FW_ACTION_ALLOW
|
||||
firewallRule.Description = "Programmatically added rule to allow the GUI to work";
|
||||
firewallRule.Enabled = true;
|
||||
firewallRule.InterfaceTypes = "All";
|
||||
firewallRule.Name = "AiQ_GUI";
|
||||
firewallRule.Protocol = 17; // UDP
|
||||
|
||||
firewallPolicy.Rules.Add(firewallRule);
|
||||
|
||||
Properties.Settings.Default.FirstRun = false;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.LogErrorMessage("Failed to install firewall. " + ex.Message);
|
||||
MessageBox.Show("Sorry, but I couldn't install the firewall rule!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ComImport, Guid("AF230D27-BABA-4E42-ACED-F524F22CFCE2")]
|
||||
public interface INetFwRule
|
||||
{
|
||||
string Name { get; set; }
|
||||
string Description { get; set; }
|
||||
string ApplicationName { get; set; }
|
||||
string ServiceName { get; set; }
|
||||
int Protocol { get; set; }
|
||||
string LocalPorts { get; set; }
|
||||
string RemotePorts { get; set; }
|
||||
string LocalAddresses { get; set; }
|
||||
string RemoteAddresses { get; set; }
|
||||
string IcmpTypesAndCodes { get; set; }
|
||||
int Direction { get; set; }
|
||||
object Interfaces { get; set; }
|
||||
string InterfaceTypes { get; set; }
|
||||
bool Enabled { get; set; }
|
||||
string Grouping { get; set; }
|
||||
int Profiles { get; set; }
|
||||
bool EdgeTraversal { get; set; }
|
||||
int Action { get; set; }
|
||||
}
|
||||
|
||||
[ComImport, Guid("98325047-C671-4174-8D81-DEFCD3F03186")]
|
||||
public interface INetFwPolicy2
|
||||
{
|
||||
int CurrentProfileTypes { get; }
|
||||
void get_FirewallEnabled(int profileType, out bool enabled);
|
||||
void put_FirewallEnabled(int profileType, bool enabled);
|
||||
void get_ExcludedInterfaces(int profileType, out object interfaces);
|
||||
void put_ExcludedInterfaces(int profileType, object interfaces);
|
||||
int BlockAllInboundTraffic { get; set; }
|
||||
int NotificationsDisabled { get; set; }
|
||||
int UnicastResponsesToMulticastBroadcastDisabled { get; set; }
|
||||
object Rules { get; }
|
||||
object ServiceRestriction { get; }
|
||||
// ...other members omitted for brevity
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user