콘솔 응용 프로그램에서 Team Foundation Server에 연결
다음 예제를 사용하는 경우 Team Foundation을 실행하는 서버에 프로그래밍 방식으로 연결한 후에 해당 서버의 팀 프로젝트에 액세스할 수 있습니다. 예제를 수정하는 경우 이 항목 뒷부분의 Getting Additional Team Foundation Services에서 설명하는 서비스를 사용할 수 있습니다. 이 항목 뒷부분의 Acting on Behalf of Another User (Impersonation)에서 설명하는 대로 가장을 하여 다른 사용자 대신 작업을 수행할 수도 있습니다.
항목 내용
예제
다음 예제를 사용하는 경우 팀 프로젝트 컬렉션 및 해당 컬렉션에 포함된 팀 프로젝트를 나열할 수 있습니다.
이 예제를 사용하려면
C# 콘솔 응용 프로그램을 만듭니다.
다음 어셈블리에 대한 참조를 추가합니다.
Program.cs의 콘텐츠를 이 항목 뒷부분에 나와 있는 코드로 바꿉니다.
해당 코드에서 TfsConfigurationServer 개체를 생성하는 데 사용되는 URL이 서버를 참조하도록 해당 URL의 Server, Port 및 VDir을 바꿉니다.
팁
올바른 URL을 사용하고 있는지 확인하려면 팀 탐색기를 사용하여 서버에서 팀 프로젝트를 열고 서버의 URL 속성을 확인합니다.
using System; using System.Collections.ObjectModel; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Framework.Common; using Microsoft.TeamFoundation.Framework.Client; namespace TfsApplication { class Program { static void Main(String[] args) { // Connect to Team Foundation Server // Server is the name of the server that is running the application tier for Team Foundation. // Port is the port that Team Foundation uses. The default port is 8080. // VDir is the virtual path to the Team Foundation application. The default path is tfs. Uri tfsUri = (args.Length < 1) ? new Uri("http://Server:Port/VDir") : new Uri(args[0]); TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri); // Get the catalog of team project collections ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren( new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); // List the team project collections foreach (CatalogNode collectionNode in collectionNodes) { // Use the InstanceId property to get the team project collection Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]); TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId); // Print the name of the team project collection Console.WriteLine("Collection: " + teamProjectCollection.Name); // Get a catalog of team projects for the collection ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren( new[] { CatalogResourceTypes.TeamProject }, false, CatalogQueryOptions.None); // List the team projects in the collection foreach (CatalogNode projectNode in projectNodes) { Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName); } } } } }
Imports System Imports System.Collections.ObjectModel Imports Microsoft.TeamFoundation.Client Imports Microsoft.TeamFoundation.Framework.Common Imports Microsoft.TeamFoundation.Framework.Client Module Module1 Sub Main(ByVal sArgs() As String) ' Connect to the Team Foundation Server ' Server is the name of the server running the application tier for Team Foundation Server ' Port is the port that the Team Foundation Server uses. The default port is 8080. ' VDir is the virtual path to the Team Foundation application. The default value is tfs. Dim tfsUri As Uri If sArgs.Length = 0 Then tfsUri = New Uri("https://Server:8080/tfs") Else tfsUri = New Uri(sArgs(1)) End If Dim configurationServer As New TfsConfigurationServer(tfsUri) configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri) ' Get the catalog of team project collections Dim collectionNodes As ReadOnlyCollection(Of CatalogNode) Dim gVar As Guid() = New Guid() {CatalogResourceTypes.ProjectCollection} collectionNodes = configurationServer.CatalogNode.QueryChildren(gVar, False, CatalogQueryOptions.None) ' List the team project collections For Each collectionNode In collectionNodes Dim collectionId As Guid = New Guid(collectionNode.Resource.Properties("InstanceID")) Dim teamProjectCollection As New TfsTeamProjectCollection(tfsUri) teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId) System.Console.WriteLine("Collection:" + teamProjectCollection.Name) ' Get a catalog of team projects for the collection Dim hVar As Guid() = New Guid() {CatalogResourceTypes.TeamProject} Dim projectNodes As ReadOnlyCollection(Of CatalogNode) projectNodes = collectionNode.QueryChildren(hVar, False, CatalogQueryOptions.None) ' List the team projects in the collection For Each projectNode In projectNodes System.Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName) Next Next End Sub End Module
추가 Team Foundation Services 얻기
추상 클래스 TfsConnection이 정의하며 TfsConfigurationServer 및 TfsTeamProjectCollection이 구현하는 GetService 메서드 중 하나를 사용하여 추가 서비스에 액세스할 수 있습니다.
TfsConfigurationServer 클래스를 사용할 때는 전체 서버용 서비스에 액세스합니다. TfsTeamProjectCollection 클래스를 사용할 때는 팀 프로젝트 컬렉션용 서비스에 액세스합니다. 예를 들어 TfsConfigurationServer용 ITeamFoundationRegistry 서비스는 서버의 등록된 속성을 제공합니다. TfsTeamProjectCollection에서 가져오는 것과 동일한 서비스는 팀 프로젝트 컬렉션의 등록된 속성을 제공합니다. 일부 서비스는 팀 프로젝트 컬렉션에만 적용됩니다.
서비스 |
TfsConfigurationServer (서버 수준) |
TfsTeamProjectCollection (컬렉션 수준) |
---|---|---|
다른 사용자 대신 작업 수행(가장)
Team Foundation Server에 연결할 때는 가장을 지원하는 메서드를 사용하여 응용 프로그램을 실행하는 ID가 아닌 다른 ID 대신 작업을 수행할 수 있습니다. 해당 연결을 기반으로 수행하는 모든 작업은 가장된 ID를 대신하여 수행됩니다. 예를 들어 사용자 A의 ID로 실행되는 응용 프로그램에서 사용자 B를 가장하는 Team Foundation Server에 대한 연결을 만들 수 있습니다. 이러한 상황에서 사용자 A가 소스 코드 변경 내용을 체크 인하면 변경 집합에는 사용자 B가 변경 내용을 체크 인했다고 기록됩니다.
Team Foundation ID 사용
Team Foundation Server에 연결하여 가장할 ID를 지정할 때는 IdentityDescriptor 개체를 사용할 수 있습니다. IdentityDescriptor는 Team Foundation에서 정의하는 ID를 지정합니다. 이 전략을 사용할 때는 암호를 지정하지 않아도 됩니다. 인증된 사용자 A ID와 가장된 사용자 B ID가 같은 경우를 제외하면 인증된 ID에는 다른 사용자 대신 요청 권한이 있어야 합니다.
서버 수준 |
---|
컬렉션 수준 |
---|
인증된 자격 증명 사용
Team Foundation Server에 연결하여 가장할 ID를 지정할 때는 ICredentials 개체를 사용할 수 있습니다. 이 전략에 특수한 권한이 필요하지는 않지만 ICredentials 개체를 만들 ID의 암호는 얻어야 합니다.
Team Foundation Server에 연결하여 새 자격 증명에 대한 요청을 처리할 때는 ICredentialsProvider 구현도 지정할 수 있습니다. 시스템은 ICredentials 개체가 지정한 자격 증명이 올바르게 인증되지 않거나 작업을 수행할 권한이 없으면 새 자격 증명을 요청하기 위해 지정하는 ICredentialsProvider의 구현을 호출합니다.
사용자에게 자격 증명을 입력하라는 메시지를 표시하려면 UICredentialsProvider 클래스를 사용할 수 있습니다. 이 클래스는 로그온 대화 상자를 표시하여 새 자격 증명을 입력하라는 메시지를 사용자에게 표시하는 ICredentialsProvider를 구현합니다.
서버 수준 |
---|
컬렉션 수준 |
---|
기술 조합 사용
Team Foundation Server에 연결할 때는 Team Foundation ID와 인증된 자격 증명을 모두 사용할 수 있습니다. 응용 프로그램은 사용자 A의 자격 증명으로 실행되는데 사용자 B의 자격 증명을 사용하며 Team Foundation Server에 연결할 때 사용자 C에 대해 IdentityDescriptor를 지정하는 경우를 예로 들 수 있습니다. 이 경우 해당 연결을 사용하여 수행하는 요청은 사용자 B로 인증되지만 사용자 C 대신 수행됩니다. 이 전략을 올바르게 적용하려면 사용자 B에게 다른 사용자 대신 요청 권한이 있어야 합니다.
서버 수준 |
---|
컬렉션 수준 |
---|
추가 리소스
Team Foundation Server에서 팀 프로젝트에 연결
Microsoft 웹 사이트의 TfsConnection, TfsConfigurationServer 및 TfsTeamProjectCollection 클래스 소개
Microsoft 웹 사이트의 버전 제어 API와 함께 TFS 구현 사용