Reputation: 8925
I've been trying to access a TFS account (programatically using the TFS SDK) in order to get information such as the project names, work item names and developpment times for each work item.
I wasn't able to get project or work item information, but I was able to authenticate and access TFS using the class TfsTeamProjectCollection.
However, using the class TfsConfigurationServer, I was never able to authenticate to the server. This is a pity because the majority of examples I've seen in the web use this TfsConfigurationServer class.
The code that allows me to access TFS:
// Connect to Team Foundation Server.
NetworkCredential netCred = new NetworkCredential("[email protected]", "myPassword");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://tfs.gfi.pt:4430/tfs/gfi/"),tfsCred);
tpc.Authenticate(); // This one works, and when I enter tpc I can see I am correctly signed-in in TFS (I can for instance check my full name)
ITeamProjectCollectionService projCollect = tpc.GetService<ITeamProjectCollectionService>(); //returns null :(
I have 2 questions:
Upvotes: 1
Views: 550
Reputation: 8343
Regarding question #1, you can find some whys in Introducing the TfsConnection, TfsConfigurationServer and TfsTeamProjectCollection Classes. Shortly, you can have many user databases, i.e. Collection, managed by a single TFS instance, i.e. the Server.
Upvotes: 1
Reputation: 8925
I just found out what the problem was. I just needed to replace the last line:
ITeamProjectCollectionService projCollect = tpc.GetService<ITeamProjectCollectionService>(); //returns null :(
By:
// Get the catalog of team project collections
ReadOnlyCollection<CatalogNode> collectionNodes = tpc.CatalogNode.QueryChildren(
new [] { CatalogResourceTypes.TeamProject},
false, CatalogQueryOptions.None);
// List the team project collections
foreach (CatalogNode collectionNode in collectionNodes)
{
Console.WriteLine(collectionNode.Resource.DisplayName);
}
Upvotes: 1