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


C# ManagementBaseObject.IsEvent方法代码示例

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


在下文中一共展示了ManagementBaseObject.IsEvent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetWqlQueryProperties

        /// <summary>
        /// Returns a System.Management.PropertyData[] of properties that will be returned by the system for the specified query string.
        /// </summary>
        /// <param name="query">A valid WQL Select query.</param>
        /// <param name="managementClass">A ManagementBaseObject (class or instance) targeted by this query.</param>
        /// <returns>A System.Management.PropertyData[] of properties that will be returned by the system for the specified query string.</returns>
        /// <remarks>
        /// This function is used to return property data for a query that does not return all of the properties in the associated class.
        /// Specifically, it is used to build grid column configuration for results returned by a query.
        /// </remarks>
        public static PropertyData[] GetWqlQueryProperties(this String query, ManagementBaseObject managementClass)
        {
            // Query has been validated
            Boolean queryValidated = false;

            // Specified managementClass is a __AggregatedEvent class
            Boolean classIsAggregatedEvent = managementClass.ClassPath.ClassName.Equals(AGGEVENT_CLASS, StringComparison.InvariantCultureIgnoreCase);

            // Parse the query with .Net's built in parser
            var selectQuery = new SelectQuery(query);

            // Validate an event query
            WqlEventQuery eventQuery;
            if(managementClass.IsEvent() || classIsAggregatedEvent)
            {
                // Parse the event query with .Net's built in parser
                eventQuery = new WqlEventQuery(query);

                // Make sure the return type for an event query with grouped intervals is __AggregateEvent
                if (eventQuery.GroupWithinInterval.Ticks > 0)
                {
                    if (!queryValidated && !managementClass.ClassPath.ClassName.Equals(AGGEVENT_CLASS, StringComparison.InvariantCultureIgnoreCase))
                        throw new ArgumentException(String.Format("Grouped event queries should return type '{0}'. Object passed was a '{1}'.", AGGEVENT_CLASS, managementClass.ClassPath.ClassName));

                    queryValidated = true;
                }
            }

            // Validate class name
            if (!queryValidated && !selectQuery.ClassName.Equals(managementClass.ClassPath.ClassName, StringComparison.InvariantCultureIgnoreCase))
                throw new ArgumentException(String.Format("The class specified in the query '{0}' does not match the class of the specified object '{1}'.", selectQuery.ClassName, managementClass.ClassPath.ClassName));

            // Extract the list of PropertyData
            var properties = new List<PropertyData>();
            if (selectQuery.SelectedProperties.Count == 0)
            {
                // Grab all properties for a SELECT *... query
                foreach (PropertyData p in managementClass.Properties)
                {
                    properties.Add(p);
                }
            }
            else
            {
                // Grab specified properties for a SELECT field1, field2,... query
                foreach (var propertyName in selectQuery.SelectedProperties)
                {
                    properties.Add(managementClass.Properties[propertyName]);
                }
            }

            return properties.ToArray();
        }
开发者ID:giapdangle,项目名称:wmilab,代码行数:63,代码来源:StringExtentions.cs


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