Hardware/ReportWriter.cs
author moel.mich
Wed, 03 Feb 2010 20:35:10 +0000
changeset 24 09ab31bee6bd
parent 1 361e324a0ed4
permissions -rw-r--r--
Release version 0.1.11. Added support for load percentage sensor type. Added load sensors for CPUs and ATI GPUs.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.IO;
     4 using System.Text;
     5 
     6 namespace OpenHardwareMonitor.Hardware {
     7   public class ReportWriter {
     8 
     9     private static void NewSection(TextWriter writer) {      
    10       for (int i = 0; i < 8; i++)
    11         writer.Write("----------");
    12       writer.WriteLine();
    13       writer.WriteLine();
    14     }
    15 
    16     public static void Save(List<IGroup> groupList, Version version) {
    17 
    18       using (TextWriter w =
    19         new StreamWriter("OpenHardwareMonitor.Report.txt")) {
    20 
    21         w.WriteLine();
    22         w.WriteLine("Open Hardware Monitor Report");
    23         w.WriteLine();
    24 
    25         NewSection(w);
    26         w.Write("Version: "); w.WriteLine(version.ToString());
    27         w.WriteLine();
    28 
    29         NewSection(w);
    30         foreach (IGroup group in groupList) {          
    31           foreach (IHardware hardware in group.Hardware) {
    32             w.WriteLine("|");
    33             w.WriteLine("+-+ {0} ({1})",
    34               new object[] { hardware.Name, hardware.Identifier });
    35             foreach (ISensor sensor in hardware.Sensors) {
    36               w.WriteLine("|   +- {0} : {1} : {2} : {3}",
    37                 new object[] { sensor.SensorType, sensor.Index, sensor.Name, 
    38                   sensor.Value });
    39             }
    40           }
    41         }
    42         w.WriteLine();
    43 
    44         foreach (IGroup group in groupList) {
    45           string report = group.GetReport();
    46           if (report != null) {
    47             NewSection(w);
    48             w.Write(report);            
    49           }
    50 
    51           IHardware[] hardwareArray = group.Hardware;
    52           foreach (IHardware hardware in hardwareArray) {
    53             string hardwareReport = hardware.GetReport();
    54             if (hardwareReport != null) {
    55               NewSection(w);
    56               w.Write(hardwareReport);
    57             }
    58           }
    59         }
    60       }
    61     }
    62   }
    63 }