Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="managementScope"></param>
        /// <param name="elementNames"></param>
        /// <returns></returns>
        public static List <MsvmComputerSystem> GetByElementNames(ManagementScope managementScope,
                                                                  IEnumerable <string> elementNames)
        {
            Assert.IsNotNull(managementScope);
            Assert.IsNotNull(elementNames);

            var sb = new StringBuilder();

            sb.AppendFormat("SELECT * FROM Msvm_ComputerSystem WHERE");
            var first = true;

            foreach (var elementName in elementNames)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(" OR");
                }

                sb.AppendFormat(" ElementName = '{0}'", elementName);
            }

            var query = sb.ToString();
            var list  = managementScope.ExecuteQuery(query, mo => new MsvmComputerSystem(mo));

            return(list);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="managementScope"></param>
        /// <param name="elementName"></param>
        /// <returns></returns>
        public static List <MsvmComputerSystem> GetByElementName(ManagementScope managementScope, string elementName)
        {
            FoundationContract.Requires <ArgumentException>(managementScope != null);

            var query = $"SELECT * FROM Msvm_ComputerSystem WHERE ElementName='{elementName}'";
            var list  = managementScope.ExecuteQuery(query, mo => new MsvmComputerSystem(mo));

            return(list);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="managementScope"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static MsvmComputerSystem GetByName(ManagementScope managementScope, string name)
        {
            Assert.IsNotNull(managementScope);

            var query = $"SELECT * FROM Msvm_ComputerSystem WHERE Name='{name}'";
            var list  = managementScope.ExecuteQuery(query, mo => new MsvmComputerSystem(mo));

            Assert.IsTrue(list.Count > 0);

            MsvmComputerSystem item;

            if (list.Count == 0)
            {
                item = null;
            }
            else
            {
                item = list[0];
            }

            return(item);
        }