当前位置: 首页>>代码示例>>C#>>正文


C# ManagementObjectSearcher.Any方法代码示例

本文整理汇总了C#中System.Management.ManagementObjectSearcher.Any方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObjectSearcher.Any方法的具体用法?C# ManagementObjectSearcher.Any怎么用?C# ManagementObjectSearcher.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.ManagementObjectSearcher的用法示例。


在下文中一共展示了ManagementObjectSearcher.Any方法的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;
            }
            */
        }
开发者ID:virmitio,项目名称:TempRepo,代码行数:76,代码来源:Utility.cs


注:本文中的System.Management.ManagementObjectSearcher.Any方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。