次の例を使用すると Team Foundation をチーム サーバーのプロジェクトにアクセスするに実行しているサーバーに割り当てる的に接続できます。例を変更すると、Getting Additional Team Foundation Services がこのトピックの後半で説明するサービスを使用できます。他の偽装に代わって使用して使用できます Acting on Behalf of Another User (Impersonation) がこのトピックの後半で説明するため。
このトピックの内容
例
プロジェクト チーム コレクションを、次の例を使用して含むチーム プロジェクトを一覧できます。
この例を使用します。
コンソール C# のアプリケーションを作成します。
次のアセンブリへの参照を追加します。
[!メモ]
Microsoft.TeamFoundation.Client と Microsoft.TeamFoundation.Common が [参照] のダイアログ ボックスの [.NET] のタブに表示されない場合は、組み立てを追加するに [参照] のタブを使用します。%ProgramFiles%\Microsoft Visual Studio 10.0\Common7 IDE ReferenceAssemblies\v2.0 でそれらを検索できます。
このトピックで後に表示されるコードと Program.cs の内容を置き換えます。
URL が、サーバーを示すように TfsConfigurationServer のオブジェクトの製造に使用される URL のそのコード、置換 [サーバー]、[ポート]と VDir。
ヒント正しい URL が使用していることを確認するには、チーム サーバーのプロジェクトを開くには チーム エクスプローラー を使用してサーバーの URL のプロパティを確認します。
.png)
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 サービスを取得できます。
抽象型クラス TfsConnection を定義します TfsConfigurationServer と TfsTeamProjectCollection を実行し、GetService 方法の 1 種類の追加サービスを使用してアクセスできます。
TfsConfigurationServer クラスを使用すると、すべてのサーバーのサービスのアクセスを制御します。TfsTeamProjectCollection クラスを使用すると、プロジェクト チーム コレクションのサービスのアクセスを制御します。たとえば、TfsConfigurationServer の ITeamFoundationRegistry サービスがサーバーの登録されたプロパティを提供します。TfsTeamProjectCollection から派生したサービスは同じチーム プロジェクト トランザクションに登録されたプロパティを提供します。あるサービスは、回収チーム プロジェクトにのみ適用されます。
サービス |
TfsConfigurationServer レベル (サーバー) |
TfsTeamProjectCollection コレクション (レベル) |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
別のユーザーに代わって機能 (偽装)
Team Foundation Serverに接続すると、アプリケーションを実行していない ID の代わりにアクションを実行するためにこの場合の偽装方法を使用できます。実行される工程が扮された ID に代わってその接続に基づいて行われます。たとえば、A のアプリケーションは、ユーザーの ID で移動ユーザーの 12 Z 対象に扮する Team Foundation Server への接続を作成ができました。ユーザーの 12 Z 対象、変更をチェックインしたユーザーを A のチェックインがこのような状況でソース・コードへの変更、変更を記録します。
Team Foundation ID を使用する
ID を指定するに Team Foundation Server に扮する接続すると IdentityDescriptor のオブジェクトを使用できます。IdentityDescriptor は Team Foundation が定義した ID を指定します。この工程を使用する場合、パスワードを指定する必要はありません。認証された ID がおよび以外と認証する *** 別のユーザーに代わって要求を行います。*** のアクセス許可が必要です (ユーザー A) と扮するユーザー (B) の ID は同じです。
サーバー レベル |
|---|
|
コレクション レベル |
|---|
|
認証される資格情報を使用して
ID を指定するに Team Foundation Server に扮する接続すると ICredentials のオブジェクトを使用できます。この計画は特別なアクセス許可が必要ではありませんが、ICredentials のオブジェクトを作成するためには ID のパスワードを取得必要があります。
新しい資格情報の処理にどの文書 Team Foundation Server に接続する際に、ICredentialsProvider の実装を指定できます。システムから電話が新しい資格情報を要求するためのときに指定する ICredentialsProvider の実装 ICredentials の対象によって指定された資格情報は、工程の実行に認証も承認されません。
資格情報のユーザーのダイアログを表示するには、新しい資格情報のユーザーを求めるにログイン ダイアログ ボックスを表示して ICredentialsProvider を実行する UICredentialsProvider クラスを使用できます。
サーバー レベル |
|---|
|
コレクション レベル |
|---|
|
技術の組み合わせを使用して
Team Foundation Serverに接続するとき Team Foundation ID と認証される資格情報を使用できます。たとえば、A のアプリケーションは、ユーザーの資格情報で実行する場合があります。Team Foundation Serverに接続するときのユーザー 12 Z 対象の資格情報を使用して、ユーザー C に IdentityDescriptor を指定する場合があります。この場合、その接続による要求は、ユーザーの 12 Z 対象として認証されますが、C ユーザーに代わって実行されます。この適用される戦略のユーザーの 12 Z 対象は *** 別のユーザーに代わって要求を行います。*** のアクセス許可が必要です。
サーバー レベル |
|---|
|
コレクション レベル |
|---|
|
その他のリソース
Team Foundation Server 上のチーム プロジェクトへの接続
TfsTeamProjectCollection の TfsConnection、TfsConfigurationServer およびクラスがあります。 Microsoft の Web サイト
バージョン管理 API の偽装を使用して TFS Microsoft の Web サイト。