Thursday, February 17, 2011

Brunswick Zone Bowling

TFS2010 Object Model: TeamProjectPicker

the TFS 2010 object model provides a window to allow our users to select a TFS server, a collection project or a project.

The window is implemented by the class TeamProjectPicker Microsoft.TeamFoundation.Client which is in the namespace (assembly Microsoft.TeamFoundation.Client.dll).

TeamProjectPicker allows some flexibility because it can be used to select a collection project, a project or a series of projects.

Before looking at how we can achieve this, we see how the class is structured.

The class has three constructors that allow you to handle the possibility of choosing what to select and what credentials provider to use.

In particular, the most comprehensive manufacturer is as follows:

  1. Public Sub New ( ByVal mode As TeamProjectPickerMode ,
  2.                  ByVal disableCollectionChange As Boolean ,
  3.                  ByVal credentialsProvider As ICredentialsProvider )

L’argomento mode, di tipo TeamProjectPickerMode, permette di selezionare la modalità di selezione e può assumere i seguenti valori:

  • NoProject : You can select the server and project collection;
  • SingleProject : You can select only one project
  • multiproject: You can select multiple projects.

The following figure illustrates how the different options:

SNAGHTML11981afb

disableCollectionChange The argument allows you to decide whether it should be automatically selected collection of default (false) that can not be changed by the user or not (true).

Finally, the argument credentialsProvider used to set the credentials provider to use in case the connection a TFS non disponga di credenziali valide. Il provider da noi impostato verrà richiamato nel momento in cui , a causa della mancanza di credenziali, l’utente clicca sul link “Use different credentials”.

La GUI, una volta istanziata, può essere personalizzata (a dire il vero non molto) utilizzando le seguenti proprietà:

  • AcceptButtonText : permette di impostare il testo che appare sul bottone di selezione;
  • HelpTopic : permette di impostare l’argomento della guida relativo al dialog;
  • Text : permette di impostare la caption del controllo.

e può essere mostrata all’utente with ShowDialog (as usual dialog windows forms).

The class exposes, finally, the two properties to retrieve the collection selected by the user (type of property SelectedTeamProjectCollection TfsTeamProjectCollection) and projects (SelectedProjects type ProjectInfo).

The following piece of code displays the dialog selection in multi project and retrieves the user-selected values:

  1. Dim pp = New TeamProjectPicker ( TeamProjectPickerMode . Multiproject,
  2. False ,
  3. New UICredentialsProvider ())
  4. If pp.ShowDialog () = Windows.Forms. DialogResult . OK Then Dim
  5. collection = pp.SelectedTeamProjectCollection
  6. Dim projects = pp.SelectedProjects
  7. '
  8. ' Use collection of projects and
  9. '
  10. End If

Before concluding I would like to report the post SetDefaultSelectionProvider method whose purpose is to allow you to change the logic with which TeamProjectPicker the server recovers, the collection and projects by default.

object as an argument of the method is provided for any class that implements the interface ITeamProjectPickerDefaultSelectionProvider. The interface provides the following methods:

  • GetDefaultCollectionId : Returns the GUID of the collection default server which is Uri passt by subject;
  • GetDefaultProjects : Uri returns a list of projects relating to the collection where Guid is passed to argument;
  • GetDefaultServerUri : Returns the URI of the server default.

This allows us to customize the logic by which the picker selects and proposes projects to the user.

Finally, the picker is a Windows Forms object, so you must reference the System.Windows.Forms assembly.

Technorati tags: object model tfs, tfs 2010 ,

Wednesday, February 16, 2011

Aspiration Of Blood Meaning

101 Async samples

Vi segnalo un post di Alessandro Del Sole in cui viene riportata la notizia che sono disponibili, sul sito di Lucian Wischik un insieme di esempi sulle funzionalità di Async attualmente in CTP.

L’indirizzo del sito è il seguente: AsyncSamplesSilverlight

 

Tag di Technorati: ,

Wednesday, February 9, 2011

Crick In Neck A Virus

VB.NET: retrieve the assemblies referenced in our application

La classe Assembly prevede il metodo GetReferencedAssembly() per recuperare l’elenco degli AssemblyName ralativi agli assembly referenziati da un determinato assembly.

The problem is that if we have a structure with more dll referenced in the chain, the method returns only the first level of the same chain.

Suppose we have the following structure:

image

or the project AssemblyExtension reference the dll AssemblyExtensionLIB1 which, in turn, reference the AssemblyExtensionLIB2.

In this case, the method GetReferencedAssembly (), applied to an assembly AssemblyExtension, returns the following list:

