如何从TFS中选择所有用户到列表?

时间:2014-08-25 12:35:46

标签: tfs2010

我希望列出TFS的所有用户,无论他们是否有任何变更集。我想要列表中的所有用户,我想使用MVC在C#中执行此操作。我在互联网上搜索但没有找到太多帮助,任何帮助材料都会非常感激。

提前致谢!

1 个答案:

答案 0 :(得分:1)

以下是我列出集合的所有用户的方法(参考Microsoft.TeamFoundation.Client.dll):

IIdentityManagementService ims = (IIdentityManagementService)tfsConnection.GetService(typeof(IIdentityManagementService));
// get all valid users of the collection
TeamFoundationIdentity SIDS = ims.ReadIdentity(IdentitySearchFactor.AccountName, "Project Collection Valid Users", MembershipQuery.Expanded, ReadIdentityOptions.ExtendedProperties);
List<string> ids = new List<string>();
foreach (var member in SIDS.Members)
{
    ids.Add(member.Identifier);
}

// get user objects for existing SIDS
TeamFoundationIdentity[][] UserId = ims.ReadIdentities(IdentitySearchFactor.Identifier, ids.ToArray(), MembershipQuery.None, ReadIdentityOptions.ExtendedProperties);
// convert to list
List<TeamFoundationIdentity> UserIds = UserId.SelectMany(T => T).ToList();

foreach (TeamFoundationIdentity user in UserIds)
{
  // exclude groups in listing
  if (!user.IsContainer)
  {
    //do what you want with the user
  }
}