mirror of
https://github.com/ckaczor/SystemTemperatureStatusWindow.git
synced 2026-01-14 01:25:42 -05:00
Split into service and UI
This commit is contained in:
60
Service/SystemTemperatureService.cs
Normal file
60
Service/SystemTemperatureService.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using OpenHardwareMonitor.Hardware;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SystemTemperatureService
|
||||
{
|
||||
public class SystemTemperatureService : ISystemTemperatureService
|
||||
{
|
||||
private static Computer _computer;
|
||||
|
||||
public List<Device> GetDeviceList()
|
||||
{
|
||||
if (_computer == null)
|
||||
{
|
||||
_computer = new Computer { HDDEnabled = true, FanControllerEnabled = false, GPUEnabled = true, MainboardEnabled = true, CPUEnabled = true };
|
||||
_computer.Open();
|
||||
}
|
||||
|
||||
var deviceList = new List<Device>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user