DCSIMG
TFS API: Get Project Members - Eran Ruso
Sign in | Join | Help

TFS API: Get Project Members

פורסם בתאריך Sep 13 2009, 03:22 PM על ידי Eran Ruso | ישנם 3 תגובות

I have been asked to write a few times custom controls that requires me to get the users from the Team Project.

The method that does that is very simple, the example in this post takes the members from the project by the “project name” that was passed to it, and adds them to a combobox named cmbUsers.

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Proxy;
using Microsoft.TeamFoundation.Server;

 

 

 

public void GetUsers(TeamFoundationServer server, string project)

 

    {
      cmbUsers.Items.Clear();

 

      IGroupSecurityService securityService = 
             
(IGroupSecurityService)server.GetService
                 (typeof(IGroupSecurityService));

 

      Identity[] projectGroups =
               securityService.ListApplicationGroups
                 (store.Projects[project].Uri.AbsoluteUri);

 

      foreach (Identity projectGroup in projectGroups)
 
    {

 

 

        Identity[] groupMembers =
               securityService.ReadIdentities
                  (SearchFactor.Sid, new string[]
                    { projectGroup.Sid },
                         QueryMembership
.Expanded);

 

 

        foreach (Identity member in groupMembers)
        {

 

          if (member.Members != null)
          {

 

 

            foreach (string memberSid in member.Members)
            {

 

 

              Identity memberInfo=
                  securityService.ReadIdentity
                     (SearchFactor.Sid, memberSid,
                         QueryMembership
.None);

 

             cmbUsers.Items.Add(memberInfo.DisplayName);

 

            }

 

 

          }

 

 

        }

      }

 

 

    }

Have Fun!!!

רשימת תגובות

# re: TFS API: Get Project Members

פורסם בתאריך Thursday, December 03, 2009 4:53 PM על ידי Jim DeLorenzo  

I'm trying to do the same as above but in a macro (VBA).  I got most of it translated, but I keep getting errors when translating....

Identity[] projectGroups =

              securityService.ListApplicationGroups

                (store.Projects[project].Uri.AbsoluteUri);

TO...

appGroups = sec.ListApplicationGroups(tp.ArtifactUri.AbsoluteUri)

the error says that the "Object reference not set to an instance of an object".

can you help?

Thanks.

# re: TFS API: Get Project Members

פורסם בתאריך Sunday, December 06, 2009 6:12 PM על ידי Eran Ruso  

Hi Jim,

From what you have written I can't understand ht do you get from tp.ArtifactUri.AbsoluteUri

are you getting the correct Uri?

Can you paste the all code? (I don't see where you get the Team Project)

Eran Ruso

# re: TFS API: Get Project Members

פורסם בתאריך Tuesday, December 22, 2009 5:15 PM על ידי Jim  

Imports Microsoft.TeamFoundation.Server.Identity

Imports Microsoft.TeamFoundation.Server

Imports Microsoft.TeamFoundation.Client

Imports Microsoft.TeamFoundation.WorkItemTracking.Client

Imports Microsoft.TeamFoundation.Common

Imports Microsoft.TeamFoundation.Proxy

'(THE ABOVE IS ONLY A FEW Imports, I haved a whole bunch for other things as well.

   Sub ListProjectsAndTeamMembersTESTING()

       Dim serverUri As String = "http://ftctfs:8080"

       Dim tfs As TeamFoundationServer = TeamFoundationServerFactory.GetServer(serverUri)

       Dim store As WorkItemStore = CType(tfs.GetService(GetType(WorkItemStore)), WorkItemStore)

       Dim CSS As ICommonStructureService = DirectCast(tfs.GetService(GetType(ICommonStructureService)), ICommonStructureService)

       Dim tfsClient As VersionControlServer = CType(tfs.GetService(GetType(VersionControlServer)), VersionControlServer)

       Dim GSS As IGroupSecurityService = DirectCast(tfs.GetService(GetType(IGroupSecurityService)), IGroupSecurityService)

       'Dim idSID As Identity = gss.ReadIdentities(SearchFactor.AccountName, factorValue:="Contributors", queryMembership:="Expanded")

       Dim strTestString As String

       Dim strProjectName As String

       Dim strFULLProjectName As String

       Dim strTeamMemberNames As String

       Dim OutWin As OutputWindowPane

       Dim ow As OutputWindow = DTE.Windows.Item(Constants.vsWindowKindOutput).Object()

       ' Other stuff

       Dim LenOTP As Int16

       Dim spaceindex As Int16

       Dim strFULLProjectNameWTM As String

       Const StartInThisColumn = 30

       Dim LenOProjName As Int16

       Dim SeeThis As String

       Dim ProjectCount As Int16

       Dim users As New Collection(Of String)

       Dim CommonStructureService As ICommonStructureService = DirectCast(tfs.GetService(GetType(ICommonStructureService)), ICommonStructureService)

       Dim GroupSecurityService As IGroupSecurityService = DirectCast(tfs.GetService(GetType(IGroupSecurityService)), IGroupSecurityService)

       Try

           OutWin = ow.OutputWindowPanes.Item("Macros")

       Catch ex As Exception

           OutWin = ow.OutputWindowPanes.Add("Macros")

       End Try

       OutWin.Clear()

       OutWin.Activate()

       DTE.ExecuteCommand("View.Output")

       ProjectCount = store.Projects.Count

       OutWin.OutputString("Project(s)   count = (" & Trim$(Str$(ProjectCount)) _

                           & ")  ...Team Member Contributors..." & vbCrLf)

       OutWin.OutputString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")

       OutWin.OutputString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf)

       For Each pi In store.Projects

           strProjectName = pi.Name

           LenOProjName = Len(strProjectName)

           OutWin.OutputString(strProjectName)

           strFULLProjectName = "ftctfs/" & strProjectName

           ' THIS IS THE LINE THAT KEEPS GIVING MY THE ERROR "OBJECT REFERENCE NOT SET TO AN INSTANCE OF AN OBJECT"

           Dim ProjGroups As Identity() = GSS.ListApplicationGroups(store.Projects.Item(strProjectName).Uri.AbsoluteUri)

           'OutWin.OutputString("  " & SeeThis & vbCrLf)

       Next

   End Sub

' I gretly aprecialte the help!

שלח תגובה

(שדה חובה) 
(שדה חובה) 
(אופציונלי)
(שדה חובה) 

Enter the numbers above: