Files
AiQ_GUI/LDS.cs
Bradley Born 8770469fd4 - AddToActionsList(Level.DEBUG) method has been changed to only visible when ChBXDevLog is true to avoid DEVS always having it on.
- added Level.DEBUG logs throughout selenium and soak test. Due to having prior issues with selenium and Soaktest
- Bug fix in LDS.cs this stops a crossthread exception as its trying to write to AddToActionsList before it loads.
2026-01-16 11:42:34 +00:00

67 lines
2.9 KiB
C#

using Newtonsoft.Json;
namespace AiQ_GUI
{
internal class LDS
{
// Path strings
public const string MAVPath = @"C:\ProgramData\MAV\AiQ_GUI\"; // Path to local storage
public const string OVsavePath = "OV_image.jpg"; // Path to save the downloaded image
public const string IROpensavePath = "IR_Open_image.jpg"; // Path to save the downloaded image
public const string IRTightsavePath = "IR_Tight_image.jpg"; // Path to save the downloaded image
public const string LDSFileName = "LDS.json"; // Local Data Store file name
const string DefaultJSON = "{\r\n \"User\": \"\",\r\n \"LastModel\": \"\",\r\n \"PSUIP\": \"\",\r\n \"EzIP\": \"\",\r\n \"ZebraIP\": \"\",\r\n \"TestTubeIP\": \"\",\r\n \"Shutter\": 0,\r\n \"Iris\": 0,\r\n \"Gain\": 0\r\n}";
public static LocalDataStore GetLDS()
{
try
{
if (!Directory.Exists(MAVPath)) // Check the AiQ folder exists in ProgramData and if it doesn't then create it
Directory.CreateDirectory(MAVPath);
if (!File.Exists(MAVPath + LDSFileName)) // Check the LDS file exists and if it doesn't then create it
File.WriteAllText(MAVPath + LDSFileName, DefaultJSON); // Save a blank version of the JSON
StreamReader file = new(MAVPath + LDSFileName);
string Content = file.ReadToEnd();
file.Close();
return JsonConvert.DeserializeObject<LocalDataStore>(Content);
}
catch // If file can't deserialise
{
Logging.LogMessage($"Error loading Local Data Store"); // Have to log this somewhere else as MainForm wont be loaded and you will get a crossthread error
return null; // Return null to indicate failure
}
}
// Save new version to disk
public static void SetLDS(LocalDataStore localDataStore)
{
try
{
string fileJSON = JsonConvert.SerializeObject(localDataStore, Formatting.Indented);
File.WriteAllText(MAVPath + LDSFileName, fileJSON);
}
catch (Exception ex)
{
MainForm.Instance.AddToActionsList($"Error saving Local Data Store: {ex.Message}", Level.WARNING);
}
}
}
public class LocalDataStore
{
public string User { get; set; } = string.Empty;
public string LastModel { get; set; } = string.Empty;
public string PSUIP { get; set; } = string.Empty;
public string EzIP { get; set; } = string.Empty;
public string ZebraIP { get; set; } = string.Empty;
public string TestTubeIP { get; set; } = string.Empty;
public int Shutter { get; set; }
public int Iris { get; set; }
public int Gain { get; set; }
}
}