2013-05-28 2 views
5

저는 회사 프로그래머를위한 TFS 그룹을 만들었으며 그 그룹의 프로그래머 목록을 얻으려고합니다. 이것은 여기까지 지금까지 시도했습니다.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(); 

목록이 비어 있습니다.

내가 누락 된 항목이 있습니까?

답변

12

그러면 찾고있는 실제 TFS 사용자 인 Microsoft.TeamFoundation.Server.Identity 개체 목록이 반환됩니다. 그런 다음이 객체를 자신의 엔티티에 직렬화하여 이후에 원하는 모든 작업을 수행 할 수 있습니다. 여기

한 방법이다 :

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; 
} 
+0

IGroupSecurityService는 현재 사용되지 않습니다. 새로운 API를 사용하면 어떻게 될까요? –

+2

사용되지 않는 코드입니다. 제안에 따라 IIdentityManagementService 또는 ISecurityService를 사용해야합니다. 누구든지 그 인터페이스를 사용하는 방법을 알고 있습니까? – jwrightmail

관련 문제