SNAGHTML4498867

As you can see there is no trace of AssemblyExtensionLIB2. The following method

di estensione provvede ad eseguire un algoritmo ricorsivo per recuperare una lista di AssemblyName contenente tutte le reference dell’assembly:

  1. Imports System.Runtime.CompilerServices
  2. Imports System.Reflection
  3.  
  4. Module AssemblyExtension
  5.  
  6.     < Extension ()> _
  7.      Public Sub GetAllReferenceAssemblies( ByVal sourceAssembly As Assembly ,
  8.                                           ByVal allowGacAssembly As Boolean ,
  9.                                           ByVal list As ICollection ( Of AssemblyName ))
  10.          If sourceAssembly Is Nothing Then Throw New ArgumentNullException ( "Source Assembly" )
  11.          If list Is Nothing Then Throw New ArgumentNullException ( "Destination List" )
  12.         list.Add(sourceAssembly.GetName())
  13.          If allowGacAssembly OrElse Not sourceAssembly.GlobalAssemblyCache Then
  14.              Dim assemblies = sourceAssembly.GetReferencedAssemblies()
  15.              For Each assemblyName In assemblies
  16.                  Dim query = From a In list _
  17.                              Where a.FullName = assemblyName.FullName _
  18.                              Select a
  19.                  If query.Count = 0 Then
  20.                      Dim assembly As Assembly = assembly.Load(assemblyName.FullName)
  21.                     assembly.GetAllReferenceAssemblies(allowGacAssembly, list)
  22. End If Next
  23. End If End
  24. Sub End Module

The extension method is applicable on any assemble and the parameters are:

  • allowGacAssembly: indicates whether to search the references in DLLs contained in the GAC;
  • list: the list that will contain AssemblyName search result.

If your project before writing:

  1. Dim list = New List (Of AssemblyName )
  2. Assembly. GetEntryAssembly (). GetAllReferenceAssemblies ( True , list)

We get:

SNAGHTML46ed88a

allowGacAssembly While if we set = false:

SNAGHTML46fb735

Attenzione: il metodo GetReferencedAssembly restituisce gli assembly effettivamente referenziati (cioè quelli per i quali c’è almeno un tipo utilizzato) e non quelli inseriti nelle referenze di Visual Studio.

 

Monday, February 7, 2011

North Face Denali Fluffy

TFS2010 Object Model: we manage the project collections

In questo post vorrei porre l’attenzione su come utilizzare l’object model di TFS per gestire le Project Collection, cioè come utilizzare  da codice i servizi messi a disposizione dalla piattaforma TFS per creare, eseguire il detach o l’attach delle project collections del nostro server.

L’object model di TFS mette a disposizione l’interfaccia ITeamProjectCollectionService implementata da quelle classi che hanno la capacità di gestire le project collections.

Per prima cosa recuperiamo questa classe, utilizzando il metodo GetService (ereditato dalla classe TfsConnection) della TfsConfigurationServer:

  1. Public Sub GetTeamProjectService()
  2.     tpcService = CType ( tfs .GetService( Of ITeamProjectCollectionService )(), ITeamProjectCollectionService )
  3.      Console .WriteLine( "ITeamProjectCollectionService ricavato!" )
  4. End Sub

dove tfs è un’istanza di TfsConfigurationServer ricavata tramite il seguente pezzo di codice:

  1. Public Sub CreateTFSInstance( ByVal server As String )
  2. & Try
  3. # 160; tfs = TfsConfigurationServerFactory . GetConfigurationServer ( New type (server),
  4. : & # 160; : & # 160; ; New UICredentialsProvider ())
  5.          tfs .EnsureAuthenticated()
  6.          Console .WriteLine( "Instanza di TFS creata!" )
  7.      Catch ex As Exception
  8.          Console . WriteLine ( "Error connecting to TFS: {0}" , ex . Message) End
  9. Try End Sub

Once recovered the service instance that implements ITeamProjectCollectionService we have a number of methods that allow us to "play" with the project collections.

Create a collection of projects

methods of collection management projects are generally methods whose execution may not take long and that is why we introduce the concept of ServicingJobDetail and append operations.

In fact the method that we use for the creation of a project is the collection method QueueCreateCollection that "appends" the task of creating the collection and returns an object of type ServicingJobDetail we can ask to have knowledge of Avenza Dellea state ' transaction.

