Example #1
1
        protected AbstractHarddrive(ISmart smart, string name, 
      string firmwareRevision, int index, 
      IEnumerable<SmartAttribute> smartAttributes, ISettings settings)
            : base(name, new Identifier("hdd",
        index.ToString(CultureInfo.InvariantCulture)), settings)
        {
            this.firmwareRevision = firmwareRevision;
              this.smart = smart;
              handle = smart.OpenDrive(index);

              if (handle != smart.InvalidHandle)
            smart.EnableSmart(handle, index);

              this.index = index;
              this.count = 0;

              this.smartAttributes = new List<SmartAttribute>(smartAttributes);

              string[] logicalDrives = smart.GetLogicalDrives(index);
              List<DriveInfo> driveInfoList = new List<DriveInfo>(logicalDrives.Length);
              foreach (string logicalDrive in logicalDrives) {
            try {
              DriveInfo di = new DriveInfo(logicalDrive);
              if (di.TotalSize > 0)
            driveInfoList.Add(new DriveInfo(logicalDrive));
            } catch (ArgumentException) { } catch (IOException) { }
              }
              driveInfos = driveInfoList.ToArray();

              CreateSensors();
        }
Example #2
0
 public SSDSandforce(ISmart smart, string name, string firmwareRevision,
                     int index, ISettings settings)
     : base(smart, name, firmwareRevision, index, smartAttributes, settings)
 {
     this.writeAmplification = new Sensor("Write Amplification", 1,
                                          SensorType.Factor, this, settings);
 }
        protected AbstractHarddrive(ISmart smart, string name,
                                    string firmwareRevision, int index,
                                    IEnumerable <SmartAttribute> smartAttributes, ISettings settings)
            : base(name, new Identifier("hdd",
                                        index.ToString(CultureInfo.InvariantCulture)), settings)
        {
            this.firmwareRevision = firmwareRevision;
            this.smart            = smart;
            handle = smart.OpenDrive(index);

            smart.EnableSmart(handle, index);

            this.index = index;
            this.count = 0;

            this.smartAttributes = new List <SmartAttribute>(smartAttributes);

            string[]         logicalDrives = smart.GetLogicalDrives(index);
            List <DriveInfo> driveInfoList = new List <DriveInfo>(logicalDrives.Length);

            foreach (string logicalDrive in logicalDrives)
            {
                try {
                    DriveInfo di = new DriveInfo(logicalDrive);
                    if (di.TotalSize > 0)
                    {
                        driveInfoList.Add(new DriveInfo(logicalDrive));
                    }
                } catch (ArgumentException) { } catch (IOException) { }
            }
            driveInfos = driveInfoList.ToArray();

            CreateSensors();
        }
Example #4
0
 public SSDSandforce(ISmart smart, string name, string firmwareRevision, 
   int index, ISettings settings) 
   : base(smart, name, firmwareRevision,  index, smartAttributes, settings) 
 {
   this.writeAmplification = new Sensor("Write Amplification", 1, 
     SensorType.Factor, this, settings);    
 }
Example #5
0
        protected ATAStorage(ISmart smart, string name,
                             string firmwareRevision, string id, int index,
                             IEnumerable <SmartAttribute> smartAttributes, ISettings settings)
            : base(name, firmwareRevision, id, index, settings)
        {
            this.smart = smart;

            this.smartAttributes = new List <SmartAttribute>(smartAttributes);

            CreateSensors();
        }
