Hardware/RAM/GenericRAM.cs
author moel.mich
Mon, 23 Jul 2012 21:54:35 +0000
changeset 370 8e4dedc41924
child 372 2de3a3e5f0b5
permissions -rw-r--r--
Added a RAM hardware and sensor, fixed Issue 115.
     1 /*
     2  
     3   This Source Code Form is subject to the terms of the Mozilla Public
     4   License, v. 2.0. If a copy of the MPL was not distributed with this
     5   file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  
     7   Copyright (C) 2012 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	
     9 */
    10 
    11 using Microsoft.VisualBasic.Devices;
    12 
    13 namespace OpenHardwareMonitor.Hardware.RAM {
    14   internal class GenericRAM : Hardware {
    15 
    16     private Sensor loadSensor;
    17     private Sensor availableMemory;
    18 
    19     private ComputerInfo computerInfo;
    20 
    21     public GenericRAM(string name, ISettings settings)
    22       : base(name, new Identifier("ram"), settings)
    23     {   
    24       computerInfo = new ComputerInfo();
    25       loadSensor = new Sensor("Memory", 0, SensorType.Load, this, settings);
    26       ActivateSensor(loadSensor);
    27 
    28       availableMemory = new Sensor("Available Memory", 0, SensorType.Data, this, settings);
    29       ActivateSensor(availableMemory);
    30     }
    31 
    32     public override HardwareType HardwareType {
    33       get {
    34         return HardwareType.RAM;
    35       }
    36     }
    37 
    38     public override void Update() {
    39       loadSensor.Value = 100.0f - 
    40         (100.0f * computerInfo.AvailablePhysicalMemory) / 
    41         computerInfo.TotalPhysicalMemory;
    42 
    43       availableMemory.Value = (float)computerInfo.AvailablePhysicalMemory /
    44         (1024 * 1024 * 1024);
    45     }
    46   }
    47 }