Example #1
0
        /// <summary>
        /// Builds an query that can be used with SQL
        /// </summary>
        public string BuildQuery(IWmiQuery queryExpression)
        {
            string query = String.Format("SELECT * FROM {0}", WmiMapper.ConvertTableName(queryExpression.Type));

            if (queryExpression.WhereExpression != null)
            {
                query = String.Format("{0} WHERE {1}", query, BuildWhereClause(queryExpression.WhereExpression));
            }

            return query;
        }
Example #2
0
        public string BuildQuery(IWmiQuery queryExpression)
        {
            string query = $"SELECT * FROM {WmiMapper.ConvertTableName(queryExpression.Type)}";

            if (queryExpression.GetWhereExpression() != null)
            {
                query = $"{query} WHERE {BuildWhereClause(queryExpression.GetWhereExpression())}";
            }

            return(query);
        }
Example #3
0
        /// <summary>
        /// Builds an query that can be used with SQL
        /// </summary>
        public string BuildQuery(IWmiQuery queryExpression)
        {
            string query = String.Format("SELECT * FROM {0}", WmiMapper.ConvertTableName(queryExpression.Type));

            if (queryExpression.WhereExpression != null)
            {
                query = String.Format("{0} WHERE {1}", query, BuildWhereClause(queryExpression.WhereExpression));
            }

            return(query);
        }
Example #4
0
        internal IEnumerator ExecuteWmiQuery(IWmiQuery query)
        {
            this.EnsureConnectionCreated();
            var wmiQueryStatement = this.builder.BuildQuery(query);

            this.WriteLog(wmiQueryStatement);

            var objQuery          = new ObjectQuery(wmiQueryStatement);
            var wmiSearcher       = new ManagementObjectSearcher(this._managementScope, objQuery);
            var genericType       = typeof(WmiObjectEnumerator <>).MakeGenericType(query.Type);
            var genericCollection = genericType.GetConstructor(new[] { typeof(ManagementObjectCollection) });

            return((IEnumerator)genericCollection.Invoke(new object[] { wmiSearcher.Get() }));
        }
Example #5
0
        /// <summary>
        /// Executes an WMI query (which is actually an wrapped expression)
        /// </summary>
        internal IEnumerator ExecuteWmiQuery(IWmiQuery query)
        {
            EnsureConnectionCreated();
            string wmiQueryStatement = _builder.BuildQuery(query);

            WriteLog(wmiQueryStatement);

            ObjectQuery objQuery = new ObjectQuery(wmiQueryStatement);
            ManagementObjectSearcher wmiSearcher = new ManagementObjectSearcher(_managementScope, objQuery);

            //Generate a new generic type
            Type genericType = typeof(WmiObjectEnumerator <>).MakeGenericType(query.Type);

            ConstructorInfo genericCollection = genericType.GetConstructor(new Type[] { typeof(ManagementObjectCollection) });

            return((IEnumerator)genericCollection.Invoke(new object[] { wmiSearcher.Get() }));
        }