Пример #1
0
        /// <summary>
        /// Returns a value that indicates if this structure is equal to another.
        /// </summary>
        /// <param name="obj">Structure with which to compare.</param>
        /// <returns>
        /// Result of the comparison of equality.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (!(obj is PropertyKey))
            {
                return(false);
            }

            var other = (PropertyKey)obj;

            return
                (PropertyId.Equals(other.PropertyId) &&
                 StructureId.Equals(other.StructureId) &&
                 PropertyUnit.Equals(other.PropertyUnit));
        }
Пример #2
0
        static void Main(string[] args)
        {
            EEDID[] instances = EEDID.Instance;
            foreach (var instance in instances)
            {
                //EEDID instance = EEDID.Parse(MacBookPro2018.IntegratedLaptopPanelEdidTable3);

                Console.WriteLine();
                Console.WriteLine(@" Implemented Blocks");
                Console.WriteLine(@" ══════════════════");

                DataBlockCollection blocks = instance.Blocks;
                foreach (KnownDataBlock block in blocks.ImplementedBlocks)
                {
                    Console.WriteLine($@" │ {block}");
                }

                foreach (DataBlock block in blocks)
                {
                    var blockLiteral = $@"{block.Key} Block";

                    Console.WriteLine();
                    Console.WriteLine($@" {blockLiteral}");
                    Console.WriteLine($@" {new string('═', blockLiteral.Length)}");

                    Console.WriteLine();
                    Console.WriteLine(@" Implemented Sections");
                    Console.WriteLine(@" ┌───────────────────");
                    var implSections = instance.Blocks[block.Key].Sections.ImplementedSections;
                    foreach (Enum section in implSections)
                    {
                        Console.WriteLine($@" │ {GetFriendlyName(section)}");
                    }

                    Console.WriteLine();
                    Console.WriteLine(@" Sections");
                    Console.WriteLine(@" ┌───────");
                    BaseDataSectionCollection sections = block.Sections;
                    foreach (DataSection section in sections)
                    {
                        var sectionLiteral = $"{GetFriendlyName(section.Key) } Section";

                        Console.WriteLine($@" │");
                        Console.WriteLine($@" ├ {sectionLiteral}");
                        Console.WriteLine($@" │ ┌{new string('─', sectionLiteral.Length - 1)}");

                        IEnumerable <IPropertyKey> properties = section.ImplementedProperties;
                        foreach (IPropertyKey property in properties)
                        {
                            string       friendlyName = property.GetPropertyName();
                            PropertyUnit valueUnit    = property.PropertyUnit;
                            string       unit         = valueUnit == PropertyUnit.None ? string.Empty : valueUnit.ToString();

                            QueryPropertyResult queryResult  = section.GetProperty(property);
                            PropertyItem        propertyItem = queryResult.Value;
                            object value = propertyItem.Value;
                            if (value == null)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: NULL");
                                continue;
                            }

                            if (value is string)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {value}{unit}");
                            }
                            else if (value is bool)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {value}{unit}");
                            }
                            else if (value is double)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {value}{unit}");
                            }
                            else if (value is byte)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {value}{unit} [{value:X2}h]");
                            }
                            else if (value is short)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {value}{unit} [{value:X4}h]");
                            }
                            else if (value is ushort)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {value}{unit} [{value:X4}h]");
                            }
                            else if (value is int)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {value}{unit} [{value:X4}h]");
                            }
                            else if (value is uint)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {value}{unit} [{value:X4}h]");
                            }
                            else if (value is long)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {value}{unit} [{value:X8}h]");
                            }
                            else if (value is ulong)
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {value}{unit} [{value:X8}h]");
                            }
                            else if (value is PointF)
                            {
                                var pointLiteral = $"{ friendlyName }";
                                Console.WriteLine($@" │ │ {pointLiteral}");
                                Console.WriteLine($@" │ │ ┌{new string('─', pointLiteral.Length - 1)}");
                                Console.WriteLine($@" │ │ │ X: {((PointF)value).X}");
                                Console.WriteLine($@" │ │ │ Y: {((PointF)value).Y}");
                                Console.WriteLine($@" │ │");
                            }
                            else if (value is StandardTimingIdentifierDescriptorItem)
                            {
                                Console.WriteLine($@" │ │ {(StandardTimingIdentifierDescriptorItem)value}");
                            }
                            else if (value.GetType() == typeof(ReadOnlyCollection <byte>))
                            {
                                Console.WriteLine($@" │ │ {friendlyName}: {string.Join(", ", (ReadOnlyCollection<byte>)value)}");
                            }
                            else if (value.GetType() == typeof(ReadOnlyCollection <string>))
                            {
                                Console.WriteLine($@" │ │ {friendlyName}");
                                Console.WriteLine($@" │ │ ┌{new string('─', friendlyName.Length - 1)}");
                                var items = (ReadOnlyCollection <string>)value;
                                foreach (string item in items)
                                {
                                    Console.WriteLine($@" │ │ │ {item}");
                                }
                            }
                            else if (value.GetType() == typeof(ReadOnlyCollection <MonitorResolutionInfo>))
                            {
                                var items = (ReadOnlyCollection <MonitorResolutionInfo>)value;
                                foreach (MonitorResolutionInfo item in items)
                                {
                                    Console.WriteLine($@" │ │ {item}");
                                }
                            }
                            else if (value.GetType() == typeof(SectionPropertiesTable))
                            {
                                Console.WriteLine($@" │ │ {friendlyName}");
                                Console.WriteLine($@" │ │ ┌{new string('─', friendlyName.Length - 1)}");
                                var dataBlockProperties = (SectionPropertiesTable)value;
                                foreach (PropertyItem dataBlockProperty in dataBlockProperties)
                                {
                                    IPropertyKey dataBlockPropertyKey  = (PropertyKey)dataBlockProperty.Key;
                                    string       dataBlockPropertyName = dataBlockPropertyKey.GetPropertyName();

                                    PropertyUnit dataBlockPropertyUnit = dataBlockPropertyKey.PropertyUnit;
                                    string       dataUnit = dataBlockPropertyKey.PropertyUnit == PropertyUnit.None ? string.Empty : dataBlockPropertyUnit.ToString();

                                    object dataBlockPropertyValue = dataBlockProperty.Value;
                                    if (dataBlockPropertyValue.GetType() == typeof(ReadOnlyCollection <byte>))
                                    {
                                        Console.WriteLine($@" │ │ │ {dataBlockPropertyName}: {string.Join(" ", (ReadOnlyCollection<byte>)dataBlockPropertyValue)}");
                                    }
                                    else if (dataBlockPropertyValue.GetType() == typeof(ReadOnlyCollection <string>))
                                    {
                                        var items = (ReadOnlyCollection <string>)dataBlockPropertyValue;
                                        foreach (string item in items)
                                        {
                                            Console.WriteLine($@" │ │ │ {item}");
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine($@" │ │ │ {dataBlockPropertyName}: {dataBlockPropertyValue} {dataUnit}");
                                    }
                                }

                                Console.WriteLine($@" │ │");
                            }
                            else if (value.GetType() == typeof(List <SectionPropertiesTable>))
                            {
                                Console.WriteLine($@" │ │ {friendlyName}");
                                Console.WriteLine($@" │ │ ┌{new string('─', friendlyName.Length - 1)}");
                                var sectionPropertiesCollection = (List <SectionPropertiesTable>)value;
                                foreach (SectionPropertiesTable sectionProperty in sectionPropertiesCollection)
                                {
                                    foreach (PropertyItem dataBlockProperty in sectionProperty)
                                    {
                                        IPropertyKey dataBlockPropertyKey  = (PropertyKey)dataBlockProperty.Key;
                                        string       dataBlockPropertyName = dataBlockPropertyKey.GetPropertyName();

                                        PropertyUnit dataBlockPropertyUnit = dataBlockPropertyKey.PropertyUnit;
                                        string       dataUnit = dataBlockPropertyKey.PropertyUnit == PropertyUnit.None ? string.Empty : dataBlockPropertyUnit.ToString();

                                        object dataBlockPropertyValue = dataBlockProperty.Value;
                                        if (dataBlockPropertyValue.GetType() == typeof(ReadOnlyCollection <string>))
                                        {
                                            Console.WriteLine($@" │ │ │ {dataBlockPropertyName}");
                                            Console.WriteLine($@" │ │ │ ┌{new string('─', dataBlockPropertyName.Length - 1)}");
                                            var items = (ReadOnlyCollection <string>)dataBlockPropertyValue;
                                            foreach (string item in items)
                                            {
                                                Console.WriteLine($@" │ │ │ │ {item}");
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine($@" │ │ │ {dataBlockPropertyName}: {dataBlockPropertyValue} {dataUnit}");
                                        }
                                    }
                                }

                                Console.WriteLine($@" │ │");
                            }
                            else
                            {
                                Console.WriteLine($@" │ │ {friendlyName} > {value}{unit}");
                            }
                        }
                    }

                    Console.WriteLine();
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" > Gets A Single Property Directly From Parsed EDID Data");
            EEDID     parsed    = EEDID.Parse(MacBookPro2018.IntegratedLaptopPanelEdidTable);
            DataBlock edidBlock = parsed.Blocks[KnownDataBlock.EDID];
            BaseDataSectionCollection edidSections  = edidBlock.Sections;
            DataSection         basicDisplaySection = edidSections[(int)KnownEdidSection.BasicDisplay];
            QueryPropertyResult gammaResult         = basicDisplaySection.GetProperty(EedidProperty.Edid.BasicDisplay.Gamma);

            if (gammaResult.Success)
            {
                Console.WriteLine($@"   > Gamma > {gammaResult.Value.Value}");
            }

            Console.ReadLine();
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Availables structures");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            DmiStructureCollection structures = DMI.Instance.Structures;

            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName}");
            }

            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine();
                Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
                Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName} structure detail");
                Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
                DmiClassCollection elements = structure.Elements;
                foreach (DmiClass element in elements)
                {
                    DmiClassPropertiesTable elementProperties = element.Properties;
                    foreach (KeyValuePair <IPropertyKey, object> property in elementProperties)
                    {
                        object value = property.Value;

                        IPropertyKey key          = property.Key;
                        string       friendlyName = GetFriendlyName(key);
                        PropertyUnit valueUnit    = key.PropertyUnit;
                        string       unit         =
                            valueUnit == PropertyUnit.None
                                ? string.Empty
                                : valueUnit.ToString();

                        if (value == null)
                        {
                            Console.WriteLine($@" > {friendlyName} > NULL");
                            continue;
                        }

                        if (value is string)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit}");
                        }
                        else if (value is byte)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X2}h]");
                        }
                        else if (value is short)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is ushort)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is int)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is uint)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is long)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value is ulong)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <byte>))
                        {
                            Console.WriteLine($@" > {friendlyName} > {string.Join(", ", (ReadOnlyCollection<byte>)value)}");
                        }
                        else if (value.GetType() == typeof(DmiGroupAssociationElementCollection))
                        {
                            // prints elements
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <string>))
                        {
                            Console.WriteLine($@" > {friendlyName}");
                            var collection = (ReadOnlyCollection <string>)value;
                            foreach (var entry in collection)
                            {
                                Console.WriteLine($@"   > {entry} {unit}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit}");
                        }
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Gets a single property directly");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");

            object biosVersion = structures.GetProperty(DmiProperty.Bios.BiosVersion);

            if (biosVersion != null)
            {
                Console.WriteLine($@" > BIOS Version > {biosVersion}");
            }

            string biosVendor = structures.GetProperty <string>(DmiProperty.Bios.Vendor);

            Console.WriteLine($@" > BIOS Vendor > {biosVendor}");

            int currentSpeed = structures.GetProperty <int>(DmiProperty.Processor.CurrentSpeed);

            Console.WriteLine($@" > Current Speed > {currentSpeed:N0} {DmiProperty.Processor.CurrentSpeed.PropertyUnit}");

            string processorManufacturer = structures.GetProperty <string>(DmiProperty.Processor.ProcessorManufacturer);

            Console.WriteLine($@" > Processor Manufacturer > {processorManufacturer}");

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Gets a multiple properties directly");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            IDictionary <int, object> systemSlots = structures.GetProperties(DmiProperty.SystemSlots.SlotId);
            bool hasSystemSlots = systemSlots.Any();

            if (!hasSystemSlots)
            {
                Console.WriteLine($@" > There is no system slots information structure in this computer");
            }
            else
            {
                foreach (KeyValuePair <int, object> systemSlot in systemSlots)
                {
                    int element  = systemSlot.Key;
                    var property = ((IEnumerable <KeyValuePair <IPropertyKey, object> >)systemSlot.Value).FirstOrDefault();
                    Console.WriteLine($@" > System Slot ({element}) > {property.Value}");
                }
            }

            Console.ReadLine();
        }
