public override void Update()
        {
            if (count == 0)
            {
                DriveAttributeValue[] values = smart.ReadSmartData(handle, index);

                foreach (KeyValuePair <SmartAttribute, Sensor> keyValuePair in sensors)
                {
                    SmartAttribute attribute = keyValuePair.Key;
                    foreach (DriveAttributeValue value in values)
                    {
                        if (value.Identifier == attribute.Identifier)
                        {
                            Sensor sensor = keyValuePair.Value;
                            sensor.Value = attribute.ConvertValue(value);
                        }
                    }
                }

                UpdateAdditionalSensors(values);
            }

            count++;
            count %= UPDATE_DIVIDER;
        }
예제 #2
0
        public override void Update()
        {
            if (count == 0)
            {
                if (handle != smart.InvalidHandle)
                {
                    DriveAttributeValue[] values = smart.ReadSmartData(handle, index);

                    foreach (KeyValuePair <SmartAttribute, Sensor> keyValuePair in sensors)
                    {
                        SmartAttribute attribute = keyValuePair.Key;
                        foreach (DriveAttributeValue value in values)
                        {
                            if (value.Identifier == attribute.Identifier)
                            {
                                Sensor sensor = keyValuePair.Value;
                                sensor.Value = attribute.ConvertValue(value, sensor.Parameters);
                            }
                        }
                    }

                    UpdateAdditionalSensors(values);
                }

                if (usageSensor != null)
                {
                    long totalSize      = 0;
                    long totalFreeSpace = 0;

                    for (int i = 0; i < driveInfos.Length; i++)
                    {
                        if (!driveInfos[i].IsReady)
                        {
                            continue;
                        }
                        try
                        {
                            totalSize      += driveInfos[i].TotalSize;
                            totalFreeSpace += driveInfos[i].TotalFreeSpace;
                        }
                        catch (IOException) { }
                        catch (UnauthorizedAccessException) { }
                    }
                    if (totalSize > 0)
                    {
                        usageSensor.Value = 100.0f - (100.0f * totalFreeSpace) / totalSize;
                    }
                    else
                    {
                        usageSensor.Value = null;
                    }
                }
            }

            count++;
            count %= UPDATE_DIVIDER;
        }
        protected override void UpdateSensors()
        {
            if (smart.IsValid)
            {
                DriveAttributeValue[] values = smart.ReadSmartData();

                foreach (KeyValuePair <SmartAttribute, Sensor> keyValuePair in sensors)
                {
                    SmartAttribute attribute = keyValuePair.Key;
                    foreach (DriveAttributeValue value in values)
                    {
                        if (value.Identifier == attribute.Identifier)
                        {
                            Sensor sensor = keyValuePair.Value;
                            sensor.Value = attribute.ConvertValue(value, sensor.Parameters);
                        }
                    }
                }

                UpdateAdditionalSensors(values);
            }
        }
        public override void Update()
        {
            if (count == 0)
            {
                DriveAttributeValue[] values = smart.ReadSmartData(handle, index);

                foreach (KeyValuePair <SmartAttribute, Sensor> keyValuePair in sensors)
                {
                    SmartAttribute attribute = keyValuePair.Key;
                    foreach (DriveAttributeValue value in values)
                    {
                        if (value.Identifier == attribute.Identifier)
                        {
                            Sensor sensor = keyValuePair.Value;
                            sensor.Value = attribute.ConvertValue(value, sensor.Parameters);
                        }
                    }
                }

                UpdateAdditionalSensors(values);

                if (usageSensor != null)
                {
                    long totalSize      = 0;
                    long totalFreeSpace = 0;
                    for (int i = 0; i < driveInfos.Length; i++)
                    {
                        totalSize      += driveInfos[i].TotalSize;
                        totalFreeSpace += driveInfos[i].TotalFreeSpace;
                    }
                    usageSensor.Value = 100.0f - (100.0f * totalFreeSpace) / totalSize;
                }
            }

            count++;
            count %= UPDATE_DIVIDER;
        }