如何在TFS API中按多个用户模式进行过滤?

时间:2016-11-23 15:18:23

标签: tfs tfs2013

我有以下代码:

var tfs = new TfsTeamProjectCollection(new Uri(TFS_SERVER_URL));    
tfs.EnsureAuthenticated();

var query = GetQuery(...)
var identities = ims.ReadFilteredIdentities(query, 5000, null, true, (int)MembershipQuery.None);
foreach (var item in identities.Items)
{
    Console.WriteLine("{0,-20} {1,-20} {2}", item.DisplayName, item.UniqueName, item.GetAttribute("Mail", null));
}

现在,当查询类似于

Microsoft.TeamFoundation.Identity.Type == 'User' AND (Microsoft.TeamFoundation.Identity.DisplayName CONTAINS 'alice' OR Microsoft.TeamFoundation.Identity.DisplayName CONTAINS 'bob')

代码抛出以下异常:

Microsoft.TeamFoundation.Framework.Client.IdentityExpressionException: TF400819: Query Expression is not well-formed 
---> System.Web.Services.Protocols.SoapException: TF400819: Query Expression is not well-formed
   --- End of inner exception stack trace ---
   at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.HandleReply(TfsClientOperation operation, TfsMessage message, Object[]& outputs)
   at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation operation, Object[] parameters, TimeSpan timeout, Object[]& outputs)
   at Microsoft.TeamFoundation.Framework.Client.IdentityManagementWebService2.ReadFilteredIdentities(String expression, Int32 suggestedPageSize, String lastSearchResult, Boolean lo
okForward, Int32 queryMembership, Int32 features)
   at Microsoft.TeamFoundation.Framework.Client.IdentityManagementService2.ReadFilteredIdentities(String expression, Int32 suggestedPageSize, String lastSearchResult, Boolean lookF
orward, Int32 queryMembership)
   at TFSTool.Program.GetUsers(IEnumerable`1 args) in C:\dayforce\SharpTop\Build\ConfigurationManagement\utilities\tfstool\Program.cs:line 1621
   at TFSTool.Program.Main(String[] args) in C:\dayforce\SharpTop\Build\ConfigurationManagement\utilities\tfstool\Program.cs:line 519

但是,如果我只搜索一个用户模式,例如:

Microsoft.TeamFoundation.Identity.Type == 'User' AND Microsoft.TeamFoundation.Identity.DisplayName CONTAINS 'mark'

它运作得很好。

所以,我的问题 - 可以在TFS Api中搜索多个用户模式,还是我被迫分别对每个模式重复查询?

1 个答案:

答案 0 :(得分:1)

不,你不能。 " OR"查询表达式不支持运算符。有关详细信息,请参阅本文中ReadFilteredIdentities()方法的说明:TeamFoundationIdentityService Class

  

ReadFilteredIdentities用于检索一组身份   在一个表达。表达式是一种类似于SQL的语法   WHERE子句。有关表达式功能的详细信息,请参阅   QueryExpression类的文档。这有两个部分   表达。 可以使用一组值   身份和他们必须在一起