本文整理汇总了C#中System.Management.ManagementObjectSearcher.SelectMany方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObjectSearcher.SelectMany方法的具体用法?C# ManagementObjectSearcher.SelectMany怎么用?C# ManagementObjectSearcher.SelectMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.ManagementObjectSearcher
的用法示例。
在下文中一共展示了ManagementObjectSearcher.SelectMany方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewResource
public static ManagementObject NewResource(this ManagementObject VM, ResourceTypes ResType, string SubType, ManagementScope Scope)
{
var pool = new ManagementObjectSearcher(Scope, new SelectQuery(VMStrings.ResourcePool,
"ResourceType = " + (ushort) ResType +
" and ResourceSubType = '" + SubType + "'"))
.Get().Cast<ManagementObject>().ToArray();
return !pool.Any()
? null
: new ManagementObject(pool.SelectMany(
item =>
item.GetRelated("MSVM_AllocationCapabilities")
.Cast<ManagementObject>()
.SelectMany(
cap =>
cap.GetRelationships("MSVM_SettingsDefineCapabilities")
.Cast<ManagementObject>()
.Where(defCap => uint.Parse(defCap["ValueRole"].ToString()) == 0))).First()["PartComponent"].ToString());
/*
if (!pool.Any())
return null;
var var1 = pool.SelectMany(item => item.GetRelated("MSVM_AllocationCapabilities").Cast<ManagementObject>());
var var2 = var1.SelectMany(cap =>cap.GetRelationships("MSVM_SettingsDefineCapabilities").Cast<ManagementObject>());
var var3 = var2.Where(defCap => uint.Parse(defCap["ValueRole"].ToString()) == 0);
var var4 = var3.First();
return var4;
*/
/*
var AllocQuery = new SelectQuery("MSVM_AllocationCapabilities",
"ResourceType = " + (ushort)ResType +" and ResourceSubType = '" + SubType + "'");
var AllocResult = new ManagementObjectSearcher(Scope, AllocQuery).Get().Cast<ManagementObject>().FirstOrDefault();
var objQuery = new SelectQuery("MSVM_SettingsDefineCapabilities",
"ValueRange = 0");
var objOut = new ManagementObjectSearcher(Scope, objQuery).Get().Cast<ManagementObject>();
objOut = objOut.Where(each => {
return each == null ? false
: each["GroupComponent"] == null ? false
: each["GroupComponent"].ToString().Equals(AllocResult["__Path"].ToString());
});
var Out = objOut.First();
var MC = GetObject(Out["PartComponent"].ToString());
return MC;
/*
var MgmtSvc = GetServiceObject(Scope, ServiceNames.VSManagement);
ManagementBaseObject inputs = MgmtSvc.GetMethodParameters("AddVirtualSystemResources");
inputs["TargetSystem"] = VM.Path.Path;
inputs["ResourceSettingData"] = new []{MC.GetText(TextFormat.WmiDtd20)};
var result = MgmtSvc.InvokeMethod("AddVirtualSystemResources", inputs, null);
switch (Int32.Parse(result["ReturnValue"].ToString()))
{
case (int)ReturnCodes.OK:
var tmp = result["NewResources"];
return GetObject(((ManagementObject[])result["NewResources"]).First()["__Path"].ToString());
case (int)ReturnCodes.JobStarted:
var job = GetObject(result["Job"].ToString());
var r = WaitForJob(job);
if (r == 0)
{
var res = result["NewResources"];
var arr = (ManagementBaseObject[])res;
var fir = arr.First();
var path = fir["__Path"].ToString();
var o = GetObject(path);
return GetObject(((ManagementObject[])result["NewResources"]).First()["__Path"].ToString());
}
return null;
default:
return null;
}
*/
}