Example #6
0
        internal AtaStorage(StorageInfo storageInfo, ISmart smart, string name, string firmwareRevision, string id, int index, IEnumerable <SmartAttribute> smartAttributes, ISettings settings)
            : base(storageInfo, name, firmwareRevision, id, index, settings)
        {
            Smart = smart;
            if (smart.IsValid)
            {
                smart.EnableSmart();
            }

            _smartAttributes = new List <SmartAttribute>(smartAttributes);
            CreateSensors();
        }
 public SSDMicron(ISmart smart, string name, string firmwareRevision,
                  int index, ISettings settings)
     : base(smart, name, firmwareRevision, index, smartAttributes, settings)
 {
     this.temperature = new Sensor("Temperature", 0, false,
                                   SensorType.Temperature, this,
                                   new[] { new ParameterDescription("Offset [°C]",
                                                                    "Temperature offset of the thermal sensor.\n" +
                                                                    "Temperature = Value + Offset.", 0) }, settings);
     this.writeAmplification = new Sensor("Write Amplification", 0,
                                          SensorType.Factor, this, settings);
 }
        static void Main(string[] args)
        {
            Client client = new Client();

            IPhoneFactory phoneFactory = client.GetInstance(FactoryName.SAMSUNG);
            IDump         dump         = phoneFactory.Dump();
            string        name         = dump.GetName("Hey this is SAMSUNG S8");

            ISmart smart       = phoneFactory.Smart();
            string modelNumber = smart.GetModelNumber("XT672K");

            System.Console.WriteLine(name + Environment.NewLine);
            System.Console.WriteLine(modelNumber + Environment.NewLine);

            Console.WriteLine("Hello World!");
        }
 public void CheckProducts()
 {
     if (factory != null)    // Checks to see if factory is null because no factory means no products.
     {
         Console.WriteLine(manu + " Factory Production:");
         ISmart sPhone = factory.GetSmart();
         IDumb  dPhone = factory.GetDumb();
         Console.Write("Smartphone: ");
         Console.WriteLine(manu + " " + sPhone.getName()); // Prints out the Manufacturer and Model of Smartphone
         Console.Write("Dumb-Phone: ");
         Console.WriteLine(manu + " " + dPhone.getName()); // Prints out the Manufacturer and Model of Dumbphone
     }
     else
     {
         Console.WriteLine("No factory. No products.");
     }
 }
        protected AbstractHarddrive(ISmart smart, string name, 
            string firmwareRevision, int index,
            IEnumerable<SmartAttribute> smartAttributes, ISettings settings)
            : base(name, new Identifier("hdd",
        index.ToString(CultureInfo.InvariantCulture)), settings)
        {
            this.firmwareRevision = firmwareRevision;
              this.smart = smart;
              handle = smart.OpenDrive(index);

              smart.EnableSmart(handle, index);

              this.index = index;
              this.count = 0;

              this.smartAttributes = new List<SmartAttribute>(smartAttributes);

              CreateSensors();
        }
        protected AbstractHarddrive(ISmart smart, string name,
                                    string firmwareRevision, int index,
                                    IEnumerable <SmartAttribute> smartAttributes, ISettings settings)
            : base(name, new Identifier("hdd",
                                        index.ToString(CultureInfo.InvariantCulture)), settings)
        {
            this.firmwareRevision = firmwareRevision;
            this.smart            = smart;
            handle = smart.OpenDrive(index);

            smart.EnableSmart(handle, index);

            this.index = index;
            this.count = 0;

            this.smartAttributes = new List <SmartAttribute>(smartAttributes);

            CreateSensors();
        }
