TFS API Part 4: Get TFS User List (Mail, Sid, Account, Domain)
TFS API Part 4: Get TFS User List (Mail, Sid, Account, Domain)
In my previous posts TFS API Part 2: Domain Picker Using Registered Servers (Cache) I demonstrate how to connect TFS and how to get TFS Projects.
In this post I’ll show how to get User List from TFS by groups.
First add reference for Microsoft.TeamFoundation, Microsoft.TeamFoundation.Client, Microsoft.TeamFoundation.Common.dll
located in - C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\
Download Demo Project
Add using for Proxy,Client and Server.
*** Good to know -> An Identity structure represents a user, group, or Team Foundation Server application group, along with some of their attributes
using Microsoft.TeamFoundation.Proxy;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
Connect to TFS and call GetTfsUsers(dp.SelectedServer) with the TFS.
Create IGroupSecurityService from TFS.
IGroupSecurityService gss = (IGroupSecurityService)server.GetService(typeof(IGroupSecurityService));
# Read Identitys
Using gss you can read all Identitys in TFS.
SearchFactor
AccountName -Logon name (for Windows identities) or an application group name, possibly qualified by domain name, such as AdventureWorks\JAaberg, ProjectURI\groupname, or GUID\groupname.
AdministrativeApplicationGroup - An administrative application group.
DistinguishedName - A LDAP escaped distinguished name, optionally prepended by LDAP://.
EveryoneApplicationGroup - The Team Foundation Server Everyone application group.
ServiceApplicationGroup - The service application group.
Sid - Contains a SID
Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Team Foundation Valid Users", QueryMembership.Expanded);
Identity SIDS = gss.ReadIdentity(SearchFactor.ServiceApplicationGroup, "Team Foundation Valid Users", QueryMembership.Expanded);
QueryMembership
Direct- Each Identity includes its direct members. However, these member identities will contain null members.
Expanded - Each returned identity includes its direct members. Each of these member identities contain their direct member identities, and so on.
None - No information about membership is returned, and corresponding properties are set to null.
Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Team Foundation Valid Users", QueryMembership.Expanded);
Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Team Foundation Valid Users", QueryMembership.Direct);
#
# Getting User List
To get Identity for each user use ReadIdentities by Sid.
Identity[] UserId = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None);
Download Demo Project