Renamed folder Wmi to WMI.
authormoel.mich
Sun, 17 Oct 2010 16:10:08 +0000
changeset 229940d86b60be7
parent 228 458a6c3de579
child 230 9abe65430da1
Renamed folder Wmi to WMI.
WMI/Hardware.cs
WMI/IWmiObject.cs
WMI/Sensor.cs
WMI/WmiProvider.cs
Wmi/Hardware.cs
Wmi/IWmiObject.cs
Wmi/Sensor.cs
Wmi/WmiProvider.cs
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/WMI/Hardware.cs	Sun Oct 17 16:10:08 2010 +0000
     1.3 @@ -0,0 +1,60 @@
     1.4 +/*
     1.5 +  
     1.6 +  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     1.7 +
     1.8 +  The contents of this file are subject to the Mozilla Public License Version
     1.9 +  1.1 (the "License"); you may not use this file except in compliance with
    1.10 +  the License. You may obtain a copy of the License at
    1.11 + 
    1.12 +  http://www.mozilla.org/MPL/
    1.13 +
    1.14 +  Software distributed under the License is distributed on an "AS IS" basis,
    1.15 +  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    1.16 +  for the specific language governing rights and limitations under the License.
    1.17 +
    1.18 +  The Original Code is the Open Hardware Monitor code.
    1.19 +
    1.20 +  The Initial Developer of the Original Code is 
    1.21 +  Paul Werelds <paul@werelds.net>.
    1.22 +  Portions created by the Initial Developer are Copyright (C) 2009-2010
    1.23 +  the Initial Developer. All Rights Reserved.
    1.24 +
    1.25 +  Contributor(s):
    1.26 +
    1.27 +  Alternatively, the contents of this file may be used under the terms of
    1.28 +  either the GNU General Public License Version 2 or later (the "GPL"), or
    1.29 +  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    1.30 +  in which case the provisions of the GPL or the LGPL are applicable instead
    1.31 +  of those above. If you wish to allow use of your version of this file only
    1.32 +  under the terms of either the GPL or the LGPL, and not to allow others to
    1.33 +  use your version of this file under the terms of the MPL, indicate your
    1.34 +  decision by deleting the provisions above and replace them with the notice
    1.35 +  and other provisions required by the GPL or the LGPL. If you do not delete
    1.36 +  the provisions above, a recipient may use your version of this file under
    1.37 +  the terms of any one of the MPL, the GPL or the LGPL.
    1.38 + 
    1.39 +*/
    1.40 +
    1.41 +using System.Management.Instrumentation;
    1.42 +using OpenHardwareMonitor.Hardware;
    1.43 +
    1.44 +namespace OpenHardwareMonitor.WMI {
    1.45 +  [InstrumentationClass(InstrumentationType.Instance)]
    1.46 +  public class Hardware : IWmiObject {
    1.47 +    #region WMI Exposed
    1.48 +    
    1.49 +    public string HardwareType { get; private set; }
    1.50 +    public string Identifier { get; private set; }
    1.51 +    public string Name { get; private set; }
    1.52 +
    1.53 +    #endregion
    1.54 +
    1.55 +    public Hardware(IHardware hardware) {
    1.56 +      Name = hardware.Name;
    1.57 +      Identifier = hardware.Identifier.ToString();
    1.58 +      HardwareType = hardware.HardwareType.ToString();
    1.59 +    }
    1.60 +
    1.61 +    public void Update() { }
    1.62 +  }
    1.63 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/WMI/IWmiObject.cs	Sun Oct 17 16:10:08 2010 +0000
     2.3 @@ -0,0 +1,47 @@
     2.4 +/*
     2.5 +  
     2.6 +  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     2.7 +
     2.8 +  The contents of this file are subject to the Mozilla Public License Version
     2.9 +  1.1 (the "License"); you may not use this file except in compliance with
    2.10 +  the License. You may obtain a copy of the License at
    2.11 + 
    2.12 +  http://www.mozilla.org/MPL/
    2.13 +
    2.14 +  Software distributed under the License is distributed on an "AS IS" basis,
    2.15 +  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    2.16 +  for the specific language governing rights and limitations under the License.
    2.17 +
    2.18 +  The Original Code is the Open Hardware Monitor code.
    2.19 +
    2.20 +  The Initial Developer of the Original Code is 
    2.21 +  Paul Werelds <paul@werelds.net>.
    2.22 +  Portions created by the Initial Developer are Copyright (C) 2009-2010
    2.23 +  the Initial Developer. All Rights Reserved.
    2.24 +
    2.25 +  Contributor(s):
    2.26 +
    2.27 +  Alternatively, the contents of this file may be used under the terms of
    2.28 +  either the GNU General Public License Version 2 or later (the "GPL"), or
    2.29 +  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    2.30 +  in which case the provisions of the GPL or the LGPL are applicable instead
    2.31 +  of those above. If you wish to allow use of your version of this file only
    2.32 +  under the terms of either the GPL or the LGPL, and not to allow others to
    2.33 +  use your version of this file under the terms of the MPL, indicate your
    2.34 +  decision by deleting the provisions above and replace them with the notice
    2.35 +  and other provisions required by the GPL or the LGPL. If you do not delete
    2.36 +  the provisions above, a recipient may use your version of this file under
    2.37 +  the terms of any one of the MPL, the GPL or the LGPL.
    2.38 + 
    2.39 +*/
    2.40 +
    2.41 +namespace OpenHardwareMonitor.WMI {
    2.42 +  interface IWmiObject {
    2.43 +    // Both of these get exposed to WMI
    2.44 +    string Name { get; }
    2.45 +    string Identifier { get; }
    2.46 +
    2.47 +    // Not exposed.
    2.48 +    void Update();
    2.49 +  }
    2.50 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/WMI/Sensor.cs	Sun Oct 17 16:10:08 2010 +0000
     3.3 @@ -0,0 +1,80 @@
     3.4 +/*
     3.5 +  
     3.6 +  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     3.7 +
     3.8 +  The contents of this file are subject to the Mozilla Public License Version
     3.9 +  1.1 (the "License"); you may not use this file except in compliance with
    3.10 +  the License. You may obtain a copy of the License at
    3.11 + 
    3.12 +  http://www.mozilla.org/MPL/
    3.13 +
    3.14 +  Software distributed under the License is distributed on an "AS IS" basis,
    3.15 +  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    3.16 +  for the specific language governing rights and limitations under the License.
    3.17 +
    3.18 +  The Original Code is the Open Hardware Monitor code.
    3.19 +
    3.20 +  The Initial Developer of the Original Code is 
    3.21 +  Paul Werelds <paul@werelds.net>.
    3.22 +  Portions created by the Initial Developer are Copyright (C) 2009-2010
    3.23 +  the Initial Developer. All Rights Reserved.
    3.24 +
    3.25 +  Contributor(s):
    3.26 +
    3.27 +  Alternatively, the contents of this file may be used under the terms of
    3.28 +  either the GNU General Public License Version 2 or later (the "GPL"), or
    3.29 +  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    3.30 +  in which case the provisions of the GPL or the LGPL are applicable instead
    3.31 +  of those above. If you wish to allow use of your version of this file only
    3.32 +  under the terms of either the GPL or the LGPL, and not to allow others to
    3.33 +  use your version of this file under the terms of the MPL, indicate your
    3.34 +  decision by deleting the provisions above and replace them with the notice
    3.35 +  and other provisions required by the GPL or the LGPL. If you do not delete
    3.36 +  the provisions above, a recipient may use your version of this file under
    3.37 +  the terms of any one of the MPL, the GPL or the LGPL.
    3.38 + 
    3.39 +*/
    3.40 +
    3.41 +using System.Management.Instrumentation;
    3.42 +using OpenHardwareMonitor.Hardware;
    3.43 +
    3.44 +namespace OpenHardwareMonitor.WMI {
    3.45 +  [InstrumentationClass(InstrumentationType.Instance)]
    3.46 +  public class Sensor : IWmiObject {
    3.47 +    private ISensor sensor;
    3.48 +
    3.49 +    #region WMI Exposed
    3.50 +
    3.51 +    public string SensorType { get; private set; }
    3.52 +    public string Identifier { get; private set; }
    3.53 +    public string Parent { get; private set; }
    3.54 +    public string Name { get; private set; }
    3.55 +    public float Value { get; private set; }
    3.56 +    public float Min { get; private set; }
    3.57 +    public float Max { get; private set; }
    3.58 +    public int Index { get; private set; }
    3.59 +
    3.60 +    #endregion
    3.61 +
    3.62 +    public Sensor(ISensor sensor) {
    3.63 +      Name = sensor.Name;
    3.64 +      Index = sensor.Index;
    3.65 +
    3.66 +      SensorType = sensor.SensorType.ToString();
    3.67 +      Identifier = sensor.Identifier.ToString();
    3.68 +      Parent = sensor.Hardware.Identifier.ToString();
    3.69 +
    3.70 +      this.sensor = sensor;
    3.71 +    }
    3.72 +    
    3.73 +    public void Update() {
    3.74 +      Value = (sensor.Value != null) ? (float)sensor.Value : 0;
    3.75 +
    3.76 +      if (sensor.Min != null)
    3.77 +        Min = (float)sensor.Min;
    3.78 +
    3.79 +      if (sensor.Max != null)
    3.80 +        Max = (float)sensor.Max;
    3.81 +    }
    3.82 +  }
    3.83 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/WMI/WmiProvider.cs	Sun Oct 17 16:10:08 2010 +0000
     4.3 @@ -0,0 +1,141 @@
     4.4 +/*
     4.5 +  
     4.6 +  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     4.7 +
     4.8 +  The contents of this file are subject to the Mozilla Public License Version
     4.9 +  1.1 (the "License"); you may not use this file except in compliance with
    4.10 +  the License. You may obtain a copy of the License at
    4.11 + 
    4.12 +  http://www.mozilla.org/MPL/
    4.13 +
    4.14 +  Software distributed under the License is distributed on an "AS IS" basis,
    4.15 +  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    4.16 +  for the specific language governing rights and limitations under the License.
    4.17 +
    4.18 +  The Original Code is the Open Hardware Monitor code.
    4.19 +
    4.20 +  The Initial Developer of the Original Code is 
    4.21 +  Paul Werelds <paul@werelds.net>.
    4.22 +  Portions created by the Initial Developer are Copyright (C) 2009-2010
    4.23 +  the Initial Developer. All Rights Reserved.
    4.24 +
    4.25 +  Contributor(s):
    4.26 +
    4.27 +  Alternatively, the contents of this file may be used under the terms of
    4.28 +  either the GNU General Public License Version 2 or later (the "GPL"), or
    4.29 +  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    4.30 +  in which case the provisions of the GPL or the LGPL are applicable instead
    4.31 +  of those above. If you wish to allow use of your version of this file only
    4.32 +  under the terms of either the GPL or the LGPL, and not to allow others to
    4.33 +  use your version of this file under the terms of the MPL, indicate your
    4.34 +  decision by deleting the provisions above and replace them with the notice
    4.35 +  and other provisions required by the GPL or the LGPL. If you do not delete
    4.36 +  the provisions above, a recipient may use your version of this file under
    4.37 +  the terms of any one of the MPL, the GPL or the LGPL.
    4.38 + 
    4.39 +*/
    4.40 +
    4.41 +using System;
    4.42 +using System.Collections.Generic;
    4.43 +using System.Management.Instrumentation;
    4.44 +using OpenHardwareMonitor.Hardware;
    4.45 +
    4.46 +[assembly: Instrumented("root/OpenHardwareMonitor")]
    4.47 +
    4.48 +[System.ComponentModel.RunInstaller(true)]
    4.49 +public class InstanceInstaller : DefaultManagementProjectInstaller { }
    4.50 +
    4.51 +namespace OpenHardwareMonitor.WMI {
    4.52 +  /// <summary>
    4.53 +  /// The WMI Provider.
    4.54 +  /// This class is not exposed to WMI itself.
    4.55 +  /// </summary>
    4.56 +  public class WmiProvider : IDisposable {
    4.57 +    private List<IWmiObject> activeInstances;
    4.58 +
    4.59 +    public WmiProvider(IComputer computer) {
    4.60 +      activeInstances = new List<IWmiObject>();
    4.61 +
    4.62 +      foreach (IHardware hardware in computer.Hardware)
    4.63 +        ComputerHardwareAdded(hardware);
    4.64 +
    4.65 +      computer.HardwareAdded += ComputerHardwareAdded;
    4.66 +      computer.HardwareRemoved += ComputerHardwareRemoved;
    4.67 +    }
    4.68 +
    4.69 +    public void Update() {
    4.70 +      foreach (IWmiObject instance in activeInstances)
    4.71 +        instance.Update();
    4.72 +    }
    4.73 +
    4.74 +    #region Eventhandlers
    4.75 +    
    4.76 +    private void ComputerHardwareAdded(IHardware hardware) {
    4.77 +      if (!Exists(hardware.Identifier.ToString())) {
    4.78 +        foreach (ISensor sensor in hardware.Sensors)
    4.79 +          HardwareSensorAdded(sensor);
    4.80 +
    4.81 +        hardware.SensorAdded += HardwareSensorAdded;
    4.82 +        hardware.SensorRemoved += HardwareSensorRemoved;
    4.83 +
    4.84 +        Hardware hw = new Hardware(hardware);
    4.85 +        activeInstances.Add(hw);
    4.86 +
    4.87 +        Instrumentation.Publish(hw);
    4.88 +      }
    4.89 +
    4.90 +      foreach (IHardware subHardware in hardware.SubHardware)
    4.91 +        ComputerHardwareAdded(subHardware);
    4.92 +    }
    4.93 +
    4.94 +    private void HardwareSensorAdded(ISensor data) {
    4.95 +      Sensor sensor = new Sensor(data);
    4.96 +      activeInstances.Add(sensor);
    4.97 +
    4.98 +      Instrumentation.Publish(sensor);
    4.99 +    }
   4.100 +
   4.101 +    private void ComputerHardwareRemoved(IHardware hardware) {
   4.102 +      hardware.SensorAdded -= HardwareSensorAdded;
   4.103 +      hardware.SensorRemoved -= HardwareSensorRemoved;
   4.104 +      
   4.105 +      foreach (ISensor sensor in hardware.Sensors) 
   4.106 +        HardwareSensorRemoved(sensor);
   4.107 +      
   4.108 +      foreach (IHardware subHardware in hardware.SubHardware)
   4.109 +        ComputerHardwareRemoved(subHardware);
   4.110 +
   4.111 +      RevokeInstance(hardware.Identifier.ToString());
   4.112 +    }
   4.113 +
   4.114 +    private void HardwareSensorRemoved(ISensor sensor) {
   4.115 +      RevokeInstance(sensor.Identifier.ToString());
   4.116 +    }
   4.117 +
   4.118 +    #endregion
   4.119 +
   4.120 +    #region Helpers
   4.121 +    
   4.122 +    private bool Exists(string identifier) {
   4.123 +      return activeInstances.Exists(h => h.Identifier == identifier);
   4.124 +    }
   4.125 +
   4.126 +    private void RevokeInstance(string identifier) {
   4.127 +      int instanceIndex = activeInstances.FindIndex(
   4.128 +        item => item.Identifier == identifier.ToString()
   4.129 +      );
   4.130 +
   4.131 +      Instrumentation.Revoke(activeInstances[instanceIndex]);
   4.132 +
   4.133 +      activeInstances.RemoveAt(instanceIndex);
   4.134 +    }
   4.135 +
   4.136 +    #endregion
   4.137 +
   4.138 +    public void Dispose() {
   4.139 +      foreach (IWmiObject instance in activeInstances)
   4.140 +        Instrumentation.Revoke(instance);
   4.141 +      activeInstances = null;
   4.142 +    }
   4.143 +  }
   4.144 +}
     5.1 --- a/Wmi/Hardware.cs	Sun Oct 17 16:04:19 2010 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,60 +0,0 @@
     5.4 -/*
     5.5 -  
     5.6 -  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     5.7 -
     5.8 -  The contents of this file are subject to the Mozilla Public License Version
     5.9 -  1.1 (the "License"); you may not use this file except in compliance with
    5.10 -  the License. You may obtain a copy of the License at
    5.11 - 
    5.12 -  http://www.mozilla.org/MPL/
    5.13 -
    5.14 -  Software distributed under the License is distributed on an "AS IS" basis,
    5.15 -  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    5.16 -  for the specific language governing rights and limitations under the License.
    5.17 -
    5.18 -  The Original Code is the Open Hardware Monitor code.
    5.19 -
    5.20 -  The Initial Developer of the Original Code is 
    5.21 -  Paul Werelds <paul@werelds.net>.
    5.22 -  Portions created by the Initial Developer are Copyright (C) 2009-2010
    5.23 -  the Initial Developer. All Rights Reserved.
    5.24 -
    5.25 -  Contributor(s):
    5.26 -
    5.27 -  Alternatively, the contents of this file may be used under the terms of
    5.28 -  either the GNU General Public License Version 2 or later (the "GPL"), or
    5.29 -  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    5.30 -  in which case the provisions of the GPL or the LGPL are applicable instead
    5.31 -  of those above. If you wish to allow use of your version of this file only
    5.32 -  under the terms of either the GPL or the LGPL, and not to allow others to
    5.33 -  use your version of this file under the terms of the MPL, indicate your
    5.34 -  decision by deleting the provisions above and replace them with the notice
    5.35 -  and other provisions required by the GPL or the LGPL. If you do not delete
    5.36 -  the provisions above, a recipient may use your version of this file under
    5.37 -  the terms of any one of the MPL, the GPL or the LGPL.
    5.38 - 
    5.39 -*/
    5.40 -
    5.41 -using System.Management.Instrumentation;
    5.42 -using OpenHardwareMonitor.Hardware;
    5.43 -
    5.44 -namespace OpenHardwareMonitor.WMI {
    5.45 -  [InstrumentationClass(InstrumentationType.Instance)]
    5.46 -  public class Hardware : IWmiObject {
    5.47 -    #region WMI Exposed
    5.48 -    
    5.49 -    public string HardwareType { get; private set; }
    5.50 -    public string Identifier { get; private set; }
    5.51 -    public string Name { get; private set; }
    5.52 -
    5.53 -    #endregion
    5.54 -
    5.55 -    public Hardware(IHardware hardware) {
    5.56 -      Name = hardware.Name;
    5.57 -      Identifier = hardware.Identifier.ToString();
    5.58 -      HardwareType = hardware.HardwareType.ToString();
    5.59 -    }
    5.60 -
    5.61 -    public void Update() { }
    5.62 -  }
    5.63 -}
     6.1 --- a/Wmi/IWmiObject.cs	Sun Oct 17 16:04:19 2010 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,47 +0,0 @@
     6.4 -/*
     6.5 -  
     6.6 -  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     6.7 -
     6.8 -  The contents of this file are subject to the Mozilla Public License Version
     6.9 -  1.1 (the "License"); you may not use this file except in compliance with
    6.10 -  the License. You may obtain a copy of the License at
    6.11 - 
    6.12 -  http://www.mozilla.org/MPL/
    6.13 -
    6.14 -  Software distributed under the License is distributed on an "AS IS" basis,
    6.15 -  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    6.16 -  for the specific language governing rights and limitations under the License.
    6.17 -
    6.18 -  The Original Code is the Open Hardware Monitor code.
    6.19 -
    6.20 -  The Initial Developer of the Original Code is 
    6.21 -  Paul Werelds <paul@werelds.net>.
    6.22 -  Portions created by the Initial Developer are Copyright (C) 2009-2010
    6.23 -  the Initial Developer. All Rights Reserved.
    6.24 -
    6.25 -  Contributor(s):
    6.26 -
    6.27 -  Alternatively, the contents of this file may be used under the terms of
    6.28 -  either the GNU General Public License Version 2 or later (the "GPL"), or
    6.29 -  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    6.30 -  in which case the provisions of the GPL or the LGPL are applicable instead
    6.31 -  of those above. If you wish to allow use of your version of this file only
    6.32 -  under the terms of either the GPL or the LGPL, and not to allow others to
    6.33 -  use your version of this file under the terms of the MPL, indicate your
    6.34 -  decision by deleting the provisions above and replace them with the notice
    6.35 -  and other provisions required by the GPL or the LGPL. If you do not delete
    6.36 -  the provisions above, a recipient may use your version of this file under
    6.37 -  the terms of any one of the MPL, the GPL or the LGPL.
    6.38 - 
    6.39 -*/
    6.40 -
    6.41 -namespace OpenHardwareMonitor.WMI {
    6.42 -  interface IWmiObject {
    6.43 -    // Both of these get exposed to WMI
    6.44 -    string Name { get; }
    6.45 -    string Identifier { get; }
    6.46 -
    6.47 -    // Not exposed.
    6.48 -    void Update();
    6.49 -  }
    6.50 -}
     7.1 --- a/Wmi/Sensor.cs	Sun Oct 17 16:04:19 2010 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,80 +0,0 @@
     7.4 -/*
     7.5 -  
     7.6 -  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     7.7 -
     7.8 -  The contents of this file are subject to the Mozilla Public License Version
     7.9 -  1.1 (the "License"); you may not use this file except in compliance with
    7.10 -  the License. You may obtain a copy of the License at
    7.11 - 
    7.12 -  http://www.mozilla.org/MPL/
    7.13 -
    7.14 -  Software distributed under the License is distributed on an "AS IS" basis,
    7.15 -  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    7.16 -  for the specific language governing rights and limitations under the License.
    7.17 -
    7.18 -  The Original Code is the Open Hardware Monitor code.
    7.19 -
    7.20 -  The Initial Developer of the Original Code is 
    7.21 -  Paul Werelds <paul@werelds.net>.
    7.22 -  Portions created by the Initial Developer are Copyright (C) 2009-2010
    7.23 -  the Initial Developer. All Rights Reserved.
    7.24 -
    7.25 -  Contributor(s):
    7.26 -
    7.27 -  Alternatively, the contents of this file may be used under the terms of
    7.28 -  either the GNU General Public License Version 2 or later (the "GPL"), or
    7.29 -  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    7.30 -  in which case the provisions of the GPL or the LGPL are applicable instead
    7.31 -  of those above. If you wish to allow use of your version of this file only
    7.32 -  under the terms of either the GPL or the LGPL, and not to allow others to
    7.33 -  use your version of this file under the terms of the MPL, indicate your
    7.34 -  decision by deleting the provisions above and replace them with the notice
    7.35 -  and other provisions required by the GPL or the LGPL. If you do not delete
    7.36 -  the provisions above, a recipient may use your version of this file under
    7.37 -  the terms of any one of the MPL, the GPL or the LGPL.
    7.38 - 
    7.39 -*/
    7.40 -
    7.41 -using System.Management.Instrumentation;
    7.42 -using OpenHardwareMonitor.Hardware;
    7.43 -
    7.44 -namespace OpenHardwareMonitor.WMI {
    7.45 -  [InstrumentationClass(InstrumentationType.Instance)]
    7.46 -  public class Sensor : IWmiObject {
    7.47 -    private ISensor sensor;
    7.48 -
    7.49 -    #region WMI Exposed
    7.50 -
    7.51 -    public string SensorType { get; private set; }
    7.52 -    public string Identifier { get; private set; }
    7.53 -    public string Parent { get; private set; }
    7.54 -    public string Name { get; private set; }
    7.55 -    public float Value { get; private set; }
    7.56 -    public float Min { get; private set; }
    7.57 -    public float Max { get; private set; }
    7.58 -    public int Index { get; private set; }
    7.59 -
    7.60 -    #endregion
    7.61 -
    7.62 -    public Sensor(ISensor sensor) {
    7.63 -      Name = sensor.Name;
    7.64 -      Index = sensor.Index;
    7.65 -
    7.66 -      SensorType = sensor.SensorType.ToString();
    7.67 -      Identifier = sensor.Identifier.ToString();
    7.68 -      Parent = sensor.Hardware.Identifier.ToString();
    7.69 -
    7.70 -      this.sensor = sensor;
    7.71 -    }
    7.72 -    
    7.73 -    public void Update() {
    7.74 -      Value = (sensor.Value != null) ? (float)sensor.Value : 0;
    7.75 -
    7.76 -      if (sensor.Min != null)
    7.77 -        Min = (float)sensor.Min;
    7.78 -
    7.79 -      if (sensor.Max != null)
    7.80 -        Max = (float)sensor.Max;
    7.81 -    }
    7.82 -  }
    7.83 -}
     8.1 --- a/Wmi/WmiProvider.cs	Sun Oct 17 16:04:19 2010 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,141 +0,0 @@
     8.4 -/*
     8.5 -  
     8.6 -  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     8.7 -
     8.8 -  The contents of this file are subject to the Mozilla Public License Version
     8.9 -  1.1 (the "License"); you may not use this file except in compliance with
    8.10 -  the License. You may obtain a copy of the License at
    8.11 - 
    8.12 -  http://www.mozilla.org/MPL/
    8.13 -
    8.14 -  Software distributed under the License is distributed on an "AS IS" basis,
    8.15 -  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    8.16 -  for the specific language governing rights and limitations under the License.
    8.17 -
    8.18 -  The Original Code is the Open Hardware Monitor code.
    8.19 -
    8.20 -  The Initial Developer of the Original Code is 
    8.21 -  Paul Werelds <paul@werelds.net>.
    8.22 -  Portions created by the Initial Developer are Copyright (C) 2009-2010
    8.23 -  the Initial Developer. All Rights Reserved.
    8.24 -
    8.25 -  Contributor(s):
    8.26 -
    8.27 -  Alternatively, the contents of this file may be used under the terms of
    8.28 -  either the GNU General Public License Version 2 or later (the "GPL"), or
    8.29 -  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    8.30 -  in which case the provisions of the GPL or the LGPL are applicable instead
    8.31 -  of those above. If you wish to allow use of your version of this file only
    8.32 -  under the terms of either the GPL or the LGPL, and not to allow others to
    8.33 -  use your version of this file under the terms of the MPL, indicate your
    8.34 -  decision by deleting the provisions above and replace them with the notice
    8.35 -  and other provisions required by the GPL or the LGPL. If you do not delete
    8.36 -  the provisions above, a recipient may use your version of this file under
    8.37 -  the terms of any one of the MPL, the GPL or the LGPL.
    8.38 - 
    8.39 -*/
    8.40 -
    8.41 -using System;
    8.42 -using System.Collections.Generic;
    8.43 -using System.Management.Instrumentation;
    8.44 -using OpenHardwareMonitor.Hardware;
    8.45 -
    8.46 -[assembly: Instrumented("root/OpenHardwareMonitor")]
    8.47 -
    8.48 -[System.ComponentModel.RunInstaller(true)]
    8.49 -public class InstanceInstaller : DefaultManagementProjectInstaller { }
    8.50 -
    8.51 -namespace OpenHardwareMonitor.WMI {
    8.52 -  /// <summary>
    8.53 -  /// The WMI Provider.
    8.54 -  /// This class is not exposed to WMI itself.
    8.55 -  /// </summary>
    8.56 -  public class WmiProvider : IDisposable {
    8.57 -    private List<IWmiObject> activeInstances;
    8.58 -
    8.59 -    public WmiProvider(IComputer computer) {
    8.60 -      activeInstances = new List<IWmiObject>();
    8.61 -
    8.62 -      foreach (IHardware hardware in computer.Hardware)
    8.63 -        ComputerHardwareAdded(hardware);
    8.64 -
    8.65 -      computer.HardwareAdded += ComputerHardwareAdded;
    8.66 -      computer.HardwareRemoved += ComputerHardwareRemoved;
    8.67 -    }
    8.68 -
    8.69 -    public void Update() {
    8.70 -      foreach (IWmiObject instance in activeInstances)
    8.71 -        instance.Update();
    8.72 -    }
    8.73 -
    8.74 -    #region Eventhandlers
    8.75 -    
    8.76 -    private void ComputerHardwareAdded(IHardware hardware) {
    8.77 -      if (!Exists(hardware.Identifier.ToString())) {
    8.78 -        foreach (ISensor sensor in hardware.Sensors)
    8.79 -          HardwareSensorAdded(sensor);
    8.80 -
    8.81 -        hardware.SensorAdded += HardwareSensorAdded;
    8.82 -        hardware.SensorRemoved += HardwareSensorRemoved;
    8.83 -
    8.84 -        Hardware hw = new Hardware(hardware);
    8.85 -        activeInstances.Add(hw);
    8.86 -
    8.87 -        Instrumentation.Publish(hw);
    8.88 -      }
    8.89 -
    8.90 -      foreach (IHardware subHardware in hardware.SubHardware)
    8.91 -        ComputerHardwareAdded(subHardware);
    8.92 -    }
    8.93 -
    8.94 -    private void HardwareSensorAdded(ISensor data) {
    8.95 -      Sensor sensor = new Sensor(data);
    8.96 -      activeInstances.Add(sensor);
    8.97 -
    8.98 -      Instrumentation.Publish(sensor);
    8.99 -    }
   8.100 -
   8.101 -    private void ComputerHardwareRemoved(IHardware hardware) {
   8.102 -      hardware.SensorAdded -= HardwareSensorAdded;
   8.103 -      hardware.SensorRemoved -= HardwareSensorRemoved;
   8.104 -      
   8.105 -      foreach (ISensor sensor in hardware.Sensors) 
   8.106 -        HardwareSensorRemoved(sensor);
   8.107 -      
   8.108 -      foreach (IHardware subHardware in hardware.SubHardware)
   8.109 -        ComputerHardwareRemoved(subHardware);
   8.110 -
   8.111 -      RevokeInstance(hardware.Identifier.ToString());
   8.112 -    }
   8.113 -
   8.114 -    private void HardwareSensorRemoved(ISensor sensor) {
   8.115 -      RevokeInstance(sensor.Identifier.ToString());
   8.116 -    }
   8.117 -
   8.118 -    #endregion
   8.119 -
   8.120 -    #region Helpers
   8.121 -    
   8.122 -    private bool Exists(string identifier) {
   8.123 -      return activeInstances.Exists(h => h.Identifier == identifier);
   8.124 -    }
   8.125 -
   8.126 -    private void RevokeInstance(string identifier) {
   8.127 -      int instanceIndex = activeInstances.FindIndex(
   8.128 -        item => item.Identifier == identifier.ToString()
   8.129 -      );
   8.130 -
   8.131 -      Instrumentation.Revoke(activeInstances[instanceIndex]);
   8.132 -
   8.133 -      activeInstances.RemoveAt(instanceIndex);
   8.134 -    }
   8.135 -
   8.136 -    #endregion
   8.137 -
   8.138 -    public void Dispose() {
   8.139 -      foreach (IWmiObject instance in activeInstances)
   8.140 -        Instrumentation.Revoke(instance);
   8.141 -      activeInstances = null;
   8.142 -    }
   8.143 -  }
   8.144 -}