Hardware/Hardware.cs
changeset 275 35788ddd1825
parent 247 6dc755f1970e
child 298 96263190189a
     1.1 --- a/Hardware/Hardware.cs	Sat Apr 23 14:18:02 2011 +0000
     1.2 +++ b/Hardware/Hardware.cs	Sat Apr 30 16:03:58 2011 +0000
     1.3 @@ -16,7 +16,7 @@
     1.4  
     1.5    The Initial Developer of the Original Code is 
     1.6    Michael Möller <m.moeller@gmx.ch>.
     1.7 -  Portions created by the Initial Developer are Copyright (C) 2009-2010
     1.8 +  Portions created by the Initial Developer are Copyright (C) 2009-2011
     1.9    the Initial Developer. All Rights Reserved.
    1.10  
    1.11    Contributor(s):
    1.12 @@ -41,7 +41,19 @@
    1.13  namespace OpenHardwareMonitor.Hardware {
    1.14    internal abstract class Hardware : IHardware {
    1.15  
    1.16 -    private readonly ListSet<ISensor> active = new ListSet<ISensor>();
    1.17 +    private readonly Identifier identifier;
    1.18 +    protected readonly string name;
    1.19 +    private string customName;
    1.20 +    protected readonly ISettings settings;
    1.21 +    protected readonly ListSet<ISensor> active = new ListSet<ISensor>();
    1.22 +
    1.23 +    public Hardware(string name, Identifier identifier, ISettings settings) {
    1.24 +      this.settings = settings;
    1.25 +      this.identifier = identifier;
    1.26 +      this.name = name;
    1.27 +      this.customName = settings.GetValue(
    1.28 +        new Identifier(Identifier, "name").ToString(), name);
    1.29 +    }
    1.30  
    1.31      public IHardware[] SubHardware {
    1.32        get { return new IHardware[0]; }
    1.33 @@ -51,29 +63,48 @@
    1.34        get { return null; }
    1.35      }
    1.36  
    1.37 -    public ISensor[] Sensors {
    1.38 +    public virtual ISensor[] Sensors {
    1.39        get { return active.ToArray(); }
    1.40      }
    1.41  
    1.42 -    protected void ActivateSensor(ISensor sensor) {
    1.43 +    protected virtual void ActivateSensor(ISensor sensor) {
    1.44        if (active.Add(sensor)) 
    1.45          if (SensorAdded != null)
    1.46            SensorAdded(sensor);
    1.47      }
    1.48  
    1.49 -    protected void DeactivateSensor(ISensor sensor) {
    1.50 +    protected virtual void DeactivateSensor(ISensor sensor) {
    1.51        if (active.Remove(sensor))
    1.52          if (SensorRemoved != null)
    1.53            SensorRemoved(sensor);     
    1.54      }
    1.55  
    1.56 +    public string Name {
    1.57 +      get {
    1.58 +        return customName;
    1.59 +      }
    1.60 +      set {
    1.61 +        if (!string.IsNullOrEmpty(value))
    1.62 +          customName = value;
    1.63 +        else
    1.64 +          customName = name;
    1.65 +        settings.SetValue(new Identifier(Identifier, "name").ToString(), 
    1.66 +          customName);
    1.67 +      }
    1.68 +    }
    1.69 +
    1.70 +    public Identifier Identifier {
    1.71 +      get {
    1.72 +        return identifier;
    1.73 +      }
    1.74 +    }
    1.75 +
    1.76      #pragma warning disable 67
    1.77      public event SensorEventHandler SensorAdded;
    1.78      public event SensorEventHandler SensorRemoved;
    1.79      #pragma warning restore 67
    1.80    
    1.81 -    public abstract string Name { get; }
    1.82 -    public abstract Identifier Identifier { get; }
    1.83 +    
    1.84      public abstract HardwareType HardwareType { get; }
    1.85  
    1.86      public virtual string GetReport() {
    1.87 @@ -88,7 +119,7 @@
    1.88        visitor.VisitHardware(this);
    1.89      }
    1.90  
    1.91 -    public void Traverse(IVisitor visitor) {
    1.92 +    public virtual void Traverse(IVisitor visitor) {
    1.93        foreach (ISensor sensor in active)
    1.94          sensor.Accept(visitor);
    1.95      }