In this post I will show how to recover and the information contained in the collection of Project Team Foundation Server using the Object Model messoci SDK available.
In the previous postseries we have seen how to connect to the TFS server, and then we take for granted being able to access the server.
To retrieve the collections of the project we can use the property CatalogNode TfsConfigurationServer class and perform a query to obtain the nodes of type Collection:
- Dim tfsInstance = TfsConfigurationServerFactory . GetConfigurationServer ( New Uri ( "http://server:8080/tfs" )) Dim
- tfsInstance.CatalogNode.QueryChildren collections = ({ CatalogResourceTypes . ProjectCollection} &
- # 160; ; & # 160; ; False , CatalogQueryOptions . None)
The variable collections contain a collection of read-only CatalogNode which are contained in the data we wanted. In particular
CatalogNode has a property of type Resource CatalogResource.
The most important properties of the class are CatalogeResource:
- Description: description of the collection (generally the resource). It is the description that we have entered during creation of the collection;
- DisplayName : name of the collective. It 's the name we included in the collection creation wizard;
- Identifier: This is a GUID that uniquely identifies the resource-level catalog;
- Properties: it is an object that implements IDictionary (Of String, String) in which contained property of the node. In particular, in this dictionary are the property instanceId useful when we want to retrieve the reference to the services exposed by the collection;
- ResourceType : contains the type of the resource. In this case it is TeamprojectCollection.
property CatalogNode a TfsConnection allows to obtain all the information relative ai nodi apparteneti alla connessione. Nel caso della TfsConfigurationServer si tratta di tuti gli oggetti contenuti nel server tra cui collection, progetti e via discorrendo.
Possiamo recuperare le informazioni contenute nella CatalogeNode anche avendo a disposizione l’istanza della Project Collection (cioè un’istannza della classe TfsTeamProjectCollection).
Prima di vedere come recuperare le informazioni di cui sopra vediamo come è possibile ottenere l’istanza della TFSTeamProjectCollection.
Se abbiamo a disposizione un’istanza della TfsConfigurationServer (vedi il post precedente), possiamo utilizzare il metodo GetTeamProjectCollection.
The method provides, as an argument, the instance identifier of the collection you want to retrieve. This is a GUID that is recoverable in the Properties property of the collection CatalogeResource instance with key "instanceId"
- Dim tfs = TfsConfigurationServerFactory . GetConfigurationServer ( New Uri ( "http://server:8080/tfs" )
- , & # 160; , & # 160; ; New UICredentialsProvider ())
- Dim collections = tfs.CatalogNode.QueryChildren({ CatalogResourceTypes .ProjectCollection},
-                                                               False ,
-                                                               CatalogQueryOptions . None)
- Dim collInstanceId = (n From In collections
- & # 160; Where n.Resource.DisplayName = "name collection"
- & # 160; Select n.Resource.Properties( "InstanceId" )).FirstOrDefault()
E’ evidente che se non abbiamo l’instance identifier e dobbiamo recuperarlo con il precedente pezzo di codice, abbiamo anche tutte le informazioni culla collection senza dover utilizzare l’istanza di TfsTeamProjectCollection ottenuta con il metodo GetTeamProjectCollection.
Supponiamo, per un attimo, di avere l’instace id senza dover accedere ai nodi della CatalogeNode dell’istanza di TfsConfigurationServer. In questo caso, per ottenere l’istanza di TfsTeamProjectCollection è sufficiente:
- Dim tfs = TfsConfigurationServerFactory . GetConfigurationServer ( New Type ( "http://server:8080/tfs" ),
- : & # 160; : & # 160; ; New UICredentialsProvider ()) Dim
- tfsColl = tfs . GetTeamProjectCollection ( New Guid (collInstanceId))
where instanceId is the string that identifies the instance of the Id collection.
GetTeamProjectCollection method behaves similarly to what we saw in the previous TfsConfigurationServerFactory post :
- if the instance of TfsConfigurationServer on which usage was generated by TfsConfigurationServerFactory, then the instance returned from the method will always same;
- if the instance of TfsConfigurationServer on which usage has been instantiated using the constructor, then the instance returned from the method will be different for each call.
Two other ways to retrieve the instance of TfsTeamProjectCollection are
- use the constructor of the class TfsTeamProjectCollection:
- Dim tfsColl = New TfsTeamProjectCollection ( New Uri ( "http://server:8080/tfs/nomecollection" )
- & # 160; , & # 160; New UICredentialsProvider ())
- use the factory class TfsTeamProjectCollectionFatctory:
- Dim tfsColl = TfsTeamProjectCollectionFactory . GetTeamProjectCollection ( New Uri ( " http://server:8080/tfs/nomecollection ")
- & # 160; , & # 160; , & # 160; ; New UICredentialsProvider ())
We observe that the URL of the collection is obtained by concatenating the name of the server URL colection.
If we use the factory, we will get the same instance of TfsTeamProjectCollection, while the manufacturer allows us to have a different instance each time.
When we have the instance to access the server component of the project collection, the same information can be recovered by going directly to the property and in particular to the property CatalogNode Resource:
- Dim collName = tfsColl.CatalogNode.Resource.DisplayName
- Dim collDescription = tfsColl.CatalogNode.Resource.Description
- Dim collInstanceId tfsColl.CatalogNode.Resource.Properties = ( "InstancreId" )
Another way to retrieve information relating to the collection in our server is to require TfsConfigurationServer instance, the service ITeamProjectCollectionService through education:
- Dim tfs = TfsConfigurationServerFactory . GetConfigurationServer ( New Type ( "http://rma-mbnb01-dev:8080/tfs" )
- & # 160; & # 160; & # 160; New UICredentialsProvider ()) Dim
- temProSrv = CType ( tfs . GetService ( Of ITeamProjectCollectionService ) (), ITeamProjectCollectionService )
and then invoke the method GetCollections:
- Dim collections = temProSrv . GetCollections ()
The result of this is a IList (Of TeamProjectCollection). The TeamProjectCollection is a class in this namespace Microsoft.TeamFoundation.Framework.Client and contains information relating to the collection project and a bit more.
0 comments:
Post a Comment