An example of code for creating a collection is as follows:

  1. Dim job = tpcService . QueueCreateCollection (collName,
  2. & # 160; , & # 160; ; String . Format ( "{0} - code created by" , collName)
  3. & # 160; & # 160; False ,
  4.                                             String . Format ( "~ / {0}" collName,),
  5. , & # 160; ; Microsoft.TeamFoundation.Framework . Common. TeamFoundationServiceHostStatus . Started,
  6. & # 160; & # 160; Nothing )
  7. Dim tpcoll = tpcService . WaitForCollectionServicingToComplete (job)

QueueCreateCollection version of the method we are using includes the following topics:

  • name is the name we intend to give to our collection;
  • description: the description of the collection;
  • IsDefault: indicates whether the collection we're creating is the default or not;
  • VirtualDirectory: is the virtual directory in which to place the collection. in our case we use the name of collection was preceded by "~/";
  • : indicates the state in which the collection should be created. In our case the status is Started;
  • servicingTokens: it is an IDictionary (Of String, String) parameters that may contain useful accessories for id creation of the collection.

When we leave the previous method, we can stand waiting for the completion of the creation of the collection, with the methodology WaitForCollectionServicingToComplete. This will end when the transaction is complete and return an object of class TeamProjectCollection with information on the collection itself.

It 's interesting to observe the operation of creating the collection using the administrative console of TFS:

image

Detach a project collection exposed by

Another feature that we are examining is that of detach a collection project.

To run the detach a collection of projects is necessary to have the ol'istanza TeamProjectCollection or GUID of the collection and call the appropriate overload of the method QueueDetachCollection ITeamProjectCollectionService interface.

The following code snippet shows how to retrieve TeamProjectCollection a name from the collection of projects and run the detach:

  1. Dim collection = (c From In tpcService . GetCollections (). ToList ()
  2. , & # 160; Where c . collName Name =
  3. , & # 160; Select c). FirstOrDefault ()
  4. If collection IsNot Nothing Then
  5. Console . WriteLine ( " ; Detach collection begun! ")
  6. Try
  7. & # 160; Dim connectionString As String = Nothing
  8. Dim job = tpcService .QueueDetachCollection(collection,
  9.                                                     Nothing ,
  10.                                                     "Sto fermando la collection!!" ,
  11.                                                    connectionString)
  12.  
  13.          Dim tpcoll = tpcService .WaitForCollectionServicingToComplete(job)
  14.          Console .Write( "Detach Collezione Ok: connectionstring={0}" , connectionString)
  15.      Catch ex As Exception
  16. Console . Write ( "Failed to detach the collection: {0 } ", ex . Message)
  17. End Try
  18. & # 160; Console . WriteLine () Else
  19. Console . WriteLine ( "The collection does not exist!" )
  20. End If

Anche in questo caso, il metodo QueueDetachCollection restituisce un oggetto di classe ServicingJobDetail grazie al quale siamo in grado di comprendere quando l’operazione ha termine.

I parametri utilizzati nella chiamata al metodo di detach sono:

  • teamProjectCollection : è l’istanza di TeamProjectCollection che identifica la collezione da sganciare;
  • servicingTokens : si tratta di un IDictionary(Of String,String) che può contenere parametri accessori utili al detach della collezione;
  • collectionStoppedMessage : è il messaggio warning that appears, for example, in the administration console TFS detach during operation;
  • detachedConnectionString: it is a return value to the caller, containing the connection string of database "dropped" from TFS that can be possibly hung up in another TFS.

Attach a project collection

The inverse of a function to detach the collection is a project that allows you to attach a hook databese (containing a collection of projects) to TFS server.

The method used for this operation is QueueAttachCollection which provides a couple of simple overload of the piuù which has three parameters:

  • databaseConnectionString: is the connection string of the database containing the collection of projects;
  • servicingToken: it is an IDictionary (Of String, String) parameters that may contain accessories that are needed to detach the collection;
  • cloneCollection: indicates whether to run a clone of the collection.

The following code snippet shows how to perform the attach of a collection given the connectionString:

  1. Dim job = tpcService . QueueAttachCollection (databaseConnectionString,
  2. & # 160; & # 160; Nothing ,
  3.                                             True )
  4.  
  5. Dim tpcoll = tpcService .WaitForCollectionServicingToComplete(job)

Come visto in precedenza possiamo sfruttare il job restituito dal metodo di attach  per capire quando il lavoro è concluso.

Tra i metodi messi a disposizione dall’interfaccia vista in questo post abbiamo anche il metodo che può essere utilizzato per eseguire l’attach di un database di TFS precedente alla versione 2010.

A compendio di questo post vorrei allegare un esempio di console sviluppata con Visual Studio 2010 che permette di integrare le funzioni viste.

The console provides the name of the TFS server in the form http://server:8080/tfs, is passed as an argument.