Example #1
0
        static void Main(string[] args)
        {
            DmiStructureCollection structures = DMI.CreateInstance().Structures;

            // type 0
            string biosVersion = GetSmbiosProperty(structures, DmiProperty.Bios.BiosVersion);
        }
Example #2
0
 //[DeploymentItem("TestFiles/human.dmi", "TestFiles")]
 public void DMIConstructorTest()
 {
     string icon = Path.Combine("TestFiles","human.dmi");
     string icon_state = string.Empty; // TODO: Initialize to an appropriate value
     DMI target = new DMI(icon);
     //testContextInstance.WriteLine("width = {0}, height={1}", target.Width, target.Height);
 }
Example #3
0
 //[DeploymentItem("TestFiles/human.dmi", "TestFiles")]
 public void DMIConstructorTest()
 {
     string icon       = Path.Combine("TestFiles", "human.dmi");
     string icon_state = string.Empty; // TODO: Initialize to an appropriate value
     DMI    target     = new DMI(icon);
     //testContextInstance.WriteLine("width = {0}, height={1}", target.Width, target.Height);
 }
        /// <summary>
        /// Process the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            DMI dmi = DMI.CreateInstance();
            DmiStructureCollection structures = dmi.Structures;
            DmiStructure           structure  = structures[Class];
            DmiClass @class = structure.Elements[0];
            IEnumerable <IPropertyKey> properties = @class.ImplementedProperties;

            var result = new List <PropertyDefinitionResult>();

            foreach (var property in properties)
            {
                result.Add(
                    new PropertyDefinitionResult
                {
                    Class              = Class,
                    ClassId            = (int)Class,
                    HexadecimalClassId = $"{(int)Class:X2}",
                    ImplementedVersion = $"{(@class.ImplementedVersion == DmiStructureVersion.Latest ? "Latest" : @class.ImplementedVersion.ToString())}",
                    PropertyKey        = property
                });
            }

            WriteObject((PropertyDefinitionResult[])result.ToArray().Clone(), true);
        }
        void SetIcon()
        {
            Texture2D tex1 = DMI.LoadTexture(EnabledSymbol);
            Texture2D tex2 = DMI.LoadTexture(DisabledSymbol);

            EnabledTexture  = new TexturePrimitive(tex1, new Vector2((Width - tex1.Width * DMI.MipMapScale) / 2, (Height - tex1.Height * DMI.MipMapScale) / 2));
            DisabledTexture = new TexturePrimitive(tex2, new Vector2((Width - tex2.Width * DMI.MipMapScale) / 2, (Height - tex2.Height * DMI.MipMapScale) / 2));
        }
Example #6
0
        public override void ScaleChanged()
        {
            ScrollUpTexture[0]   = DMI.LoadTexture("NA_15.bmp");
            ScrollUpTexture[1]   = DMI.LoadTexture("NA_13.bmp");
            ScrollDownTexture[0] = DMI.LoadTexture("NA_16.bmp");
            ScrollDownTexture[1] = DMI.LoadTexture("NA_14.bmp");

            SetFont();
        }
Example #7
0
        /// <summary>
        /// Process the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            DMI dmi = DMI.CreateInstance();
            DmiStructureCollection structures  = dmi.Structures;
            DmiStructure           structure   = structures[Property.Class];
            DmiClass            element        = structure.Elements[Property.Index];
            QueryPropertyResult propertyResult = element.GetProperty(Property.PropertyKey);

            WriteObject(propertyResult.Value);
        }
        /// <summary>
        /// Process the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            var result = new Collection <StructureResult>();
            DmiStructureCollection structures = DMI.CreateInstance().Structures;

            foreach (DmiStructure structure in structures)
            {
                result.Add(
                    new StructureResult
                {
                    Class              = structure.Class,
                    ClassId            = (int)structure.Class,
                    HexadecimalClassId = $"{(int)structure.Class:X2}"
                });
            }

            WriteObject((StructureResult[])result.ToArray().Clone(), true);
        }
