The current structure of my classes goes a little bit like this:
PC.Processor.Architecture[0] = The Architecture of the first processor (assuming a multi-processor system).
How I ideally want it is more like this:
PC.Processor[0].Architecture, because it’s a bit more self explanatory this way.
Is there a fairly efficient way of doing this with what I have? Bear in mind there are like, over 9000 properties in each of the classes Processor, Motherboard, Memory etc and WMI calls are not CPU-cheap to run.
Here are the important snippets for my classes
class PC
{
public Processor Processor;
public Motherboard Motherboard;
// Constructor
public PC()
{
Processor = new Processor();
Motherboard = new Motherboard();
}
// Method to get all info sequentially
public void GetAllInfo()
{
Processor.GetInfo();
Motherboard.GetInfo();
}
}
class Processor
{
public string[] Architecture;
public string[] Availability;
public UInt16[] Cores;
public void GetInfo()
{
// Get WMI Information from custom process
// Returns as an array of ManagementObjects for each matched device (which is a bit like an array of dictionaries)
ManagementObject[] WMIData = DataRetriever.GetWMIData("Win32_Processor");
try
{
for (int i = 1; i < WMIData.Length; i++)
{
this.Architecture[i] = (string)WMIData[i]["Architecture"];
this.Availability[i] = (string)WMIData[i]["Availability"];
this.Cores[i] = (UInt16)WMIData[i]["NumberOfCores"];
}
}
catch (NullReferenceException e)
{
// To be implemented
}
}
}
FURTHERMORE
There may be more than one WMI search query per class. For example, HardDrive needs to make use of both Win32_PhysicalMedia and ATAPI_SmartData (or whatever the class actually is.)
Thanks to everyone who’s responded.
I’ve come up with a reasonably elegant solution that suits my needs.
PC Class Example:
Processor Class Example:
Usage example:
In the event a device needs to query more than one WMI class, each additional class can be listed as an extra parameter in the device constructor and GetInfo() method.