bug: enforce device details scope

This commit is contained in:
Gary Sharp
2025-06-15 17:51:35 +10:00
parent bccbb20b84
commit 6e2c36d4ae
@@ -10,16 +10,16 @@ namespace Disco.Services
public static class DeviceDetailExtensions public static class DeviceDetailExtensions
{ {
#region Helpers #region Helpers
private static string GetDetail(this IEnumerable<DeviceDetail> details, string Scope, string Key) public static string GetDetail(this IEnumerable<DeviceDetail> details, string scope, string key)
{ {
if (details == null) if (details == null)
throw new ArgumentNullException("details"); throw new ArgumentNullException("details");
if (string.IsNullOrEmpty(Scope)) if (string.IsNullOrEmpty(scope))
throw new ArgumentNullException("Scope"); throw new ArgumentNullException("Scope");
if (string.IsNullOrEmpty(Key)) if (string.IsNullOrEmpty(key))
throw new ArgumentNullException("Key"); throw new ArgumentNullException("Key");
var detail = details.Where(d => d.Key == Key).FirstOrDefault(); var detail = details.Where(d => d.Scope == scope && d.Key == key).FirstOrDefault();
if (detail == null) if (detail == null)
return null; return null;
@@ -27,19 +27,19 @@ namespace Disco.Services
return detail.Value; return detail.Value;
} }
private static void SetDetail(this Device device, string Scope, string Key, string Value) public static void SetDetail(this Device device, string scope, string key, string value)
{ {
if (device == null) if (device == null)
throw new ArgumentNullException("device"); throw new ArgumentNullException("device");
if (string.IsNullOrEmpty(Scope)) if (string.IsNullOrEmpty(scope))
throw new ArgumentNullException("Scope"); throw new ArgumentNullException("Scope");
if (string.IsNullOrEmpty(Key)) if (string.IsNullOrEmpty(key))
throw new ArgumentNullException("Key"); throw new ArgumentNullException("Key");
var detail = device.DeviceDetails.Where(d => d.Scope == Scope && d.Key == Key).FirstOrDefault(); var detail = device.DeviceDetails.Where(d => d.Scope == scope && d.Key == key).FirstOrDefault();
// No Detail Stored & Set to Null // No Detail Stored & Set to Null
if (detail == null && Value == null) if (detail == null && value == null)
return; return;
if (detail == null) if (detail == null)
@@ -47,22 +47,22 @@ namespace Disco.Services
detail = new DeviceDetail() detail = new DeviceDetail()
{ {
DeviceSerialNumber = device.SerialNumber, DeviceSerialNumber = device.SerialNumber,
Scope = Scope, Scope = scope,
Key = Key, Key = key,
Value = Value Value = value
}; };
device.DeviceDetails.Add(detail); device.DeviceDetails.Add(detail);
} }
if (detail.Value != Value) if (detail.Value != value)
{ {
if (Value == null) if (value == null)
{ {
device.DeviceDetails.Remove(detail); device.DeviceDetails.Remove(detail);
} }
else else
{ {
detail.Value = Value; detail.Value = value;
} }
} }
} }
@@ -189,7 +189,7 @@ namespace Disco.Services
public static List<Processor> Processors(this IEnumerable<DeviceDetail> details) public static List<Processor> Processors(this IEnumerable<DeviceDetail> details)
{ {
var json = details.GetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyProcessors); var json = details.GetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyProcessors);
if (string.IsNullOrEmpty(json)) if (string.IsNullOrEmpty(json))
return null; return null;