2013-05-28 33 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

関連する問題