diff --git a/Disco.Client/Interop/Hardware.cs b/Disco.Client/Interop/Hardware.cs index f35aec7c..7d8bf954 100644 --- a/Disco.Client/Interop/Hardware.cs +++ b/Disco.Client/Interop/Hardware.cs @@ -1,6 +1,7 @@ using Disco.Models.ClientServices; using Disco.Models.ClientServices.EnrolmentInformation; using System; +using System.Collections.Generic; using System.Linq; using System.Management; @@ -40,14 +41,200 @@ namespace Disco.Client.Interop throw new Exception($"The serial number reported by this device is over 60 characters long:\r\n{audit.SerialNumber}"); } -#warning TODO: Processors, PhysicalMemory, DiskDrives, etc + audit.ApplyProcessorInformation(); + audit.ApplyPhysicalMemoryInformation(); + audit.ApplyDiskDriveInformation(); audit.NetworkAdapters = Network.GetNetworkAdapters(); return audit; } - private static void ApplyBIOSInformation(this DeviceHardware DeviceHardware) + private static void ApplyProcessorInformation(this DeviceHardware deviceHardware) + { + try + { + using (var mSearcher = new ManagementObjectSearcher("SELECT DeviceID, Manufacturer, Name, Description, Architecture, Family, MaxClockSpeed, NumberOfCores, NumberOfLogicalProcessors FROM Win32_Processor")) + { + using (var mResults = mSearcher.Get()) + { + if (mResults.Count > 0) + { + var processors = new List(mResults.Count); + foreach (var mItem in mResults.Cast()) + { + if (mItem != null) + { + var processor = new Processor(); + + processor.DeviceID = (string)mItem.GetPropertyValue("DeviceID"); + processor.Manufacturer = (string)mItem.GetPropertyValue("Manufacturer"); + processor.Name = (string)mItem.GetPropertyValue("Name"); + processor.Description = (string)mItem.GetPropertyValue("Description"); + processor.Family = (ushort)mItem.GetPropertyValue("Family"); + processor.MaxClockSpeed = (uint)mItem.GetPropertyValue("MaxClockSpeed"); + processor.NumberOfCores = (uint)mItem.GetPropertyValue("NumberOfCores"); + processor.NumberOfLogicalProcessors = (uint)mItem.GetPropertyValue("NumberOfLogicalProcessors"); + + var architectureCode = (ushort)mItem.GetPropertyValue("Architecture"); + processor.Architecture = Enum.GetName(typeof(ProcessorArchitectures), architectureCode) ?? $"Unknown {architectureCode}"; + + processors.Add(processor); + } + } + deviceHardware.Processors = processors; + } + } + } + } + catch (Exception) + { + // ignore errors to ensure backwards compatibility + } + } + + private static void ApplyPhysicalMemoryInformation(this DeviceHardware deviceHardware) + { + try + { + using (var mSearcher = new ManagementObjectSearcher("SELECT Tag, SerialNumber, Manufacturer, PartNumber, Capacity, ConfiguredClockSpeed, Speed, DeviceLocator FROM Win32_PhysicalMemory")) + { + using (var mResults = mSearcher.Get()) + { + if (mResults.Count > 0) + { + var physicalMemories = new List(mResults.Count); + foreach (var mItem in mResults.Cast()) + { + if (mItem != null) + { + var physicalMemory = new PhysicalMemory(); + + physicalMemory.Tag = (string)mItem.GetPropertyValue("Tag"); + physicalMemory.SerialNumber = (string)mItem.GetPropertyValue("SerialNumber"); + physicalMemory.Manufacturer = (string)mItem.GetPropertyValue("Manufacturer"); + physicalMemory.PartNumber = (string)mItem.GetPropertyValue("PartNumber"); + physicalMemory.Capacity = (ulong)mItem.GetPropertyValue("Capacity"); + physicalMemory.ConfiguredClockSpeed = (uint)mItem.GetPropertyValue("ConfiguredClockSpeed"); + physicalMemory.Speed = (uint)mItem.GetPropertyValue("Speed"); + physicalMemory.DeviceLocator = (string)mItem.GetPropertyValue("DeviceLocator"); + + physicalMemories.Add(physicalMemory); + } + } + deviceHardware.PhysicalMemory = physicalMemories; + } + } + } + } + catch (Exception) + { + // ignore errors to ensure backwards compatibility + } + } + + private static void ApplyDiskDriveInformation(this DeviceHardware deviceHardware) + { + try + { + using (var diskSearcher = new ManagementObjectSearcher("SELECT DeviceID, Manufacturer, Model, MediaType, InterfaceType, SerialNumber, FirmwareRevision, Size FROM Win32_DiskDrive")) + { + using (var diskResults = diskSearcher.Get()) + { + if (diskResults.Count > 0) + { + var diskDrives = new List(diskResults.Count); + foreach (var diskResult in diskResults.Cast()) + { + if (diskResult != null) + { + var diskDrive = new DiskDrive(); + + diskDrive.DeviceID = (string)diskResult.GetPropertyValue("DeviceID"); + diskDrive.Manufacturer = (string)diskResult.GetPropertyValue("Manufacturer"); + diskDrive.Model = (string)diskResult.GetPropertyValue("Model"); + diskDrive.MediaType = (string)diskResult.GetPropertyValue("MediaType"); + diskDrive.InterfaceType = (string)diskResult.GetPropertyValue("InterfaceType"); + diskDrive.SerialNumber = (string)diskResult.GetPropertyValue("SerialNumber"); + diskDrive.FirmwareRevision = (string)diskResult.GetPropertyValue("FirmwareRevision"); + diskDrive.Size = (ulong)diskResult.GetPropertyValue("Size"); + + using (var partitionSearcher = new ManagementObjectSearcher($"ASSOCIATORS OF {{Win32_DiskDrive.DeviceID=\"{diskDrive.DeviceID.Replace(@"\", @"\\")}\"}} WHERE AssocClass = Win32_DiskDriveToDiskPartition")) + { + using (var partitionResults = partitionSearcher.Get()) + { + if (partitionResults.Count > 0) + { + var partitions = new List(partitionResults.Count); + foreach (var partitionResult in partitionResults.Cast()) + { + if (partitionResult != null) + { + var partition = new DiskDrivePartition(); + + partition.DeviceID = (string)partitionResult.GetPropertyValue("DeviceID"); + partition.Bootable = (bool)partitionResult.GetPropertyValue("Bootable"); + partition.BootPartition = (bool)partitionResult.GetPropertyValue("BootPartition"); + partition.PrimaryParition = (bool)partitionResult.GetPropertyValue("PrimaryPartition"); + partition.Size = (ulong)partitionResult.GetPropertyValue("Size"); + partition.StartingOffset = (ulong)partitionResult.GetPropertyValue("StartingOffset"); + partition.Type = (string)partitionResult.GetPropertyValue("Type"); + + using (var logicalSearcher = new ManagementObjectSearcher($"ASSOCIATORS OF {{Win32_DiskPartition.DeviceID=\"{partition.DeviceID}\"}} WHERE AssocClass = Win32_LogicalDiskToPartition")) + { + using (var logicalResults = logicalSearcher.Get()) + { + if (logicalResults.Count > 0) + { + foreach (var logicalResult in logicalResults.Cast().Take(1)) + { + if (logicalResult != null) + { + var logical = new DiskLogical(); + + logical.DeviceID = (string)logicalResult.GetPropertyValue("DeviceID"); + logical.Description = (string)logicalResult.GetPropertyValue("Description"); + var driveType = (uint)logicalResult.GetPropertyValue("DriveType"); + logical.DriveType = Enum.GetName(typeof(DiskLogicalDriveTypes), driveType) ?? $"Unknown {driveType}"; + var mediaType = (uint)logicalResult.GetPropertyValue("MediaType"); + logical.MediaType = Enum.GetName(typeof(DiskLogicalMediaTypes), mediaType) ?? $"Unknown {mediaType}"; + logical.FileSystem = (string)logicalResult.GetPropertyValue("FileSystem"); + logical.Size = (ulong)logicalResult.GetPropertyValue("Size"); + logical.FreeSpace = (ulong)logicalResult.GetPropertyValue("FreeSpace"); + logical.VolumeName = (string)logicalResult.GetPropertyValue("VolumeName"); + logical.VolumeSerialNumber = (string)logicalResult.GetPropertyValue("VolumeSerialNumber"); + + partition.LogicalDisk = logical; + } + } + } + } + } + + partitions.Add(partition); + } + } + diskDrive.Partitions = partitions; + } + } + } + + diskDrives.Add(diskDrive); + } + } + + deviceHardware.DiskDrives = diskDrives; + } + } + } + } + catch (Exception) + { + // ignore errors to ensure backwards compatibility + } + } + + private static void ApplyBIOSInformation(this DeviceHardware deviceHardware) { try { @@ -62,16 +249,16 @@ namespace Disco.Client.Interop var serialNumber = (string)mItem.GetPropertyValue("SerialNumber"); if (!string.IsNullOrWhiteSpace(serialNumber)) { - DeviceHardware.SerialNumber = serialNumber.Trim(); + deviceHardware.SerialNumber = serialNumber.Trim(); } var manufacturer = (string)mItem.GetPropertyValue("Manufacturer"); - if (DeviceHardware.Manufacturer == null && !string.IsNullOrWhiteSpace(manufacturer)) + if (deviceHardware.Manufacturer == null && !string.IsNullOrWhiteSpace(manufacturer)) { - DeviceHardware.Manufacturer = manufacturer.Trim(); + deviceHardware.Manufacturer = manufacturer.Trim(); } - ErrorReporting.DeviceIdentifier = DeviceHardware.SerialNumber; + ErrorReporting.DeviceIdentifier = deviceHardware.SerialNumber; } else { @@ -87,7 +274,7 @@ namespace Disco.Client.Interop } } - private static void ApplySystemInformation(this DeviceHardware DeviceHardware) + private static void ApplySystemInformation(this DeviceHardware deviceHardware) { try { @@ -102,16 +289,16 @@ namespace Disco.Client.Interop var manufacturer = (string)mItem.GetPropertyValue("Manufacturer"); if (!string.IsNullOrWhiteSpace(manufacturer)) { - DeviceHardware.Manufacturer = manufacturer.Trim(); + deviceHardware.Manufacturer = manufacturer.Trim(); } var model = (string)mItem.GetPropertyValue("Model"); if (!string.IsNullOrWhiteSpace(model)) { - DeviceHardware.Model = model.ToString(); + deviceHardware.Model = model.ToString(); } - DeviceHardware.ModelType = ((PCSystemTypes)mItem.GetPropertyValue("PCSystemType")).Description(); + deviceHardware.ModelType = ((PCSystemTypes)mItem.GetPropertyValue("PCSystemType")).Description(); } else { @@ -127,7 +314,7 @@ namespace Disco.Client.Interop } } - public static void ApplySystemInformation(this Enrol Enrol) + public static void ApplySystemInformation(this Enrol enrol) { try { @@ -139,11 +326,11 @@ namespace Disco.Client.Interop { if (mItem != null) { - Enrol.IsPartOfDomain = (bool)mItem.GetPropertyValue("PartOfDomain"); + enrol.IsPartOfDomain = (bool)mItem.GetPropertyValue("PartOfDomain"); - if (Enrol.IsPartOfDomain) + if (enrol.IsPartOfDomain) { - Enrol.DNSDomainName = (string)mItem.GetPropertyValue("Domain"); + enrol.DNSDomainName = (string)mItem.GetPropertyValue("Domain"); } } else @@ -160,7 +347,7 @@ namespace Disco.Client.Interop } } - private static void ApplyBaseBoardInformation(this DeviceHardware DeviceHardware) + private static void ApplyBaseBoardInformation(this DeviceHardware deviceHardware) { try { @@ -174,34 +361,34 @@ namespace Disco.Client.Interop { // Apply Manufacturer/Model information only if not previously found in Win32_ComputerSystem var manufacturer = (string)mItem.GetPropertyValue("Manufacturer"); - if (DeviceHardware.Manufacturer == null && !string.IsNullOrWhiteSpace(manufacturer)) + if (deviceHardware.Manufacturer == null && !string.IsNullOrWhiteSpace(manufacturer)) { - DeviceHardware.Manufacturer = manufacturer.Trim(); + deviceHardware.Manufacturer = manufacturer.Trim(); } var model = (string)mItem.GetPropertyValue("Model"); - if (DeviceHardware.Model == null && !string.IsNullOrWhiteSpace(model)) + if (deviceHardware.Model == null && !string.IsNullOrWhiteSpace(model)) { - DeviceHardware.Model = model.ToString(); + deviceHardware.Model = model.ToString(); } var product = (string)mItem.GetPropertyValue("Product"); - if (DeviceHardware.Model == null && !string.IsNullOrWhiteSpace(product)) + if (deviceHardware.Model == null && !string.IsNullOrWhiteSpace(product)) { - DeviceHardware.Model = product.ToString(); + deviceHardware.Model = product.ToString(); } // Added 2012-11-22 G# - Lenovo IdeaPad Serial SHIM // http://www.discoict.com.au/forum/feature-requests/2012/11/serial-number-detection-on-ideapads.aspx var serialNumber = (string)mItem.GetPropertyValue("SerialNumber"); if (!string.IsNullOrWhiteSpace(serialNumber) && - (DeviceHardware.SerialNumber == null || - ((DeviceHardware.Manufacturer?.Equals("LENOVO", StringComparison.OrdinalIgnoreCase) ?? false) && - ((DeviceHardware.Model?.Equals("S10-3", StringComparison.OrdinalIgnoreCase) ?? false) // S10-3 - || (DeviceHardware.Model?.Equals("2957", StringComparison.OrdinalIgnoreCase) ?? false))))) + (deviceHardware.SerialNumber == null || + ((deviceHardware.Manufacturer?.Equals("LENOVO", StringComparison.OrdinalIgnoreCase) ?? false) && + ((deviceHardware.Model?.Equals("S10-3", StringComparison.OrdinalIgnoreCase) ?? false) // S10-3 + || (deviceHardware.Model?.Equals("2957", StringComparison.OrdinalIgnoreCase) ?? false))))) { - DeviceHardware.SerialNumber = serialNumber.Trim(); - ErrorReporting.DeviceIdentifier = DeviceHardware.SerialNumber; + deviceHardware.SerialNumber = serialNumber.Trim(); + ErrorReporting.DeviceIdentifier = deviceHardware.SerialNumber; } } else @@ -218,7 +405,7 @@ namespace Disco.Client.Interop } } - private static void ApplySystemProductInformation(this DeviceHardware DeviceHardware) + private static void ApplySystemProductInformation(this DeviceHardware deviceHardware) { try { @@ -230,28 +417,28 @@ namespace Disco.Client.Interop { if (mItem != null) { - if (DeviceHardware.SerialNumber == null) + if (deviceHardware.SerialNumber == null) { var serialNumber = mItem.GetPropertyValue("IdentifyingNumber") as string; if (!string.IsNullOrWhiteSpace(serialNumber)) { - DeviceHardware.SerialNumber = serialNumber.Trim(); - ErrorReporting.DeviceIdentifier = DeviceHardware.SerialNumber; + deviceHardware.SerialNumber = serialNumber.Trim(); + ErrorReporting.DeviceIdentifier = deviceHardware.SerialNumber; } } var uUID = (string)mItem.GetPropertyValue("UUID"); if (!string.IsNullOrWhiteSpace(uUID)) { - DeviceHardware.UUID = uUID.Trim(); + deviceHardware.UUID = uUID.Trim(); // if serial number is absent attempt using UUID if valid - if (string.IsNullOrWhiteSpace(DeviceHardware.SerialNumber)) + if (string.IsNullOrWhiteSpace(deviceHardware.SerialNumber)) { Guid uuidGuid; - if (Guid.TryParse(DeviceHardware.UUID, out uuidGuid) && uuidGuid != Guid.Empty) + if (Guid.TryParse(deviceHardware.UUID, out uuidGuid) && uuidGuid != Guid.Empty) { - DeviceHardware.SerialNumber = $"UUID{uuidGuid:N}"; + deviceHardware.SerialNumber = $"UUID{uuidGuid:N}"; } } } @@ -308,5 +495,56 @@ namespace Disco.Client.Interop PerformanceServer, Maximum } + + private enum ProcessorArchitectures : ushort + { + x86 = 0, + MIPS = 1, + Alpha = 2, + PowerPC = 3, + ia64 = 6, + x64 = 9, + } + + private enum DiskLogicalDriveTypes : uint + { + Unknown = 0, + NoRootDirectory, + Removable, + Fixed, + Remote, + CDRom, + RAMDisk, + } + + private enum DiskLogicalMediaTypes : uint + { + Unknown = 0, + F5_1Pt2_512, + F3_1Pt44_512, + F3_2Pt88_512, + F3_20Pt8_512, + F3_720_512, + F5_360_512, + F5_320_512, + F5_320_1024, + F5_180_512, + F5_160_512, + RemovableMedia, + FixedMedia, + F3_120M_512, + F3_640_512, + F5_640_512, + F5_720_512, + F3_1Pt2_512, + F3_1Pt23_1024, + F5_1Pt23_1024, + F3_128Mb_512, + F3_230Mb_512, + F8_256_128, + F3_200Mb_512, + F3_240M_512, + F3_32M_512, + } } } diff --git a/Disco.Models/ClientServices/EnrolmentInformation/DiskDrive.cs b/Disco.Models/ClientServices/EnrolmentInformation/DiskDrive.cs index f4f23d6d..1e84e74e 100644 --- a/Disco.Models/ClientServices/EnrolmentInformation/DiskDrive.cs +++ b/Disco.Models/ClientServices/EnrolmentInformation/DiskDrive.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace Disco.Models.ClientServices.EnrolmentInformation { @@ -12,7 +11,6 @@ namespace Disco.Models.ClientServices.EnrolmentInformation public string InterfaceType { get; set; } public string SerialNumber { get; set; } public string FirmwareRevision { get; set; } - public DateTime InstallDate { get; set; } public ulong Size { get; set; } public List Partitions { get; set; } diff --git a/Disco.Models/ClientServices/EnrolmentInformation/DiskDrivePartition.cs b/Disco.Models/ClientServices/EnrolmentInformation/DiskDrivePartition.cs index 8a0f07a7..526cdb9b 100644 --- a/Disco.Models/ClientServices/EnrolmentInformation/DiskDrivePartition.cs +++ b/Disco.Models/ClientServices/EnrolmentInformation/DiskDrivePartition.cs @@ -1,16 +1,15 @@ -using System.Collections.Generic; - -namespace Disco.Models.ClientServices.EnrolmentInformation +namespace Disco.Models.ClientServices.EnrolmentInformation { public class DiskDrivePartition { - public bool DeviceID { get; set; } + public string DeviceID { get; set; } public bool Bootable { get; set; } public bool BootPartition { get; set; } public bool PrimaryParition { get; set; } public ulong Size { get; set; } public ulong StartingOffset { get; set; } + public string Type { get; set; } - public List LogicalDisks { get; set; } + public DiskLogical LogicalDisk { get; set; } } } diff --git a/Disco.Models/ClientServices/EnrolmentInformation/DiskLogical.cs b/Disco.Models/ClientServices/EnrolmentInformation/DiskLogical.cs index 56b45bad..f8667535 100644 --- a/Disco.Models/ClientServices/EnrolmentInformation/DiskLogical.cs +++ b/Disco.Models/ClientServices/EnrolmentInformation/DiskLogical.cs @@ -1,23 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Disco.Models.ClientServices.EnrolmentInformation +namespace Disco.Models.ClientServices.EnrolmentInformation { public class DiskLogical { - public string DeviceID { get; set; } public string Description { get; set; } - public int DriveType { get; set; } - public int MediaType { get; set; } + public string DriveType { get; set; } + public string MediaType { get; set; } public string FileSystem { get; set; } public ulong Size { get; set; } public ulong FreeSpace { get; set; } public string VolumeName { get; set; } public string VolumeSerialNumber { get; set; } - } } diff --git a/Disco.Models/ClientServices/EnrolmentInformation/PhysicalMemory.cs b/Disco.Models/ClientServices/EnrolmentInformation/PhysicalMemory.cs index 7ebe7e62..775076b2 100644 --- a/Disco.Models/ClientServices/EnrolmentInformation/PhysicalMemory.cs +++ b/Disco.Models/ClientServices/EnrolmentInformation/PhysicalMemory.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Disco.Models.ClientServices.EnrolmentInformation +namespace Disco.Models.ClientServices.EnrolmentInformation { public class PhysicalMemory { @@ -14,10 +8,9 @@ namespace Disco.Models.ClientServices.EnrolmentInformation public string PartNumber { get; set; } public ulong Capacity { get; set; } - public int ClockSpeed { get; set; } - public int Voltage { get; set; } - - public string Location { get; set; } + public uint ConfiguredClockSpeed { get; set; } + public uint Speed { get; set; } + public string DeviceLocator { get; set; } } } diff --git a/Disco.Models/ClientServices/EnrolmentInformation/Processor.cs b/Disco.Models/ClientServices/EnrolmentInformation/Processor.cs index f4d0eb1f..2e3a4db6 100644 --- a/Disco.Models/ClientServices/EnrolmentInformation/Processor.cs +++ b/Disco.Models/ClientServices/EnrolmentInformation/Processor.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Disco.Models.ClientServices.EnrolmentInformation +namespace Disco.Models.ClientServices.EnrolmentInformation { public class Processor { @@ -13,9 +7,9 @@ namespace Disco.Models.ClientServices.EnrolmentInformation public string Name { get; set; } public string Description { get; set; } public string Architecture { get; set; } - public short Family { get; set; } - public int MaxClockSpeed { get; set; } - public int NumberOfCores { get; set; } - public int NumberOfLogicalProcessors { get; set; } + public ushort Family { get; set; } + public uint MaxClockSpeed { get; set; } + public uint NumberOfCores { get; set; } + public uint NumberOfLogicalProcessors { get; set; } } } diff --git a/Disco.Models/Repository/Device/DeviceDetail.cs b/Disco.Models/Repository/Device/DeviceDetail.cs index 66288ce5..4c9da984 100644 --- a/Disco.Models/Repository/Device/DeviceDetail.cs +++ b/Disco.Models/Repository/Device/DeviceDetail.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace Disco.Models.Repository @@ -16,6 +12,10 @@ namespace Disco.Models.Repository public const string HardwareKeyACAdapter = "ACAdapter"; public const string HardwareKeyBattery = "Battery"; public const string HardwareKeyKeyboard = "Keyboard"; + public const string HardwareKeyNetworkAdapters = "NetworkAdapters"; + public const string HardwareKeyProcessors = "Processors"; + public const string HardwareKeyPhysicalMemory = "PhysicalMemory"; + public const string HardwareKeyDiskDrives = "DiskDrives"; [Column(Order = 0), Key] public string DeviceSerialNumber { get; set; } diff --git a/Disco.Services/Devices/DeviceDetailExtensions.cs b/Disco.Services/Devices/DeviceDetailExtensions.cs index a123bb25..5329698e 100644 --- a/Disco.Services/Devices/DeviceDetailExtensions.cs +++ b/Disco.Services/Devices/DeviceDetailExtensions.cs @@ -1,4 +1,6 @@ -using Disco.Models.Repository; +using Disco.Models.ClientServices.EnrolmentInformation; +using Disco.Models.Repository; +using Exceptionless.Json; using System; using System.Collections.Generic; using System.Linq; @@ -155,5 +157,106 @@ namespace Disco.Services device.SetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyKeyboard, Keyboard); } #endregion + + /// + /// Gets the Network Adapters Device Detail Value + /// + public static List NetworkAdapters(this IEnumerable details) + { + var json = details.GetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyNetworkAdapters); + + if (string.IsNullOrEmpty(json)) + return null; + + return JsonConvert.DeserializeObject>(json); + } + /// + /// Sets the Network Adapters Device Detail Value + /// + public static void NetworkAdapters(this IEnumerable details, Device device, List networkAdapters) + { + var json = default(string); + + if (networkAdapters != null && networkAdapters.Count > 0) + json = JsonConvert.SerializeObject(networkAdapters); + + device.SetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyNetworkAdapters, json); + } + + /// + /// Gets the Processors Device Detail Value + /// + public static List Processors(this IEnumerable details) + { + var json = details.GetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyProcessors); + + if (string.IsNullOrEmpty(json)) + return null; + + return JsonConvert.DeserializeObject>(json); + } + /// + /// Sets the Processors Device Detail Value + /// + public static void Processors(this IEnumerable details, Device device, List processors) + { + var json = default(string); + + if (processors != null && processors.Count > 0) + json = JsonConvert.SerializeObject(processors); + + device.SetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyProcessors, json); + } + + /// + /// Gets the Physical Memory Device Detail Value + /// + public static List PhysicalMemory(this IEnumerable details) + { + var json = details.GetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyPhysicalMemory); + + if (string.IsNullOrEmpty(json)) + return null; + + return JsonConvert.DeserializeObject>(json); + } + /// + /// Sets the Physical Memory Device Detail Value + /// + public static void PhysicalMemory(this IEnumerable details, Device device, List physicalMemory) + { + var json = default(string); + + if (physicalMemory != null && physicalMemory.Count > 0) + json = JsonConvert.SerializeObject(physicalMemory); + + device.SetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyPhysicalMemory, json); + } + + /// + /// Gets the Disk Drives Device Detail Value + /// + public static List DiskDrives(this IEnumerable details) + { + var json = details.GetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyDiskDrives); + + if (string.IsNullOrEmpty(json)) + return null; + + return JsonConvert.DeserializeObject>(json); + } + /// + /// Sets the Disk Drives Device Detail Value + /// + public static void DiskDrives(this IEnumerable details, Device device, List diskDrives) + { + var json = default(string); + + if (diskDrives != null && diskDrives.Count > 0) + json = JsonConvert.SerializeObject(diskDrives); + + device.SetDetail(DeviceDetail.ScopeHardware, DeviceDetail.HardwareKeyDiskDrives, json); + } + } } diff --git a/Disco.Services/Devices/Enrolment/DeviceEnrolment.cs b/Disco.Services/Devices/Enrolment/DeviceEnrolment.cs index c9d04cbb..b5d2c880 100644 --- a/Disco.Services/Devices/Enrolment/DeviceEnrolment.cs +++ b/Disco.Services/Devices/Enrolment/DeviceEnrolment.cs @@ -453,6 +453,16 @@ namespace Disco.Services.Devices.Enrolment RepoDevice.LastEnrolDate = DateTime.Now; } + // store hardware audit information + if (Request.Hardware.Processors?.Count > 0) + RepoDevice.DeviceDetails.Processors(RepoDevice, Request.Hardware.Processors); + if (Request.Hardware.PhysicalMemory?.Count > 0) + RepoDevice.DeviceDetails.PhysicalMemory(RepoDevice, Request.Hardware.PhysicalMemory); + if (Request.Hardware.DiskDrives?.Count > 0) + RepoDevice.DeviceDetails.DiskDrives(RepoDevice, Request.Hardware.DiskDrives); + if (Request.Hardware.NetworkAdapters?.Count > 0) + RepoDevice.DeviceDetails.NetworkAdapters(RepoDevice, Request.Hardware.NetworkAdapters); + if (adMachineAccount == null) { if (RepoDevice.DeviceProfile.ProvisionADAccount)