From 6e2c36d4ae52d1f7a7765471026e1b70d2f910c1 Mon Sep 17 00:00:00 2001 From: Gary Sharp Date: Sun, 15 Jun 2025 17:51:35 +1000 Subject: [PATCH] bug: enforce device details scope --- .../Devices/DeviceDetailExtensions.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Disco.Services/Devices/DeviceDetailExtensions.cs b/Disco.Services/Devices/DeviceDetailExtensions.cs index 34e83b73..bca203f4 100644 --- a/Disco.Services/Devices/DeviceDetailExtensions.cs +++ b/Disco.Services/Devices/DeviceDetailExtensions.cs @@ -10,16 +10,16 @@ namespace Disco.Services public static class DeviceDetailExtensions { #region Helpers - private static string GetDetail(this IEnumerable details, string Scope, string Key) + public static string GetDetail(this IEnumerable details, string scope, string key) { if (details == null) throw new ArgumentNullException("details"); - if (string.IsNullOrEmpty(Scope)) + if (string.IsNullOrEmpty(scope)) throw new ArgumentNullException("Scope"); - if (string.IsNullOrEmpty(Key)) + if (string.IsNullOrEmpty(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) return null; @@ -27,19 +27,19 @@ namespace Disco.Services 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) throw new ArgumentNullException("device"); - if (string.IsNullOrEmpty(Scope)) + if (string.IsNullOrEmpty(scope)) throw new ArgumentNullException("Scope"); - if (string.IsNullOrEmpty(Key)) + if (string.IsNullOrEmpty(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 - if (detail == null && Value == null) + if (detail == null && value == null) return; if (detail == null) @@ -47,22 +47,22 @@ namespace Disco.Services detail = new DeviceDetail() { DeviceSerialNumber = device.SerialNumber, - Scope = Scope, - Key = Key, - Value = Value + Scope = scope, + Key = key, + Value = value }; device.DeviceDetails.Add(detail); } - if (detail.Value != Value) + if (detail.Value != value) { - if (Value == null) + if (value == null) { device.DeviceDetails.Remove(detail); } else { - detail.Value = Value; + detail.Value = value; } } } @@ -189,7 +189,7 @@ namespace Disco.Services public static List Processors(this IEnumerable details) { var json = details.GetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyProcessors); - + if (string.IsNullOrEmpty(json)) return null;