获得TFS组的成员
本文关键字:成员 TFS 获得 | 更新日期: 2023-09-27 18:15:47
我为我们公司的程序员创建了一个TFS组,我正试图获得该组的程序员列表。这是目前为止我尝试过的。
ICommonStructureService iss = (ICommonStructureService)tfsServer.GetService(typeof(ICommonStructureService));
IGroupSecurityService gss = tfsServer.GetService<IGroupSecurityService>();
Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded);
Identity[] _userIds = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None);
var companyProgrammers = _userIds.Where(u=>u.MemeberOf.Contains("CompanyProgrammers")).ToList();
列表为空。
我错过了什么吗?
这将返回一个Microsoft.TeamFoundation.Server.Identity
对象列表,这些对象是您正在查找的实际TFS用户。然后你可以将这些对象序列化为你自己的实体,这样你就可以对它们做任何你想做的事情。
是这样做的:
private List<Identity> ListContributors()
{
const string projectName = "<<TFS PROJECT NAME>>";
const string groupName = "Contributors";
const string projectUri = "<<TFS PROJECT COLLECTION>>";
TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(projectUri));
ICommonStructureService css = (ICommonStructureService) projectCollection.GetService(typeof(ICommonStructureService));
IGroupSecurityService gss = projectCollection.GetService<IGroupSecurityService>();
// get the tfs project
var projectList = css.ListAllProjects();
var project = projectList.FirstOrDefault(o => o.Name.Contains(projectName));
// project doesn't exist
if (project == null) return null;
// get the tfs group
var groupList = gss.ListApplicationGroups(project.Uri);
var group = groupList.FirstOrDefault(o => o.AccountName.Contains(groupName)); // you can also use DisplayName
// group doesn't exist
if (group == null) return null;
Identity sids = gss.ReadIdentity(SearchFactor.Sid, group.Sid, QueryMembership.Expanded);
// there are no users
if (sids.Members.Length == 0) return null;
// convert to a list
List<Identity> contributors = gss.ReadIdentities(SearchFactor.Sid, sids.Members, QueryMembership.Expanded).ToList();
return contributors;
}