本文整理汇总了C#中System.Management.ManagementObjectCollection类的典型用法代码示例。如果您正苦于以下问题:C# ManagementObjectCollection类的具体用法?C# ManagementObjectCollection怎么用?C# ManagementObjectCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ManagementObjectCollection类属于System.Management命名空间,在下文中一共展示了ManagementObjectCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Baseboard
public Baseboard(ManagementObjectCollection queryResult)
{
foreach (var obj in queryResult) {
foreach (var data in obj.Properties) {
switch (data.Name) {
case "Manufacturer":
this.Manufacturer = data.Value.ToString();
break;
case "Model":
try {
this.Model = data.Value.ToString();
} catch (NullReferenceException) {
this.Model = String.Empty;
}
break;
case "Product":
this.Product = data.Value.ToString();
break;
case "SerialNumber":
this.SerialNumber = data.Value.ToString();
break;
}
}
}
}
示例2: VideoController
public VideoController(ManagementObjectCollection queryResult)
{
foreach (var obj in queryResult) {
foreach (var data in obj.Properties) {
switch (data.Name) {
case "AdapterCompatibility":
this.AdapterCompatibility = data.Value.ToString();
break;
case "AdapterRam":
this.AdapterRam = data.Value.ToString();
break;
case "Name":
this.Name = data.Value.ToString();
break;
case "VideoModeDescription":
this.VideoModeDescription = data.Value.ToString();
break;
case "VideoProcessor":
try {
this.VideoProcessor = data.Value.ToString();
} catch (NullReferenceException) {
this.VideoProcessor = String.Empty;
}
break;
case "VideoMemoryType":
this.VideoMemoryType = data.Value.ToString();
break;
}
}
}
}
示例3: CCM_DCMBaselines
/// <summary>
/// Get DCM Baselines (Class SMS_DesiredConfiguration)
/// </summary>
/// <param name="refresh">true=reload;false=get cached objects</param>
/// <returns>Class SMS_DesiredConfiguration</returns>
public ManagementObjectCollection CCM_DCMBaselines(bool refresh)
{
if (refresh)
{
oDCMBaselines = null;
}
return CCM_DCMBaselines();
}
示例4: PopulateClassesList
public WmiResult PopulateClassesList(ManagementObjectCollection pManagementClasses)
{
Classes = new List<string>();
CollectedClasses = pManagementClasses;
foreach (ManagementObject WmiClass in pManagementClasses)
{
Classes.Add(WmiClass["__Class"].ToString());
}
return this;
}
示例5: MotherboardDevice
public MotherboardDevice(ManagementObjectCollection queryResult)
{
foreach (var obj in queryResult) {
foreach (var data in obj.Properties) {
switch (data.Name) {
case "Manufacturer":
this.Manufacturer = data.Value.ToString();
break;
}
}
}
}
示例6: GetFirstObjectFromCollection
/// <summary>
/// Gets the first object in a collection of ManagementObject instances.
/// </summary>
/// <param name="collection">The collection of ManagementObject instances.</param>
/// <returns>The first object in the collection</returns>
public static ManagementObject GetFirstObjectFromCollection(ManagementObjectCollection collection)
{
if (collection.Count == 0)
{
throw new ArgumentException("The collection contains no objects", "collection");
}
foreach (ManagementObject managementObject in collection)
{
return managementObject;
}
return null;
}
示例7: GetEventRecordList
public List<LogFilterRow> GetEventRecordList(ManagementObjectCollection mossos, List<string> searchTermList)
{
var eventRecordList = new List<LogFilterRow>();
int sTCount = searchTermList.Count;
foreach (var serv in ListOfServersToQuery)
{
var insertionStrings = String.Empty;
foreach (var mo in mossos)
{
var eventRec = new LogFilterRow();
string timeWrittenStr = (mo["TimeWritten"] != null) ? mo["TimeWritten"].ToString() : String.Empty;
eventRec.Time = ManagementDateTimeConverter.ToDateTime(timeWrittenStr);
// DateTime.ParseExact(timeWrittenStr, "yyyyMMddHHmmss.ffffff-zzz", provider);
eventRec.LogType = Global_Const.EVENTLOGTYPE;
eventRec.Src = serv + "\\EventLog\\" + Global_Const.SOURCE;
string sourceName = (mo["SourceName"] != null) ? mo["SourceName"].ToString() : String.Empty;
string message = (mo["Message"] != null) ? mo["Message"].ToString() : String.Empty;
if (mo["InsertionStrings"] != null)
{
var strList = (String[]) mo["InsertionStrings"];
insertionStrings = strList.Aggregate(insertionStrings,
(current, insString) => current + (" " + insString));
}
else
{
insertionStrings = String.Empty;
}
// var eventRec = new EventRecord((ManagementObject)mo);
//Filter out all data that contains records that we are interested in.
for (int index = 0; index < sTCount; index++)
{
var searchTerm = searchTermList[index];
if (sourceName.Contains(searchTerm) || message.Contains(searchTerm) ||
insertionStrings.Contains(searchTerm))
{
// eventRec.SearchT = "Word_" + index.ToString(CultureInfo.InvariantCulture);
eventRec.Msg = message + " -- " + insertionStrings;
eventRecordList.Add(eventRec);
insertionStrings = String.Empty;
message = String.Empty;
break;
}
insertionStrings = String.Empty;
message = String.Empty;
}
}
}
return eventRecordList;
}
示例8: DiskDrive
public DiskDrive(ManagementObjectCollection queryResult)
{
foreach (var obj in queryResult) {
foreach (var data in obj.Properties) {
switch (data.Name) {
case "Model":
this.Model = data.Value.ToString();
break;
case "Size":
this.Size = data.Value.ToString();
break;
case "Manufacturer":
this.Manufacturer = data.Value.ToString();
break;
}
}
}
}
示例9: BIOS
public BIOS(ManagementObjectCollection queryResult)
{
foreach (var obj in queryResult) {
foreach (var data in obj.Properties) {
switch (data.Name) {
case "Manufacturer":
this.Manufacturer = data.Value.ToString();
break;
case "SerialNumber":
this.SerialNumber = data.Value.ToString();
break;
case "SMBIOSBIOSVersion":
this.SMBIOSBIOSVersion = data.Value.ToString();
break;
}
}
}
}
示例10: Processor
public Processor(ManagementObjectCollection queryResult)
{
foreach (var obj in queryResult) {
foreach (var data in obj.Properties) {
switch (data.Name) {
case "Manufacturer":
this.Manufacturer = data.Value.ToString();
break;
case "Name":
this.Name = data.Value.ToString();
break;
case "Description":
this.Description = data.Value.ToString();
break;
case "MaxClockSpeed":
this.MaxClockSpeed = data.Value.ToString();
break;
case "L2CacheSize":
this.L2CacheSize = data.Value.ToString();
break;
case "AddressWidth":
this.AddressWidth = data.Value.ToString();
break;
case "DataWidth":
this.DataWidth = data.Value.ToString();
break;
case "NumberOfCores":
this.NumberOfCores = data.Value.ToString();
break;
case "NumberOfLogicalProcessors":
this.NumberOfLogicalProcessors = data.Value.ToString();
break;
case "ProcessorId":
this.ProcessorId = data.Value.ToString();
break;
}
}
}
}
示例11: PhysicalMemory
public PhysicalMemory(ManagementObjectCollection queryResult)
{
foreach (var obj in queryResult) {
foreach (var data in obj.Properties) {
switch (data.Name) {
case "Capacity":
this.Capacity = data.Value.ToString();
break;
case "DataWidth":
this.DataWidth = data.Value.ToString();
break;
case "FormFactory":
this.FormFactory = data.Value.ToString();
break;
case "MemoryType":
this.MemoryType = data.Value.ToString();
break;
case "Speed":
this.Speed = data.Value.ToString();
break;
}
}
}
}
示例12: MessageInstanceEnumerator
public MessageInstanceEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum)
{
privObjEnum = objEnum;
}
示例13: MessageInstanceCollection
public MessageInstanceCollection(ManagementObjectCollection objCollection)
{
privColObj = objCollection;
}
示例14: ReportVMMetrics
private void ReportVMMetrics(ManagementObjectCollection vms)
{
// Create Management Service
ManagementObject vsms = hyperv.GetVSMS(this.name);
// Create Host metrics
UInt16 numberOfProcs = 0;
UInt16 processorLoad = 0;
UInt64 memoryUsage = 0;
UInt64 hostCapacityBytes = hyperv.GetHostMemoryCapacityBytes(this.name);
foreach (ManagementObject vm in vms)
{
// Name of VM
string name = vm["ElementName"].ToString();
// Create Settings
ManagementObject vmSettings = hyperv.GetVirtualSystemSettingData(this.name, vm["__PATH"].ToString());
// Get VM Settings
ManagementBaseObject inParams = vsms.GetMethodParameters("GetSummaryInformation");
inParams["SettingData"] = new string[1] { vmSettings["__PATH"].ToString() };
// Request CPU Information
inParams["RequestedInformation"] = new int[4] { 4, 100, 101, 103 };
ManagementBaseObject outParams = vsms.InvokeMethod("GetSummaryInformation", inParams, null);
ManagementBaseObject[] value = (ManagementBaseObject[])outParams.GetPropertyValue("SummaryInformation");
UInt16 state = (UInt16)value[0].GetPropertyValue("EnabledState");
numberOfProcs += (UInt16)value[0].GetPropertyValue("NumberOfProcessors");
ReportMetric($"vms/{name}/numberofprocessors", "procs", (UInt16)value[0].GetPropertyValue("NumberOfProcessors"));
if (state == 2)
{
processorLoad += (UInt16)value[0].GetPropertyValue("ProcessorLoad");
ReportMetric($"vms/{name}/processorload", "percent", (UInt16)value[0].GetPropertyValue("ProcessorLoad"));
memoryUsage += (UInt64)value[0].GetPropertyValue("MemoryUsage");
ReportMetric($"vms/{name}/memoryused", "mibibytes", (UInt64)value[0].GetPropertyValue("MemoryUsage"));
}
// Cleanup
inParams.Dispose();
outParams.Dispose();
vmSettings.Dispose();
}
vsms.Dispose();
// Report Host Metrics
ReportMetric($"host/numberofprocessors", "procs", numberOfProcs);
ReportMetric($"host/processorload", "percent", processorLoad);
ReportMetric($"host/vms/memoryused", "mibibytes", memoryUsage);
ReportMetric($"host/vms/memoryused", "percent", (float)(((Decimal)(memoryUsage * 1048576) / (Decimal)hostCapacityBytes) * 100));
}
示例15: ReportReplicationHealth
private void ReportReplicationHealth(ManagementObjectCollection vms)
{
// Create Host metrics
int hostReplicationHealth = 0;
foreach (ManagementObject vm in vms)
{
// Name of VM
string name = vm["ElementName"].ToString();
// Get Replication Mode
hyperv.NewRelicMetric ReplicationMode;
ReplicationMode = hyperv.GetReplicationMode(vm);
// Get Replication Health Status
hyperv.NewRelicMetric ReplicationHealth;
ReplicationHealth = hyperv.GetReplicationHealth(vm);
hostReplicationHealth += (int)ReplicationHealth.Metric;
if (ReplicationMode.Metric == 1)
{
// Primary Replication Node
log.Info($"Primary Node {name} - Health: {ReplicationHealth.Description}");
ReportMetric($"replication/primary/{name}/health", "errors", ReplicationHealth.Metric);
}
else if (ReplicationMode.Metric != 0)
{
// Secondary Replication Node
log.Info($"Secondary Node {name} - Health: {ReplicationHealth.Description}");
ReportMetric($"replication/secondary/{name}/health", "errors", ReplicationHealth.Metric);
}
}
// Report Host Metrics
ReportMetric($"host/vms/replicationhealth", "errors", hostReplicationHealth);
}