In the previous post, we talked about using criteria to query on instances. This post talks about using criteria to query types in the management pack such as classes, relationships, tasks, views etc. These are queries such as:
· Query for all classes that match a given class name.
· Query for all relationships with a particular target class.
· Query for all tasks with a particular category.
· Query for all management packs of a particular version and so on.
There is a criteria class associated with each of these types. Example, the class ManagementPackClassCriteria is used to query for management pack classes.
public class ManagementPackClassCriteria : QueryCriteria<ManagementPackClassCriteria>
The following table indicates all the properties of a management pack class that can be queried for. Example – All classes with a specific management pack id, classes that are abstract, classes that are sealed etc.
The constructor for these classes accepts a criteria xml as shown below:
public ManagementPackCriteria(string criteria)
All type related criteria classes provide a similar constructor. The criteria parameter follows the same schema as discussed in this post except for the following differences:
· Only <GenericProperty> tags are used and not <Property> for indicating properties to query. As a result the syntax followed is <GenericProperty>propertyName</GenericProperty>
· ContainmentCriteriaType and FullTextCriteriaType cannot be used.
· Guid values for types need to be used instead of type names as there is no managementpack parameter exposed and hence the type name cannot be resolved.
Here’s an example of a criteria xml that queries for all classes in a given management pack.
The code for the same looks as below:
ManagementPackClassCriteria criteria = new ManagementPackClassCriteria(criteria);
IList<ManagementPackClass> mpClasses = managementGroup.EntityTypes.GetClasses(criteria);
In this post, we talked about querying for all incidents that were related to config items. Consider querying for all relationships that exist in the system that include config item as a source or target. The criteria xml for the same would look like:
<Value>replace with guid value for config item type</Value>
The following table indicates all the properties on which a ManagementPackRelationship can be queried for
Note: For operations that involve querying for classes or relationships frequently, it will be better to use regular APIs without criteria and compare results on the client for performance reasons.