Example #9
0
        public override void ScaleChanged()
        {
            SpeedIncreaseTexture        = DMI.LoadTexture("PL_21.png");
            SpeedReductionTexture       = DMI.LoadTexture("PL_22.png");
            YellowSpeedReductionTexture = DMI.LoadTexture("PL_23.png");
            for (int i = 1; i < 37; i++)
            {
                if (i == 21)
                {
                    i = 24;
                }
                Texture2D tex = DMI.LoadTexture("PL_" + (i < 10 ? "0" : "") + i + ".png");
                TrackConditionTextureData[i] = tex;
            }
            TrackConditionTextureData[40] = DMI.LoadTexture("PL_tunnel.png");
            TrackConditionTextureData[41] = DMI.LoadTexture("PL_bridge.png");
            TrackConditionTextureData[42] = DMI.LoadTexture("PL_station.png");
            TrackConditionTextureData[43] = DMI.LoadTexture("PL_endoftrack.png");

            SetFont();
        }
        internal void LoadData(XgdInfo xgdInfo, byte[] dmi, byte[] securitySector,
                               SS.SecuritySector?decodedSecuritySector)
        {
            xboxSecuritySector = securitySector;

            if (xgdInfo != null)
            {
                stkXboxInformation.Visible = true;
                txtXboxL0Video.Text        = $"{xgdInfo.L0Video} sectors";
                txtXboxL1Video.Text        = $"{xgdInfo.L1Video} sectors";
                txtXboxMiddleZone.Text     = $"{xgdInfo.MiddleZone} sectors";
                txtXboxGameSize.Text       = $"{xgdInfo.GameSize} sectors";
                txtXboxTotalSize.Text      = $"{xgdInfo.TotalSize} sectors";
                txtXboxRealBreak.Text      = xgdInfo.LayerBreak.ToString();
            }

            if (dmi != null)
            {
                if (DMI.IsXbox(dmi))
                {
                    grpXboxDmi.Visible = true;
                    txtXboxDmi.Text    = DMI.PrettifyXbox(dmi);
                }
                else if (DMI.IsXbox360(dmi))
                {
                    grpXboxDmi.Visible = true;
                    txtXboxDmi.Text    = DMI.PrettifyXbox360(dmi);
                }
            }

            if (decodedSecuritySector.HasValue)
            {
                grpXboxSs.Visible = true;
                txtXboxSs.Text    = SS.Prettify(decodedSecuritySector);
            }

            btnSaveXboxSs.Visible = securitySector != null;
            Visible = stkXboxInformation.Visible || grpXboxDmi.Visible || grpXboxSs.Visible ||
                      btnSaveXboxSs.Visible;
        }
Example #11
0
        public XboxInfoViewModel([CanBeNull] XgdInfo xgdInfo, [CanBeNull] byte[] dmi, [CanBeNull] byte[] securitySector,
                                 SS.SecuritySector?decodedSecuritySector, Window view)
        {
            _xboxSecuritySector = securitySector;
            _view             = view;
            SaveXboxSsCommand = ReactiveCommand.Create(ExecuteSaveXboxSsCommand);

            if (xgdInfo != null)
            {
                XboxInformationVisible = true;
                XboxL0VideoText        = $"{xgdInfo.L0Video} sectors";
                XboxL1VideoText        = $"{xgdInfo.L1Video} sectors";
                XboxMiddleZoneText     = $"{xgdInfo.MiddleZone} sectors";
                XboxGameSizeText       = $"{xgdInfo.GameSize} sectors";
                XboxTotalSizeText      = $"{xgdInfo.TotalSize} sectors";
                XboxRealBreakText      = xgdInfo.LayerBreak.ToString();
            }

            if (dmi != null)
            {
                if (DMI.IsXbox(dmi))
                {
                    XboxDmiText = DMI.PrettifyXbox(dmi);
                }
                else if (DMI.IsXbox360(dmi))
                {
                    XboxDmiText = DMI.PrettifyXbox360(dmi);
                }
            }

            if (decodedSecuritySector.HasValue)
            {
                XboxSsText = SS.Prettify(decodedSecuritySector);
            }

            SaveXboxSsVisible = securitySector != null;
        }
 /// <summary>
 /// Process the command.
 /// </summary>
 protected override void ProcessRecord()
 {
     WriteObject(DMI.CreateInstance().SmbiosVersion);
 }
