/// <summary>Reloads the hardware informations.</summary> public void Reload(bool usecache = false) { if (usecache && _isCollected) return; try { var moc = new ManagementObjectSearcher("SELECT * FROM Win32_Printer").Get(); new ListAssimilator<ManagementObject, PrinterDevice>(moc.OfType<ManagementObject>(), _printerDevices) { OnPairFound = (o, device) => device.Load(o), EqualFunc = (o, device) => device.Name == o.TryGet<string>("Name"), CreateFunc = o => PrinterDevice.FromManagementObject(o) }.Execute(); } catch (Exception) { } _isCollected = true; }
/// <summary>Reloads all the items in <see cref="Devices" /> list.</summary> /// <param name="usecache">if true the WMI will only be queried if it haven't been done before.</param> public void Reload(bool usecache = false) { if (usecache && _isCollected) return; try { var moc = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController").Get(); new ListAssimilator<ManagementObject, CsgGraphicDevice>(moc.OfType<ManagementObject>(), _devices) { CreateFunc = o => CsgGraphicDevice.FromManagementObject(o), EqualFunc = (o, device) => device.DeviceId == o.TryGet<string>("DeviceID"), OnPairFound = (o, device) => device.Load(o) }.Execute(); } catch (Exception) { _devices.Clear(); } _isCollected = true; }
/// <summary>Reloads all the items in <see cref="Devices" /> list.</summary> /// <param name="usecache">if true the WMI will only be queried if it haven't been done before.</param> public void Reload(bool usecache = false) { if (usecache && _isCollected) return; try { var moc = new ManagementObjectSearcher("ROOT\\StandardCimv2", "SELECT * FROM MSFT_NetAdapter WHERE HardwareInterface='True'").Get(); new ListAssimilator<ManagementObject, CsgNetworkDevice>(moc.OfType<ManagementObject>(), _devices) { CreateFunc = o => CsgNetworkDevice.FromManagementObject(o), EqualFunc = (o, device) => device.DeviceId == o.TryGet<string>("DeviceID"), OnPairFound = (o, device) => device.Load(o), }.Execute(); } catch (Exception) { _devices.Clear(); } _isCollected = true; }
private void CollectDiscDrives(bool useCache = false) { if (useCache && _isDiscDrivesCollected) return; try { var moc = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive").Get(); new ListAssimilator<ManagementObject, CsgDiskDriveDevice>(moc.OfType<ManagementObject>().ToList(), _devices) { CreateFunc = mo => CsgDiskDriveDevice.FromManagementObject(mo), EqualFunc = (mo, device) => device.DeviceId == mo.TryGet<string>("DeviceID"), OnPairFound = (mo, device) => device.Load(mo) }.Execute(); } catch (Exception) { _devices.Clear(); } _isDiscDrivesCollected = true; }
internal void CollectDiscPartitions(bool useCache = false) { if (useCache && _isDiscPartitionsCollected) return; CollectDiscDrives(true); try { var moc = new ManagementObjectSearcher("SELECT * FROM Win32_DiskPartition").Get(); var groupedPartitions = moc.OfType<ManagementObject>().GroupBy(x => x.TryGet<UInt32>("DiskIndex")).ToArray(); foreach (var groupedPartition in groupedPartitions) { var device = Devices.FirstOrDefault(x => x.Index == groupedPartition.Key); if (device == null) continue; try { new ListAssimilator<ManagementObject, CsgDiskPartition>(groupedPartition.ToList(), device._partitions) { CreateFunc = mo => CsgDiskPartition.FromManagementObject(mo), EqualFunc = (mo, partition) => partition.DeviceId == mo.TryGet<string>("DeviceID"), OnPairFound = (mo, partition) => partition.Load(mo) }.Execute(); } catch (Exception) { device._partitions.Clear(); } } } catch (Exception) { foreach (var device in Devices) { device._partitions.Clear(); } } _isDiscPartitionsCollected = true; }