using OpenHardwareMonitor.Hardware; using System.Collections.Generic; using System.Linq; namespace SystemTemperatureService { public class SystemTemperatureService : ISystemTemperatureService { private static Computer _computer; public List GetDeviceList() { if (_computer == null) { _computer = new Computer { HDDEnabled = true, FanControllerEnabled = false, GPUEnabled = true, MainboardEnabled = true, CPUEnabled = true }; _computer.Open(); } var deviceList = new List(); foreach (var hardware in _computer.Hardware) { hardware.Update(); var averageValue = hardware.Sensors.Where(sensor => sensor.SensorType == SensorType.Temperature).Average(sensor => sensor.Value); if (averageValue.HasValue) { Device device = null; switch (hardware.HardwareType) { case HardwareType.CPU: device = new Device { Type = DeviceType.Cpu }; break; case HardwareType.GpuAti: case HardwareType.GpuNvidia: device = new Device { Type = DeviceType.Gpu }; break; case HardwareType.HDD: device = new Device { Type = DeviceType.Hdd }; break; } if (device != null) { device.Id = hardware.Identifier.ToString(); device.Temperature = averageValue.Value; } deviceList.Add(device); } } return deviceList; } } }