Пример #4
0
        /// <summary>
        /// Parse the <see cref="EEDID"/> given.
        /// </summary>
        /// <param name="instance"><see cref="EEDID"/> instance to parse.</param>
        public void Parse(EEDID instance)
        {
            Logger.Info("");
            Logger.Info(@" Implemented Blocks");
            Logger.Info(@" ══════════════════");

            DataBlockCollection blocks = instance.Blocks;

            foreach (KnownDataBlock block in blocks.ImplementedBlocks)
            {
                Logger.Info($@" │ {block}");
            }

            foreach (DataBlock block in blocks)
            {
                var blockLiteral = $@"{block.Key} Block";

                Logger.Info("");
                Logger.Info($@" {blockLiteral}");
                Logger.Info($@" {new string('═', blockLiteral.Length)}");

                Logger.Info("");
                Logger.Info(@" Implemented Sections");
                Logger.Info(@" ┌───────────────────");
                var implSections = instance.Blocks[block.Key].Sections.ImplementedSections;
                foreach (Enum section in implSections)
                {
                    Logger.Info($@" │ {section.AsFriendlyName()}");
                }

                Logger.Info("");
                Logger.Info(@" Sections");
                Logger.Info(@" ┌───────");
                BaseDataSectionCollection sections = block.Sections;
                foreach (DataSection section in sections)
                {
                    var sectionLiteral = $"{section.Key.AsFriendlyName()} Section";

                    Logger.Info($@" │");
                    Logger.Info($@" ├ {sectionLiteral}");
                    Logger.Info($@" │ ┌{new string('─', sectionLiteral.Length - 1)}");

                    IEnumerable <IPropertyKey> properties = section.ImplementedProperties;
                    foreach (IPropertyKey property in properties)
                    {
                        string       friendlyName = property.GetPropertyName();
                        PropertyUnit valueUnit    = property.PropertyUnit;
                        string       unit         = valueUnit == PropertyUnit.None ? string.Empty : valueUnit.ToString();

                        QueryPropertyResult queryResult  = section.GetProperty(property);
                        PropertyItem        propertyItem = queryResult.Result;
                        object value = propertyItem.Value;
                        if (value == null)
                        {
                            Logger.Info($@" │ │ {friendlyName}: NULL");
                            continue;
                        }

                        if (value is string)
                        {
                            Logger.Info($@" │ │ {friendlyName}: {value}{unit}");
                        }
                        else if (value is bool)
                        {
                            Logger.Info($@" │ │ {friendlyName}: {value}{unit}");
                        }
                        else if (value is double)
                        {
                            Logger.Info($@" │ │ {friendlyName}: {value}{unit}");
                        }
                        else if (value is byte)
                        {
                            Logger.Info($@" │ │ {friendlyName}: {value}{unit} [{value:X2}h]");
                        }
                        else if (value is short)
                        {
                            Logger.Info($@" │ │ {friendlyName}: {value}{unit} [{value:X4}h]");
                        }
                        else if (value is ushort)
                        {
                            Logger.Info($@" │ │ {friendlyName}: {value}{unit} [{value:X4}h]");
                        }
                        else if (value is int)
                        {
                            Logger.Info($@" │ │ {friendlyName}: {value}{unit} [{value:X4}h]");
                        }
                        else if (value is uint)
                        {
                            Logger.Info($@" │ │ {friendlyName}: {value}{unit} [{value:X4}h]");
                        }
                        else if (value is long)
                        {
                            Logger.Info($@" │ │ {friendlyName}: {value}{unit} [{value:X8}h]");
                        }
                        else if (value is ulong)
                        {
                            Logger.Info($@" │ │ {friendlyName}: {value}{unit} [{value:X8}h]");
                        }
                        else if (value is PointF)
                        {
                            var pointLiteral = $"{ friendlyName }";
                            Logger.Info($@" │ │ {pointLiteral}");
                            Logger.Info($@" │ │ ┌{new string('─', pointLiteral.Length - 1)}");
                            Logger.Info($@" │ │ │ X: {((PointF)value).X}");
                            Logger.Info($@" │ │ │ Y: {((PointF)value).Y}");
                            Logger.Info($@" │ │");
                        }
                        else if (value is StandardTimingIdentifierDescriptorItem)
                        {
                            Logger.Info($@" │ │ {(StandardTimingIdentifierDescriptorItem)value}");
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <byte>))
                        {
                            Logger.Info($@" │ │ {friendlyName}: {string.Join(", ", (ReadOnlyCollection<byte>)value)}");
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <string>))
                        {
                            Logger.Info($@" │ │ {friendlyName}");
                            Logger.Info($@" │ │ ┌{new string('─', friendlyName.Length - 1)}");
                            var items = (ReadOnlyCollection <string>)value;
                            foreach (string item in items)
                            {
                                Logger.Info($@" │ │ │ {item}");
                            }
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <MonitorResolutionInfo>))
                        {
                            var items = (ReadOnlyCollection <MonitorResolutionInfo>)value;
                            foreach (MonitorResolutionInfo item in items)
                            {
                                Logger.Info($@" │ │ {item}");
                            }
                        }
                        else if (value.GetType() == typeof(SectionPropertiesTable))
                        {
                            Logger.Info($@" │ │ {friendlyName}");
                            Logger.Info($@" │ │ ┌{new string('─', friendlyName.Length - 1)}");
                            var dataBlockProperties = (SectionPropertiesTable)value;
                            foreach (PropertyItem dataBlockProperty in dataBlockProperties)
                            {
                                IPropertyKey dataBlockPropertyKey  = (PropertyKey)dataBlockProperty.Key;
                                string       dataBlockPropertyName = dataBlockPropertyKey.GetPropertyName();

                                PropertyUnit dataBlockPropertyUnit = dataBlockPropertyKey.PropertyUnit;
                                string       dataUnit = dataBlockPropertyKey.PropertyUnit == PropertyUnit.None ? string.Empty : dataBlockPropertyUnit.ToString();

                                object dataBlockPropertyValue = dataBlockProperty.Value;
                                if (dataBlockPropertyValue.GetType() == typeof(ReadOnlyCollection <byte>))
                                {
                                    Logger.Info($@" │ │ │ {dataBlockPropertyName}: {string.Join(" ", (ReadOnlyCollection<byte>)dataBlockPropertyValue)}");
                                }
                                else if (dataBlockPropertyValue.GetType() == typeof(ReadOnlyCollection <string>))
                                {
                                    var items = (ReadOnlyCollection <string>)dataBlockPropertyValue;
                                    foreach (string item in items)
                                    {
                                        Logger.Info($@" │ │ │ {item}");
                                    }
                                }
                                else
                                {
                                    Logger.Info($@" │ │ │ {dataBlockPropertyName}: {dataBlockPropertyValue} {dataUnit}");
                                }
                            }

                            Logger.Info($@" │ │");
                        }
                        else if (value.GetType() == typeof(List <SectionPropertiesTable>))
                        {
                            Logger.Info($@" │ │ {friendlyName}");
                            Logger.Info($@" │ │ ┌{new string('─', friendlyName.Length - 1)}");
                            var sectionPropertiesCollection = (List <SectionPropertiesTable>)value;
                            foreach (SectionPropertiesTable sectionProperty in sectionPropertiesCollection)
                            {
                                foreach (PropertyItem dataBlockProperty in sectionProperty)
                                {
                                    IPropertyKey dataBlockPropertyKey  = (PropertyKey)dataBlockProperty.Key;
                                    string       dataBlockPropertyName = dataBlockPropertyKey.GetPropertyName();

                                    PropertyUnit dataBlockPropertyUnit = dataBlockPropertyKey.PropertyUnit;
                                    string       dataUnit = dataBlockPropertyKey.PropertyUnit == PropertyUnit.None ? string.Empty : dataBlockPropertyUnit.ToString();

                                    object dataBlockPropertyValue = dataBlockProperty.Value;
                                    if (dataBlockPropertyValue.GetType() == typeof(ReadOnlyCollection <string>))
                                    {
                                        Logger.Info($@" │ │ │ {dataBlockPropertyName}");
                                        Logger.Info($@" │ │ │ ┌{new string('─', dataBlockPropertyName.Length - 1)}");
                                        var items = (ReadOnlyCollection <string>)dataBlockPropertyValue;
                                        foreach (string item in items)
                                        {
                                            Logger.Info($@" │ │ │ │ {item}");
                                        }
                                    }
                                    else
                                    {
                                        Logger.Info($@" │ │ │ {dataBlockPropertyName}: {dataBlockPropertyValue} {dataUnit}");
                                    }
                                }
                            }

                            Logger.Info($@" │ │");
                        }
                        else
                        {
                            Logger.Info($@" │ │ {friendlyName} > {value}{unit}");
                        }
                    }
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Initialize a new instance of the structure <see cref="T:iTin.Core.Hardware.PropertyKey" /> specifying the structure, property and measured unit.
 /// </summary>
 /// <param name="structureId">Structure identifier.</param>
 /// <param name="propertyId">Property identifier.</param>
 /// <param name="propertyUnit">Unit identifier.</param>
 public PropertyKey(Enum structureId, Enum propertyId, PropertyUnit propertyUnit)
 {
     PropertyId   = propertyId;
     StructureId  = structureId;
     PropertyUnit = propertyUnit;
 }
