WMIProvider/Sensor.cs
author paulwerelds
Sat, 16 Oct 2010 13:29:06 +0000
changeset 223 39f73ac8c2f4
child 224 be9534663a55
permissions -rw-r--r--
Added a WMI provider, documentation to follow.
paulwerelds@223
     1
using System.Management.Instrumentation;
paulwerelds@223
     2
using OpenHardwareMonitor.Hardware;
paulwerelds@223
     3
paulwerelds@223
     4
namespace OpenHardwareMonitor.WMIProvider {
paulwerelds@223
     5
  [InstrumentationClass(InstrumentationType.Instance)]
paulwerelds@223
     6
  public class Sensor : IWmiClass {
paulwerelds@223
     7
paulwerelds@223
     8
    private ISensor _sensor;
paulwerelds@223
     9
paulwerelds@223
    10
    public string SensorType { get; private set; }
paulwerelds@223
    11
    public string Identifier { get; private set; }
paulwerelds@223
    12
    public string Parent { get; private set; }
paulwerelds@223
    13
    public string Name { get; private set; }
paulwerelds@223
    14
    public float Value { get; private set; }
paulwerelds@223
    15
    public float Min { get; private set; }
paulwerelds@223
    16
    public float Max { get; private set; }
paulwerelds@223
    17
    public int Index { get; private set; }
paulwerelds@223
    18
paulwerelds@223
    19
    public Sensor(ISensor sensor) {
paulwerelds@223
    20
      Name = sensor.Name;
paulwerelds@223
    21
      Index = sensor.Index;
paulwerelds@223
    22
paulwerelds@223
    23
      SensorType = sensor.SensorType.ToString();
paulwerelds@223
    24
      Identifier = sensor.Identifier.ToString();
paulwerelds@223
    25
      Parent = sensor.Hardware.Identifier.ToString();
paulwerelds@223
    26
paulwerelds@223
    27
      _sensor = sensor;
paulwerelds@223
    28
    }
paulwerelds@223
    29
    
paulwerelds@223
    30
    public void Update() {
paulwerelds@223
    31
      Value = (_sensor.Value != null) ? (float)_sensor.Value : 0;
paulwerelds@223
    32
paulwerelds@223
    33
      if (_sensor.Min != null)
paulwerelds@223
    34
        Min = (float)_sensor.Min;
paulwerelds@223
    35
paulwerelds@223
    36
      if (_sensor.Max != null)
paulwerelds@223
    37
        Max = (float)_sensor.Max;
paulwerelds@223
    38
    }
paulwerelds@223
    39
  }
paulwerelds@223
    40
}