Example #13
0
 public void FieldSelected(int index)
 {
     if (!FullScreen)
     {
         var  field = Fields[index];
         bool overrideOperational = field.DataArea.DelayType;
         field.SetAccepted(true);
         if (field.TechnicalRangeInvalid || field.TechnicalResolutionInvalid || (field.OperationalRangeInvalid && !overrideOperational))
         {
             if (field.OperationalRangeInvalid)
             {
                 field.DataArea.DelayType = true;
             }
             return;
         }
         string result = WindowTitle + "\n";
         result += field.Name + "=" + field.AcceptedValue + "\n";
         //if (DMI.ETCSStatus != null) DMI.ETCSStatus.DriverActionResult = result;
         DMI.ExitWindow(this);
     }
     else if (ActiveField == index)
     {
         var  field = Fields[index];
         bool overrideOperational = field.DataArea.DelayType;
         field.SetAccepted(true);
         if (field.TechnicalRangeInvalid || field.TechnicalResolutionInvalid || (field.OperationalRangeInvalid && !overrideOperational))
         {
             if (field.OperationalRangeInvalid)
             {
                 Fields[index].DataArea.DelayType = true;
             }
             for (int i = 0; i < Fields.Count; i++)
             {
                 if (i != index)
                 {
                     Fields[i].DataArea.Enabled = false;
                 }
             }
             PrevButton.Enabled = false;
             NextButton.Enabled = false;
             return;
         }
         if (index + 1 < Fields.Count)
         {
             ActiveField++;
         }
         else
         {
             ActiveField = 0;
         }
         NextButton.Enabled = CurrentPage + 1 < NumPages;
         PrevButton.Enabled = CurrentPage > 0;
         bool allaccepted = true;
         foreach (var f in Fields)
         {
             if (!f.Accepted)
             {
                 allaccepted = false;
                 break;
             }
         }
         if (allaccepted)
         {
             YesButton.Enabled = true;
         }
         else
         {
             YesButton.Enabled = false;
         }
         PrepareLayout();
     }
     else
     {
         ActiveField = index;
         PrepareLayout();
     }
 }