Пример #6
0
        static void Main(string[] args)
        {
            DMI dmi = DMI.CreateInstance();

            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" SMBIOS");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine($@" Version > {dmi.SmbiosVersion}");

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Availables structures");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            DmiStructureCollection structures = dmi.Structures;

            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName}");

                int totalStructures = structure.Elements.Count;
                if (totalStructures > 1)
                {
                    Console.WriteLine($@"     > {totalStructures} structures");
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Implemented SMBIOS Structure Version");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName}");

                DmiClassCollection elements = structure.Elements;
                foreach (DmiClass element in elements)
                {
                    Console.WriteLine($@"     > {element.ImplementedVersion}");
                }
            }

            foreach (DmiStructure structure in structures)
            {
                DmiClassCollection elements = structure.Elements;
                foreach (DmiClass element in elements)
                {
                    Console.WriteLine();
                    Console.WriteLine(element.ImplementedVersion == DmiStructureVersion.Latest
                        ? $@" ———————————————————————————————————————————————————— {element.ImplementedVersion} ——"
                        : $@" ——————————————————————————————————————————————————————— {element.ImplementedVersion} ——");
                    Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName} structure detail");
                    Console.WriteLine(@" ——————————————————————————————————————————————————————————————");

                    IEnumerable <IPropertyKey> properties = element.ImplementedProperties;
                    foreach (var property in properties)
                    {
                        QueryPropertyResult queryResult  = element.GetProperty(property);
                        PropertyItem        propertyItem = queryResult.Result;
                        object       value        = propertyItem.Value;
                        string       friendlyName = property.GetPropertyName();
                        PropertyUnit valueUnit    = property.PropertyUnit;
                        string       unit         = valueUnit == PropertyUnit.None ? string.Empty : valueUnit.ToString();
                        if (value == null)
                        {
                            Console.WriteLine($@" > {friendlyName} > NULL");
                            continue;
                        }

                        if (value is string)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit}");
                        }
                        else if (value is byte)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X2}h]");
                        }
                        else if (value is short)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is ushort)
                        {
                            Console.WriteLine(property.Equals(DmiProperty.MemoryDevice.ConfiguredMemoryClockSpeed)
                                ? $@" > {friendlyName} > {value} {(int.Parse(dmi.SmbiosVersion) > 300 ? PropertyUnit.MTs : PropertyUnit.MHz)} [{value:X4}h]"
                                : $@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is int)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is uint)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is long)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value is ulong)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <byte>))
                        {
                            Console.WriteLine($@" > {friendlyName} > {string.Join(", ", (ReadOnlyCollection<byte>)value)}");
                        }
                        else if (value is DmiGroupAssociationElementCollection)
                        {
                            // prints elements
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <string>))
                        {
                            Console.WriteLine($@" > {friendlyName}");
                            var collection = (ReadOnlyCollection <string>)value;
                            foreach (var entry in collection)
                            {
                                Console.WriteLine($@"   > {entry} {unit}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit}");
                        }
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Gets a single property directly");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");

            QueryPropertyResult biosVersion = structures.GetProperty(DmiProperty.Bios.BiosVersion);

            if (biosVersion.Success)
            {
                Console.WriteLine($@" > BIOS Version > {biosVersion.Result.Value}");
            }

            QueryPropertyResult biosVendor = structures.GetProperty(DmiProperty.Bios.Vendor);

            if (biosVendor.Success)
            {
                Console.WriteLine($@" > BIOS Vendor > {biosVendor.Result.Value}");
            }

            QueryPropertyResult currentSpeed = structures.GetProperty(DmiProperty.Processor.CurrentSpeed);

            if (currentSpeed.Success)
            {
                Console.WriteLine($@" > Current Speed > {currentSpeed.Result.Value} {currentSpeed.Result.Key.PropertyUnit}");
            }

            QueryPropertyResult processorManufacturer = structures.GetProperty(DmiProperty.Processor.ProcessorManufacturer);

            if (processorManufacturer.Success)
            {
                Console.WriteLine($@" > Processor Manufacturer > {processorManufacturer.Result.Value}");
            }

            Console.WriteLine();
            Console.WriteLine(@" ———————————————————————————————————————————————— Collection ——");
            Console.WriteLine(@" Gets a multiple properties directly");
            Console.WriteLine(@"   Handle result as collection");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            QueryPropertyCollectionResult systemSlotsQueryResult = structures.GetProperties(DmiProperty.SystemSlots.SlotDesignation);

            if (!systemSlotsQueryResult.Success)
            {
                Console.WriteLine($@" > Error(s)");
                Console.WriteLine($@"   {systemSlotsQueryResult.Errors.AsMessages().ToStringBuilder()}");
            }
            else
            {
                IEnumerable <PropertyItem> systemSlotsItems = systemSlotsQueryResult.Result.ToList();
                bool hasSystemSlotsItems = systemSlotsItems.Any();
                if (!hasSystemSlotsItems)
                {
                    Console.WriteLine($@" > Sorry, The '{DmiProperty.SystemSlots.SlotId}' property has not implemented on this system");
                }
                else
                {
                    int index = 0;
                    foreach (var systemSlotItem in systemSlotsItems)
                    {
                        Console.WriteLine($@" >  System Slot ({index}) > {systemSlotItem.Value}");
                        index++;
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" ———————————————————————————————————————————————— Dictionary ——");
            Console.WriteLine(@" Gets a multiple properties directly");
            Console.WriteLine(@"   Handle result as dictionary");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            var systemSlotsQueryDictionayResult = systemSlotsQueryResult.AsDictionaryResult();

            if (!systemSlotsQueryDictionayResult.Success)
            {
                Console.WriteLine($@" > Error(s)");
                Console.WriteLine($@"   {systemSlotsQueryDictionayResult.Errors.AsMessages().ToStringBuilder()}");
            }
            else
            {
                var  systemSlotsItems    = systemSlotsQueryDictionayResult.Result.ToList();
                bool hasSystemSlotsItems = systemSlotsItems.Any();
                if (!hasSystemSlotsItems)
                {
                    Console.WriteLine($@" > Sorry, The '{DmiProperty.SystemSlots.SlotId}' property has not implemented on this system");
                }
                else
                {
                    foreach (var systemSlotItemEntry in systemSlotsItems)
                    {
                        var itemIndex = systemSlotItemEntry.Key;
                        var itemValue = systemSlotItemEntry.Value;

                        Console.WriteLine($@" >  System Slot ({itemIndex}) > {itemValue.Value}");
                    }
                }
            }

            Console.ReadLine();
        }
Пример #7
0
        static void Main(string[] args)
        {
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(" Availables structures");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");

            DmiStructureCollection structures = DMI.Instance.Structures;

            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine($@" {(int) structure.Class:D3}-{structure.Class}");
            }

            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine();
                Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
                Console.WriteLine($@" {(int)structure.Class:D3}-{structure.Class} structure detail");
                Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
                DmiClassCollection elements = structure.Elements;
                foreach (DmiClass element in elements)
                {
                    DmiClassPropertiesTable elementProperties = element.Properties;
                    foreach (KeyValuePair <PropertyKey, object> property in elementProperties)
                    {
                        object value = property.Value;

                        PropertyKey key = property.Key;
                        Enum        id  = key.PropertyId;

                        PropertyUnit valueUnit = key.PropertyUnit;
                        string       unit      =
                            valueUnit == PropertyUnit.None
                                ? string.Empty
                                : valueUnit.ToString();

                        if (value == null)
                        {
                            Console.WriteLine($@" > {id} > NULL");
                            continue;
                        }

                        if (value is string)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit}");
                        }
                        else if (value is byte)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X2}h]");
                        }
                        else if (value is short)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is ushort)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is int)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is uint)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is long)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value is ulong)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <byte>))
                        {
                            Console.WriteLine($@" > {id} > {string.Join(", ", (ReadOnlyCollection<byte>)value)}");
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <string>))
                        {
                            Console.WriteLine($@" > {id}");
                            var collection = (ReadOnlyCollection <string>)value;
                            foreach (var entry in collection)
                            {
                                Console.WriteLine($@"   > {entry} {unit}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($@" > {id} > {value} {unit}");
                        }
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Gets a single property directly");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");

            object biosVersion = structures.GetProperty(DmiProperty.Bios.BiosVersion);

            if (biosVersion != null)
            {
                Console.WriteLine($" > BIOS Version > {biosVersion}");
            }

            string biosVendor = structures.GetProperty <string>(DmiProperty.Bios.Vendor);

            Console.WriteLine($" > BIOS Vendor > {biosVendor}");

            string processorFamily = structures.GetProperty <string>(DmiProperty.Processor.Family);

            Console.WriteLine($" > Processor Family > {processorFamily}");

            string processorManufacturer = structures.GetProperty <string>(DmiProperty.Processor.ProcessorManufacturer);

            Console.WriteLine($" > Processor Manufacturer > {processorManufacturer}");

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Gets a multiple properties directly");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            IDictionary <int, object> systemSlots = structures.GetProperties(DmiProperty.SystemSlots.SlotId);

            foreach (KeyValuePair <int, object> systemSlot in systemSlots)
            {
                int    element  = systemSlot.Key;
                object property = systemSlot.Value;
                Console.WriteLine($" > System Slot ({element}) > {property}");
            }

            Console.ReadLine();
        }