本文整理汇总了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();
}