Example #14
0
        public DataEntryWindow(DMIDataEntryDefinition definition, DriverMachineInterface dmi) : base(definition.WindowTitle, definition.FullScreen || definition.Fields.Count > 1, dmi)
        {
            Definition = definition;
            Title      = definition.WindowTitle;
            int i = 0;

            LabelFont = GetFont(FontHeightLabel);
            foreach (var field in Definition.Fields)
            {
                Fields.Add(new DataEntryField(field, i, this, !FullScreen));
                i++;
            }
            if (FullScreen)
            {
                NextButton = new DMIIconButton("NA_17.bmp", "NA_18.2.bmp", Viewer.Catalog.GetString("Next"), true, () =>
                {
                    if ((ActiveField / 4) < (Fields.Count / 4))
                    {
                        NextButton.Enabled = false;
                        PrevButton.Enabled = true;
                        ActiveField        = 4 * (ActiveField / 4 + 1);
                        PrepareLayout();
                    }
                }, 82, 50, dmi);
                PrevButton = new DMIIconButton("NA_18.bmp", "NA_19.bmp", Viewer.Catalog.GetString("Next"), true, () =>
                {
                    if (ActiveField > 3)
                    {
                        NextButton.Enabled = true;
                        PrevButton.Enabled = false;
                        ActiveField        = 4 * (ActiveField / 4 - 1);
                        PrepareLayout();
                    }
                }, 82, 50, dmi);
                DataEntryCompleteLabel = new DMITextLabel(Title + " data entry complete?", 334, 50, dmi);
                YesButton = new DMIYesButton(dmi);
                YesButton.PressedAction = () =>
                {
                    bool overrideOperational = YesButton.DelayType;
                    YesButton.DelayType = false;
                    Dictionary <string, string> values = new Dictionary <string, string>();
                    foreach (var field in Fields)
                    {
                        values[field.Name] = field.AcceptedValue;
                    }
                    bool checkPassed = true;
                    foreach (var check in Definition.TechnicalCrossChecks)
                    {
                        var conflict = check.GetConflictingVariables(values);
                        foreach (var name in conflict)
                        {
                            foreach (var field in Fields)
                            {
                                if (field.Name == name)
                                {
                                    checkPassed = false;
                                    field.TechnicalCrossCheckInvalid = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!checkPassed)
                    {
                        return;
                    }
                    if (overrideOperational)
                    {
                        foreach (var check in Definition.OperationalCrossChecks)
                        {
                            var conflict = check.GetConflictingVariables(values);
                            foreach (var name in conflict)
                            {
                                foreach (var field in Fields)
                                {
                                    if (field.Name == name)
                                    {
                                        checkPassed = false;
                                        field.OperationalCrossCheckInvalid = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (!checkPassed)
                    {
                        YesButton.DelayType = true;
                        return;
                    }
                    string result = WindowTitle + "\n";
                    foreach (var field in Fields)
                    {
                        result += field.Name + "=" + field.AcceptedValue + "\n";
                    }
                    //if (DMI.ETCSStatus != null) DMI.ETCSStatus.DriverActionResult = result;
                    DMI.ExitWindow(this);
                };
                YesButton.ExtendedSensitiveArea = new Rectangle(0, 50, 0, 0);
                PrevButton.Enabled = false;
                NextButton.Enabled = false;
            }
            if (Fields.Count > 4)
            {
                NextButton.Enabled = true;
            }
            PrepareLayout();
            Visible = true;
        }
Example #15
0
        /// <summary>
        /// Process the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            DMI dmi = DMI.CreateInstance();

            var result     = new List <PropertyDefinitionResult>();
            var structures = dmi.Structures;

            foreach (var structure in structures)
            {
                int index = 0;
                DmiClassCollection elements = structure.Elements;
                foreach (DmiClass element in elements)
                {
                    IEnumerable <IPropertyKey> properties = element.ImplementedProperties;
                    foreach (IPropertyKey propertyKey in properties)
                    {
                        if (!propertyKey.PropertyId.ToString().Equals(Name, StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        result.Add(
                            new PropertyDefinitionResult
                        {
                            Index              = index,
                            Class              = structure.Class,
                            ClassId            = (int)structure.Class,
                            HexadecimalClassId = $"{(int)structure.Class:X2}",
                            ImplementedVersion = $"{(element.ImplementedVersion == DmiStructureVersion.Latest ? "Latest" : element.ImplementedVersion.ToString())}",
                            PropertyKey        = propertyKey
                        });
                    }

                    index++;
                }
            }

            IEnumerable <PropertyDefinitionResult> classFiltered =
                Class.HasValue
                    ? result.Where(property => property.Class == Class).ToList()
                    : (result as IEnumerable <PropertyDefinitionResult>).ToList();

            IEnumerable <PropertyDefinitionResult> indexfFiltered;

            if (Index.HasValue)
            {
                indexfFiltered =
                    classFiltered.Any()
                        ? classFiltered.Where(property => property.Index == Index).ToList()
                        : result.Where(property => property.Index == Index).ToList();
            }
            else
            {
                indexfFiltered = (classFiltered as IEnumerable <PropertyDefinitionResult>).ToList();
            }

            if (indexfFiltered.Count() == 1)
            {
                WriteObject(indexfFiltered.FirstOrDefault());
            }
            else
            {
                WriteObject((PropertyDefinitionResult[])indexfFiltered.ToArray().Clone(), true);
            }
        }
Example #16
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();
        }
Example #17
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(@" ——————————————————————————————————————————————————————————————");

                    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(key.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(@" ——————————————————————————————————————————————————————————————");

            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}");

            ushort currentSpeed = structures.GetProperty <ushort>(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();
        }
Example #18
0
        /// <summary>
        /// Intialize all the stock indicators
        /// </summary>
        private IList <TechnicalIndicatorBase> InitializeIndicators(DeepQStockContext DbContext, PeriodType type)
        {
            var atr = DbContext.AverageTrueRanges.SingleOrDefault(a => a.StockExchangeId == Parameters.Id && a.Type == type);

            if (atr == null)
            {
                atr = new AverageTrueRange(type, Parameters.Id);
                DbContext.AverageTrueRanges.Add(atr);
            }

            var ma8 = DbContext.SimpleMovingAverages.SingleOrDefault(a => a.StockExchangeId == Parameters.Id && a.Type == type && a.Size == 8);

            if (ma8 == null)
            {
                ma8 = new SimpleMovingAverage(type, Parameters.Id, 8);
                DbContext.SimpleMovingAverages.Add(ma8);
            }

            var ema20 = DbContext.ExponentialMovingAverages.SingleOrDefault(a => a.StockExchangeId == Parameters.Id && a.Type == type && a.Size == 20);

            if (ema20 == null)
            {
                ema20 = new ExponentialMovingAverage(type, Parameters.Id, 20);
                DbContext.ExponentialMovingAverages.Add(ema20);
            }

            var ema50 = DbContext.ExponentialMovingAverages.SingleOrDefault(a => a.StockExchangeId == Parameters.Id && a.Type == type && a.Size == 50);

            if (ema50 == null)
            {
                ema50 = new ExponentialMovingAverage(type, Parameters.Id, 50);
                DbContext.ExponentialMovingAverages.Add(ema50);
            }

            var ema200 = DbContext.ExponentialMovingAverages.SingleOrDefault(a => a.StockExchangeId == Parameters.Id && a.Type == type && a.Size == 200);

            if (ema200 == null)
            {
                ema200 = new ExponentialMovingAverage(type, Parameters.Id, 200);
                DbContext.ExponentialMovingAverages.Add(ema200);
            }

            var rsi = DbContext.RSIs.SingleOrDefault(a => a.StockExchangeId == Parameters.Id && a.Type == type);

            if (rsi == null)
            {
                rsi = new RSI(type, Parameters.Id);
                DbContext.RSIs.Add(rsi);
            }

            var dmi = DbContext.DMIs.SingleOrDefault(a => a.StockExchangeId == Parameters.Id && a.Type == type);

            if (dmi == null)
            {
                dmi = new DMI(type, Parameters.Id, atr: atr);
                DbContext.DMIs.Add(dmi);
            }

            var macd = DbContext.MACDs.SingleOrDefault(a => a.StockExchangeId == Parameters.Id && a.Type == type);

            if (macd == null)
            {
                macd = new MACD(type, Parameters.Id);
                DbContext.MACDs.Add(macd);
            }

            var bollingerB = DbContext.BollingerBandsPercentBs.SingleOrDefault(a => a.StockExchangeId == Parameters.Id && a.Type == type);

            if (bollingerB == null)
            {
                bollingerB = new BollingerBandsPercentB(type, Parameters.Id);
                DbContext.BollingerBandsPercentBs.Add(bollingerB);
            }

            return(new List <TechnicalIndicatorBase>()
            {
                ma8, ema20, ema50, ema200, atr, rsi, dmi, macd, bollingerB
            });
        }