1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
namespace Smart
{
public class Infos
{
public byte[] VendorSpecByte { get; set; }
public string InstanceN { get; set; }
public List<PropertyContent> Datas { get; set; }
public Infos()
{
Datas = new List<PropertyContent>();
LoadInfos();
}
private void LoadInfos()
{
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT VendorSpecific, InstanceName FROM MSStorageDriver_FailurePredictData"))
{
foreach (ManagementObject data in searcher.Get())
{
try
{
this.VendorSpecByte = (byte[])data.GetPropertyValue("VendorSpecific");
this.InstanceN = (string)data.GetPropertyValue("InstanceName");
for (int i = 0; i <= 29; i++)
{
int id = VendorSpecByte[i * 12 + 2];
int flags = VendorSpecByte[i * 12 + 4];
bool failureImminent = (flags & 0x1) == 0x1;
UInt32 vendordata = BitConverter.ToUInt32(VendorSpecByte, i * 12 + 7);
if (!(id == 0))
{
PropertyContent pInfos = new PropertyContent();
pInfos.Id = id;
pInfos.Value = Convert.ToString(vendordata);
pInfos.IsOk = (failureImminent == false);
this.Datas.Add(pInfos);
}
}
}
catch (ManagementException ex)
{
throw new ManagementException("Erreur WMI", ex);
}
}
}
}
public string FormatToString()
{
string str = String.Empty;
foreach (PropertyContent d in Datas)
{
str += ("ID:"
+ (d.Id + ("\r\n" + ("PropertyName:"
+ (d.PropertyName + ("\r\n" + ("PropertyValue:"
+ (d.Value + ("\r\n" + ("PropertyState:"
+ (Convert.ToString(d.IsOk) + "\r\n")))))))))));
}
return str;
}
}
public class PropertyContent
{
private int m_Id;
public int Id
{
get { return m_Id; }
set
{
m_Id = value;
switch (m_Id)
{
case 1:
m_PropertyName = PropertyNames.RawReadErrorRate;
break;
case 2:
m_PropertyName = PropertyNames.ThroughputPerformance;
break;
case 3:
m_PropertyName = PropertyNames.SpinUpTime;
break;
case 4:
m_PropertyName = PropertyNames.StartStopCount;
break;
case 5:
m_PropertyName = PropertyNames.ReallocatedSectorCount;
break;
case 6:
m_PropertyName = PropertyNames.ReadChannelMargin;
break;
case 7:
m_PropertyName = PropertyNames.SeekErrorRate;
break;
case 8:
m_PropertyName = PropertyNames.SeekTimePerformance;
break;
case 9:
m_PropertyName = PropertyNames.PowerOnHours;
break;
case 10:
m_PropertyName = PropertyNames.SpinRetryCount;
break;
case 11:
m_PropertyName = PropertyNames.CalibrationRetryCount;
break;
case 12:
m_PropertyName = PropertyNames.PowerCycleCount;
break;
case 171:
m_PropertyName = PropertyNames.ProgramFailBlockCount;
break;
case 172:
m_PropertyName = PropertyNames.EraseFailBlockCount;
break;
case 173:
m_PropertyName = PropertyNames.UnknownAttribute;
break;
case 174:
m_PropertyName = PropertyNames.UnexpectedPowerLossCount;
break;
case 187:
m_PropertyName = PropertyNames.ReportedUncorrectableErrors;
break;
case 192:
m_PropertyName = PropertyNames.PoweroffRetractCount;
break;
case 193:
m_PropertyName = PropertyNames.LoadCycleCount;
break;
case 194:
m_PropertyName = PropertyNames.Temperature;
break;
case 196:
m_PropertyName = PropertyNames.ReallocationEventCount;
break;
case 197:
m_PropertyName = PropertyNames.CurrentPendingSectorCount;
break;
case 198:
m_PropertyName = PropertyNames.OfflineScanUncorrectableSectorCount;
break;
case 199:
m_PropertyName = PropertyNames.UltraDMACRCErrorCount;
break;
case 201:
m_PropertyName = PropertyNames.SoftReadErrorRate;
break;
case 220:
m_PropertyName = PropertyNames.DiskShift;
break;
case 230:
m_PropertyName = PropertyNames.LifeCurveStatus;
break;
case 232:
m_PropertyName = PropertyNames.AvailableReservedSpace;
break;
case 234:
m_PropertyName = PropertyNames.Reserved;
break;
case 241:
m_PropertyName = PropertyNames.LifetimeWritesFromHost;
break;
case 242:
m_PropertyName = PropertyNames.LifetimeReadsFromHost;
break;
}
}
}
private string m_PropertyName;
public string PropertyName
{
get { return m_PropertyName; }
}
public string Value { get; set; }
public bool IsOk { get; set; }
private struct PropertyNames
{
public const string RawReadErrorRate = "Raw Read Error Rate";
public const string ThroughputPerformance = "Throughput Performance";
public const string SpinUpTime = "Spin Up Time";
public const string StartStopCount = "Start/Stop Count";
public const string ReallocatedSectorCount = "Reallocated Sector Count";
public const string ReadChannelMargin = "Read Channel Margin";
public const string SeekErrorRate = "Seek Error Rate";
public const string SeekTimePerformance = "Seek Time Performance";
public const string PowerOnHours = "Power-On Hours";
public const string SpinRetryCount = "Spin Retry Count";
public const string CalibrationRetryCount = "Calibration Retry Count";
public const string PowerCycleCount = "Power Cycle Count";
public const string ProgramFailBlockCount = "Program Fail Block Count";
public const string EraseFailBlockCount = "Erase Fail Block Count";
public const string UnknownAttribute = "Unknown Attribute";
public const string UnexpectedPowerLossCount = "Unexpected Power Loss Count";
public const string ReportedUncorrectableErrors = "Reported Uncorrectable Errors";
public const string PoweroffRetractCount = "Power-off Retract Count";
public const string LoadCycleCount = "Load Cycle Count";
public const string Temperature = "Temperature";
public const string ReallocationEventCount = "Reallocation Event Count";
public const string CurrentPendingSectorCount = "Current Pending Sector Count";
public const string OfflineScanUncorrectableSectorCount = "Off-line Scan Uncorrectable Sector Count";
public const string UltraDMACRCErrorCount = "Ultra DMA CRC Error Count";
public const string SoftReadErrorRate = "Soft Read Error Rate";
public const string DiskShift = "Disk Shift";
public const string LifeCurveStatus = "Life Curve Status";
public const string AvailableReservedSpace = "Available Reserved Space";
public const string Reserved = "Reserved";
public const string LifetimeWritesFromHost = "Lifetime Writes From Host";
public const string LifetimeReadsFromHost = "Lifetime Reads From Host";
}
}
} |
Partager