diff --git a/Windows/Workhorse/Monitor/Config.cs b/Windows/Workhorse/Monitor/Config.cs
index 2b2a75d..70b7776 100644
--- a/Windows/Workhorse/Monitor/Config.cs
+++ b/Windows/Workhorse/Monitor/Config.cs
@@ -25,11 +25,38 @@ namespace HardwareMonitor.Monitor.Config
{
public abstract class CaptureDescriptor
{
+ #region Private fields
+
+ private Regex _nameRegex = null;
+
+ #endregion Private fields
+
#region Public Properties
+ ///
+ /// The name of the hardware or sensor to look for. Regex (where appropriate)
+ ///
+ [XmlAttribute()]
+ public string Name { get; set; }
+
+ ///
+ /// A unique Id used to identify this captured value from the layouts xml. Regex
+ ///
[XmlAttribute("CaptureAs")]
public string CaptureName { get; set; }
+ [XmlIgnore()]
+ public Regex NameRegex
+ {
+ get
+ {
+ if (_nameRegex == null)
+ _nameRegex = new Regex(Name);
+
+ return _nameRegex;
+ }
+ }
+
#endregion Public Properties
}
@@ -48,20 +75,8 @@ public class Component : CaptureDescriptor
///
public class Sensor : CaptureDescriptor
{
- #region Private fields
-
- private Regex _nameRegex = null;
-
- #endregion Private fields
-
#region Public Properties
- ///
- /// The name of the sensor to look for. Regex
- ///
- [XmlAttribute()]
- public string Name { get; set; }
-
///
/// The type of hardware the sensor is tied to
///
@@ -74,18 +89,6 @@ public class Sensor : CaptureDescriptor
[XmlAttribute()]
public SensorType Type { get; set; }
- [XmlIgnore()]
- public Regex NameRegex
- {
- get
- {
- if (_nameRegex == null)
- _nameRegex = new Regex(Name);
-
- return _nameRegex;
- }
- }
-
#endregion Public Properties
}
@@ -99,15 +102,6 @@ public class CompoundSensor : CaptureDescriptor
#region Public Properties
- ///
- /// User defined name
- ///
- ///
- /// The compount sensor will appear as a regular sensor in the snapshot, so this is used as the display name
- ///
- [XmlAttribute()]
- public string Name { get; set; }
-
///
/// How the values of all the sensors will be aggregated
///
diff --git a/Windows/Workhorse/Monitor/Snapshot.cs b/Windows/Workhorse/Monitor/Snapshot.cs
index 87d58e5..327667d 100644
--- a/Windows/Workhorse/Monitor/Snapshot.cs
+++ b/Windows/Workhorse/Monitor/Snapshot.cs
@@ -85,6 +85,27 @@ public class Capture
public dynamic Value { get; set; }
#endregion Public Properties
+
+ public Capture(Config.Component config, Plugin.IHardware hardware)
+ {
+ if (string.IsNullOrEmpty(config.Name))
+ Name = config.CaptureName;
+ else
+ Name = config.NameRegex.Replace(hardware.Name, config.CaptureName);
+ Value = hardware.Name;
+ }
+
+ public Capture(Config.Sensor config, Plugin.ISensor sensor)
+ {
+ Name = config.NameRegex.Replace(sensor.Name, config.CaptureName);
+ Value = sensor.Value;
+ }
+
+ public Capture(string name, dynamic value)
+ {
+ Name = name;
+ Value = value;
+ }
}
///
@@ -94,16 +115,11 @@ public class Snapshot
{
#region Private fields
- private List _hardwareSamples = new List();
- private List _sensorSamples = new List();
private Dictionary _captures = new Dictionary();
#endregion Private fields
#region Public Properties
-
- public List HardwareSamples => _hardwareSamples;
- public List SensorSamples => _sensorSamples;
public Dictionary Captures => _captures;
#endregion Public Properties
diff --git a/Windows/Workhorse/Monitor/Watcher.cs b/Windows/Workhorse/Monitor/Watcher.cs
index 43db150..d4a261b 100644
--- a/Windows/Workhorse/Monitor/Watcher.cs
+++ b/Windows/Workhorse/Monitor/Watcher.cs
@@ -136,10 +136,11 @@ private static void PollHardware(IEnumerable hardware, PollDat
if (watchedHardware == null)
continue;
- data.Snapshot.HardwareSamples.Add(new HardwareSample() { Component = watchedHardware, Name = hardwareItem.Name });
-
if (!string.IsNullOrWhiteSpace(watchedHardware.CaptureName))
- data.Snapshot.Captures[watchedHardware.CaptureName] = new Capture() { Name = watchedHardware.CaptureName, Value = hardwareItem.Name };
+ {
+ Capture capture = new Capture(watchedHardware, hardwareItem);
+ data.Snapshot.Captures[capture.Name] = capture;
+ }
PollSensors(hardwareItem, data);
}
@@ -162,10 +163,11 @@ private static void CheckSensor(Plugin.ISensor sensor, PollData data)
if (watchedSensor == null)
return;
- data.Snapshot.SensorSamples.Add(new SensorSample() { Sensor = watchedSensor, Name = sensor.Name, Value = sensor.Value });
-
if (!string.IsNullOrWhiteSpace(watchedSensor.CaptureName))
- data.Snapshot.Captures.Add(watchedSensor.CaptureName, new Capture() { Name = watchedSensor.CaptureName, Value = sensor.Value });
+ {
+ Capture capture = new Capture(watchedSensor, sensor);
+ data.Snapshot.Captures[capture.Name] = capture;
+ }
}
private static void CheckCompoundSensor(Plugin.ISensor sensor, PollData data)
@@ -243,7 +245,8 @@ private static void ProcessCompoundSensors(PollData data)
float result = instance.Calculate(from sample in compoundSensorData.Samples select sample.Value);
- data.Snapshot.Captures.Add(compoundSensorData.Sensor.CaptureName, new Capture() { Name = compoundSensorData.Sensor.CaptureName, Value = result });
+ Capture capture = new Capture(compoundSensorData.Sensor.CaptureName, result);
+ data.Snapshot.Captures[capture.Name] = capture;
}
}