Example #12
0
        internal HardDrive(ISmart smart, string name,
                           string firmwareRevision, int index,
                           IEnumerable <SmartAttribute> smartAttributes)
            : base(name, $"hdd/{index}")
        {
            this.FirmwareRevision = firmwareRevision;
            this.smart            = smart;
            handle = smart.OpenDrive(index);

            if (handle != smart.InvalidHandle)
            {
                smart.EnableSmart(handle, index);
            }

            this.index = index;
            count      = 0;

            this.SmartAttributes = new List <SmartAttribute>(smartAttributes);

            var logicalDrives = smart.GetLogicalDrives(index);
            var driveInfoList = new List <DriveInfo>(logicalDrives.Length);

            foreach (var logicalDrive in logicalDrives)
            {
                try
                {
                    var di = new DriveInfo(logicalDrive);
                    if (di.TotalSize > 0)
                    {
                        driveInfoList.Add(new DriveInfo(logicalDrive));
                    }
                }
                catch (ArgumentException)
                {
                }
            }
Example #13
0
 public GenericHarddisk(ISmart smart, string name, string firmwareRevision,
                        int index, ISettings settings)
     : base(smart, name, firmwareRevision, "hdd", index, smartAttributes, settings)
 {
 }
 public SsdSandforce(StorageInfo storageInfo, ISmart smart, string name, string firmwareRevision, int index, ISettings settings)
     : base(storageInfo, smart, name, firmwareRevision, "ssd", index, _smartAttributes, settings)
 {
     _writeAmplification = new Sensor("Write Amplification", 1, SensorType.Factor, this, settings);
 }
Example #15
0
        public static AbstractHarddrive CreateInstance(ISmart smart, 
      int driveIndex, ISettings settings)
        {
            IntPtr deviceHandle = smart.OpenDrive(driveIndex);

              string name = null;
              string firmwareRevision = null;
              DriveAttributeValue[] values = { };

              if (deviceHandle != smart.InvalidHandle) {
            bool nameValid = smart.ReadNameAndFirmwareRevision(deviceHandle,
            driveIndex, out name, out firmwareRevision);
            bool smartEnabled = smart.EnableSmart(deviceHandle, driveIndex);

            if (smartEnabled)
              values = smart.ReadSmartData(deviceHandle, driveIndex);

            smart.CloseHandle(deviceHandle);

            if (!nameValid) {
              name = null;
              firmwareRevision = null;
            }
              } else {
            string[] logicalDrives = smart.GetLogicalDrives(driveIndex);
            if (logicalDrives == null || logicalDrives.Length == 0)
              return null;
              }

              if (string.IsNullOrEmpty(name))
            name = "Generic Hard Disk";

              if (string.IsNullOrEmpty(firmwareRevision))
            firmwareRevision = "Unknown";

              foreach (Type type in hddTypes) {
            // get the array of name prefixes for the current type
            NamePrefixAttribute[] namePrefixes = type.GetCustomAttributes(
              typeof(NamePrefixAttribute), true) as NamePrefixAttribute[];

            // get the array of the required SMART attributes for the current type
            RequireSmartAttribute[] requiredAttributes = type.GetCustomAttributes(
              typeof(RequireSmartAttribute), true) as RequireSmartAttribute[];

            // check if all required attributes are present
            bool allRequiredAttributesFound = true;
            foreach (var requireAttribute in requiredAttributes) {
              bool adttributeFound = false;
              foreach (DriveAttributeValue value in values) {
            if (value.Identifier == requireAttribute.AttributeId) {
              adttributeFound = true;
              break;
            }
              }
              if (!adttributeFound) {
            allRequiredAttributesFound = false;
            break;
              }
            }

            // if an attribute is missing, then try the next type
            if (!allRequiredAttributesFound)
              continue;

            // check if there is a matching name prefix for this type
            foreach (NamePrefixAttribute prefix in namePrefixes) {
              if (name.StartsWith(prefix.Prefix, StringComparison.InvariantCulture))
            return Activator.CreateInstance(type, smart, name, firmwareRevision,
              driveIndex, settings) as AbstractHarddrive;
            }
              }

              // no matching type has been found
              return null;
        }
Example #16
0
 public SSDPlextor(ISmart smart, string name, string firmwareRevision,
                   int index, ISettings settings)
     : base(smart, name, firmwareRevision, "ssd", index, smartAttributes, settings)
 {
 }
        public static AbstractHarddrive CreateInstance(ISmart smart,
                                                       int driveIndex, ISettings settings)
        {
            IntPtr deviceHandle = smart.OpenDrive(driveIndex);

            string name             = null;
            string firmwareRevision = null;

            DriveAttributeValue[] values = { };

            if (deviceHandle != smart.InvalidHandle)
            {
                bool nameValid = smart.ReadNameAndFirmwareRevision(deviceHandle,
                                                                   driveIndex, out name, out firmwareRevision);
                bool smartEnabled = smart.EnableSmart(deviceHandle, driveIndex);

                if (smartEnabled)
                {
                    values = smart.ReadSmartData(deviceHandle, driveIndex);
                }

                smart.CloseHandle(deviceHandle);

                if (!nameValid)
                {
                    name             = null;
                    firmwareRevision = null;
                }
            }
            else
            {
                string[] logicalDrives = smart.GetLogicalDrives(driveIndex);
                if (logicalDrives == null || logicalDrives.Length == 0)
                {
                    return(null);
                }
            }

            if (string.IsNullOrEmpty(name))
            {
                name = "Generic Hard Disk";
            }

            if (string.IsNullOrEmpty(firmwareRevision))
            {
                firmwareRevision = "Unknown";
            }

            foreach (Type type in hddTypes)
            {
                // get the array of name prefixes for the current type
                NamePrefixAttribute[] namePrefixes = type.GetCustomAttributes(
                    typeof(NamePrefixAttribute), true) as NamePrefixAttribute[];

                // get the array of the required SMART attributes for the current type
                RequireSmartAttribute[] requiredAttributes = type.GetCustomAttributes(
                    typeof(RequireSmartAttribute), true) as RequireSmartAttribute[];

                // check if all required attributes are present
                bool allRequiredAttributesFound = true;
                foreach (var requireAttribute in requiredAttributes)
                {
                    bool adttributeFound = false;
                    foreach (DriveAttributeValue value in values)
                    {
                        if (value.Identifier == requireAttribute.AttributeId)
                        {
                            adttributeFound = true;
                            break;
                        }
                    }
                    if (!adttributeFound)
                    {
                        allRequiredAttributesFound = false;
                        break;
                    }
                }

                // if an attribute is missing, then try the next type
                if (!allRequiredAttributesFound)
                {
                    continue;
                }

                // check if there is a matching name prefix for this type
                foreach (NamePrefixAttribute prefix in namePrefixes)
                {
                    if (name.StartsWith(prefix.Prefix, StringComparison.InvariantCulture))
                    {
                        return(Activator.CreateInstance(type, smart, name, firmwareRevision,
                                                        driveIndex, settings) as AbstractHarddrive);
                    }
                }
            }

            // no matching type has been found
            return(null);
        }
Example #18
0
 public GenericHarddisk(ISmart smart, string name, string firmwareRevision, 
   int index, ISettings settings)
   : base(smart, name, firmwareRevision, index, smartAttributes, settings) {}
Example #19
0
 public SSDSamsung(ISmart smart, string name, string firmwareRevision,
   int index, ISettings settings)
   : base(smart, name, firmwareRevision, index, smartAttributes, settings) { }
Example #20
0
 internal GenericHardDisk(StorageInfo storageInfo, ISmart smart, string name, string firmwareRevision, int index, ISettings settings)
     : base(storageInfo, smart, name, firmwareRevision, "hdd", index, _smartAttributes.AsIReadOnlyList(), settings)
 {
 }
Example #21
0
 public SSDSamsung(ISmart smart, string name, string firmwareRevision,
                   int index, ISettings settings)
     : base(smart, name, firmwareRevision, index, smartAttributes, settings)
 {
 }
Example #22
0
 public GenericHarddisk(ISmart smart, string name, string firmwareRevision,
                        int index)
     : base(smart, name, firmwareRevision, index, smartAttributes)
 {
 }
Example #23
0
 public SSDIntel(ISmart smart, string name, string firmwareRevision,
                 int index)
     : base(smart, name, firmwareRevision, index, smartAttributes)
 {
 }
Example #24
0
 public SsdPlextor(StorageInfo storageInfo, ISmart smart, string name, string firmwareRevision, int index, ISettings settings)
     : base(storageInfo, smart, name, firmwareRevision, "ssd", index, _smartAttributes, settings)
 {
 }