我正在使用 Service Manager/System Center 2012,Service Pack 1。(版本 7.5.2905.0
我正在尝试做一些应该很简单的事情,但似乎有关于如何实际进行查询的零文档。因此,我有一个用户对象(该用户的 EnterpriseManagementObject),并且我想查询服务管理器以了解该用户是受影响用户的所有事件。
代码是:(从我找到的一个例子)
strIncidentSearchCriteria =
String.Format(@"<Criteria xmlns=""http://Microsoft.EnterpriseManagement.Core.Criteria/"">
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Path[Relationship='WorkItem!System.WorkItemAffectedUser' TypeConstraint='System!System.Domain.User']/Property[Type='System!System.Domain.User']/UserName$</Property>
</ValueExpressionLeft>
<Operator>Equal</Operator>
<ValueExpressionRight>
<Value>" + user.FullName + @"</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
</Criteria>");
EnterpriseManagementObjectCriteria emocWorkitem = new EnterpriseManagementObjectCriteria(incidentSearchCriteria, mpc, mp, emg);
这会引发异常:
The provided path ($Context/Path[Relationship='WorkItem!System.WorkItemAffectedUser' TypeConstraint='System!System.Domain.User']/Property[Type='System!System.Domain.User']/UserName$) was not valid.
参数名称:路径参考
我很确定 Property 字段是错误的,但似乎没有关于如何创建 XML 或如何指定 Property 或任何内容的文档。
如果我将搜索更改为:
//strIncidentSearchCriteria = String.Format(@"<Criteria xmlns=""http://Microsoft.EnterpriseManagement.Core.Criteria/"">" +
// "<Expression>" +
// "<SimpleExpression>" +
// "<ValueExpressionLeft>" +
// "<Property>$Context/Property[Type='System.WorkItem.Incident']/Status$</Property>" +
// "</ValueExpressionLeft>" +
// "<Operator>NotEqual</Operator>" +
// "<ValueExpressionRight>" +
// "<Value>" + new Guid("2b8830b6-59f0-f574-9c2a-f4b4682f1681") + "</Value>" + // Resolved
// //Closed:"<Value>" + new Guid("bd0ae7c4-3315-2eb3-7933-82dfc482dbaf") + "</Value>" +
// "</ValueExpressionRight>" +
// "</SimpleExpression>" +
// "</Expression>" +
// "</Criteria>");
(当然,没有注释掉)
另外,另一个问题:如果我执行上面的查询并返回所有已解决的匹配事件 - 它在能够枚举之前内存不足 - 显然,它是这样编写的,因此它将所有匹配的内容拉入列表或其他内容中然后你枚举 - 而不是根据需要提取更多数据。有什么办法可以拉动一切吗?(我最初的方法是提取所有内容,然后自己过滤 - 这是一次性的,如果需要,我可以忍受一个小时。(但是,我也需要这个查询用于长期项目,所以我'我真的需要知道如何查询影响给定用户的所有事件,以及所有分配的用户是 X 等。你从哪里学到这些东西??)
谢谢
更新:
这个查询失败了,我该如何让它工作。(这是我最终想要开始工作的事情)
<Criteria xmlns="http://Microsoft.EnterpriseManagement.Core.Criteria/">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='System.WorkItem.Incident']/Status$</Property>
</ValueExpressionLeft>
<Operator>NotEqual</Operator>
<ValueExpressionRight>
<Value>2b8830b6-59f0-f574-9c2a-f4b4682f1681</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='System.WorkItem.Incident']/Status$</Property>
</ValueExpressionLeft>
<Operator>NotEqual</Operator>
<ValueExpressionRight>
<Value>bd0ae7c4-3315-2eb3-7933-82dfc482dbaf</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Path[Relationship='WorkItem!System.WorkItemAssignedToUser' TypeConstraint='System!System.Domain.User']/Property[Type='System!System.Domain.User']/DisplayName$</Property>
</ValueExpressionLeft>
<Operator>Like</Operator>
<ValueExpressionRight>
<Value>%Bill%</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
</And>
</And>
</Expression>
</Criteria>
=======更新和解决方案========
想通了,你必须告诉它事件类型的位置,所以这个查询有效:
<Criteria xmlns="http://Microsoft.EnterpriseManagement.Core.Criteria/">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='CoreIncident!System.WorkItem.Incident']/Status$</Property>
</ValueExpressionLeft>
<Operator>NotEqual</Operator>
<ValueExpressionRight>
<Value>2b8830b6-59f0-f574-9c2a-f4b4682f1681</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='CoreIncident!System.WorkItem.Incident']/Status$</Property>
</ValueExpressionLeft>
<Operator>NotEqual</Operator>
<ValueExpressionRight>
<Value>bd0ae7c4-3315-2eb3-7933-82dfc482dbaf</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Path[Relationship='WorkItem!System.WorkItemAssignedToUser' TypeConstraint='System!System.Domain.User']/Property[Type='System!System.Domain.User']/DisplayName$</Property>
</ValueExpressionLeft>
<Operator>Like</Operator>
<ValueExpressionRight>
<Value>%Bill%</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
</And>
</Expression>
</And>
</Expression>
</Criteria>