Skip to main content

How to create an adapter for the TFS Integration Platform - Part IV: IProvider

Note: This post is part of a series and you can find the rest of the parts in the series index.

IProvider is the first class we will look at implementing for both adapters (WI and VC) as it provides the core information for the platform to talk to our adapter. The first thing you provider needs is the ProviderDescriptionAttribute, which has three properties ID, Name and Version.

[ProviderDescription("{7F3F91B2-758A-4B3C-BBA8-CE34AE1D48EE}", "SharePoint TIP Adapter - Version Control", "1.0.0.0")]
The ID must be unique and you will need a record of it somewhere as it is used in configuration for the platform. The name and version are potentially used to make it easier for users, but I have not seen them used anywhere (maybe in future/different tools).

The only  method in the provider is the GetService method which is used to get the implementations of the interfaces/classes we will be building later. Put another way this allows the platform to request a class which implements a specific interface using this method:

object IServiceProvider.GetService(Type serviceType)
{
    TraceManager.TraceInformation("WSSVC:Adapter:GetService - {0}", serviceType);

    if (serviceType == typeof(IAnalysisProvider))
    {
        if (analysisProvider == null)
        {
            analysisProvider = new SharePointVCAnalysisProvider();
        }
        return analysisProvider;
    }
    
    if (serviceType == typeof(IMigrationProvider))
    {
        if (migrationProvider == null)
        {
            migrationProvider = new SharePointVCMigrationProvider();
        }
        return migrationProvider;
    }

    if (serviceType == typeof(IServerPathTranslationService))
    {
        if (transalationProvider == null)
        {
            transalationProvider = new SharePointVCAdapterTranslation();
        }
        return transalationProvider;
    }        

    return null;
}

Above is the implementation is what I used in the SharePoint VC adapter, the WI adapter is the same except it does not have the server path translation service at the end.

Power Tip: Using Visual Studio 2010’s new “Generation from usage” features makes this stage of development much easier. 

How to create an adapter for the TFS Integration Platform - Part III: Overview of adapters

Note: This post is part of a series and you can find the rest of the parts in the series index.

The TFS Integration Platform has two types of adapters, a WI (for work items, tasks,  bugs etc…) and a VC (version control) adapter and they are nothing more than a .NET assembly made up of a number of classes which, mostly, you will inherit from interfaces in the Toolkit project. For both adapters the key interfaces you need to implement are:

  • IProvider: Gives the platform the way to invoke your adapter.
  • IMigrationProvider: This is used for writing to the adapters source system, so for me SharePoint.
  • IMigrationItemSerializer: This provides support for converting the item to XML.
  • IAnalysisProvider: This is used for reading from the adapters source system.

as well as they both need to implement the ChangeActionHandlers abstract class.

The VC adapter also needs:

  • IServerPathTranslationService: Used to translate the path (i.e. directories and such) from other adapters to this adapter and visa versa.

 

image 

While the WIT adapter needs:

  • IConflictHandler: Provides support for handling conflicts during the migration.

image

So in both adapters you will need a minimum of 6 classes you will implement, excluding any extra ones you will need for your specific requirements.

The core concepts of the adapters are all explained in the interfaces and so it appears that it is very simple to implement, and indeed it is – however there are some weird things which may catch you up which we will cover in detail in future posts.

TraceManager

Something very nice in the platform is the TraceManager class which is really just a wrapper around System.Diagnostics.Trace but it has some extras in that wrapper, such as being what is included in the console windows and log files. You will see this sprinkled through out my code because it is useful to to have when trying to debug later on.

Power Tip: The TraceManager puts all information written to it in the log files, so please make sure you do not put any sensitive information in there.

How to create an adapter for the TFS Integration Platform - Part II: Setup of the environment

Note: This post is part of a series and you can find the rest of the parts in the series index.

Getting started with the adapter development is not the easiest task because you are stuck a little in the wild, so this part will serve as as a quick start guide for getting what you need to become a TFS Integration Platform developer.

SQL Server

The TFS Integration Platform requires Microsoft SQL Server so you need to install an instance of that.

TFS

It goes without saying, or maybe it doesn’t, that if you plan to write an adapter to integrate to TFS you will need TFS. Even if you don’t care about TFS, you will want to test and the TFS 2010 adapters are of the highest quality and so they make a great test target (so testing between your adapter and TFS). Thankfully with TFS 2010 you can now install on Windows 7 natively so this means as a developer you can have a great easy environment.

Target system (SharePoint for me)

Since I was developing for SharePoint that meant I needed a SharePoint installation, which meant a 20Gb Windows 7 Virtual Machine :( Hopefully for you this will be less of an issue.

TFS Integration Platform

The TFS Integration Platform, is a software component and database which runs on your machine and handles the actual moving of data around. You can get it from http://tfsintegration.codeplex.com/releases - however it may not be obvious which is the one you want since the team has so many download options, you want the tools:

image

During install you will get an option to install the service, which is recommended for production environments when you want to have the synchronisation running continuously. However for development this is not needed.

Power Tip: Once you have completed the tools install, go into to SQL Server and backup the TFSIntegrationPlatform database immediately. There are not only a few odd bugs that roam around the platform (it’s still in beta) which may cause you to need a restore of the database but if you want to test on a clean environment then a restore is quicker than a reinstall.

Platform Source

To build adapters you will also need the source code for the TFS Integration Platform which you can also get from CodePlex. Best is to get the latest drop of the code which you can get from the Source Control page and then by clicking on the Download link in the latest version box on the far right.

image

In there you will find the IntegrationPlatform folder which contains all the code from Microsoft.

image

Power Tip: Make a common root for the TFS code and yours (in my case I used RangersCode) and then create sub directories in there for platform and your code (so I had My Production and MS production folders under RangersCode). This helps keep the items close, which makes things easier later plus keeps them separate so you can identify them.

The code itself is for Visual Studio 2008, however you can be just like me and use Visual Studio 2010 and it will work just fine. Once you have done all of this you are finally ready for writing your adapter!

How to create an adapter for the TFS Integration Platform - Part I: Introduction

Note: This post is part of a series and you can find the rest of the parts in the series index.

Since September 2009 I have been engaged in a ALM Rangers project, namely the TFS Integration Platform. Which is:

The TFS Integration Platform is a project developed by the Team Foundation Server (TFS) product group and the Visual Studio ALM Rangers to facilitate the development of tools that integrate TFS with other systems. Currently, the scope of this project is to enable TFS to integrate with other version control and work-item/bug tracking systems, but the eventual goal of this project is to enable integration with a broader range of tools/systems (i.e. build). This platform enables the development of two major classifications of tools: tools that move data unidirectionally into TFS, and tools that synchronize data bidirectionally.

So in short it is a integration system, like BizTalk or SSIS but specially built for version control and work items. I have not said TFS there because, it can work to migrate between other source control and work item systems provided adapters exist. Adapters are the logic which allows the TFS platform to connect to a variety of technologies, and my goal has been to build two of them – one for SharePoint lists and one for SharePoint document libraries.

You may have noticed that SharePoint isn’t a version control or work item system, so why integrate? Well lots of companies do use it for ALM related items, such as the lists being used for tracking work items and the document libraries are used to store content which should be in a source control system. This is the first post in a series which will give you an idea of what is involved in building adapters, show you what to avoid and hopefully give you a few laughs at my expense. 

Now I want to be clear this series will not covering usage of the platform or any of the core concepts in it. For those please see the links below in particular Willy-Peter’s blog. You do need to understand a bit about how the platform works before you attempt to build your own adapter.

As all my work was done for the ALM Rangers the source code for my adapters is included in the code which can be obtained from the CodePlex site.

To help you on your way let’s list a few links which are key for this:

.NET 4 Baby Steps: Part XIII - Tiny steps

07042010191 Note: This post is part of a series and you can find the rest of the parts in the series index.

There is a bunch of tiny additions in .NET 4 which I have not covered yet, this post provides a quick hit list of some of the new and improved features:

New

  • new StringBuilder.Clear: Quick method to clear a string builder.
  • new StopWatch.Reset: Quick method to reset a stop watch timer.
  • new IntPtr & UIntPtr: Both have had two new methods added, one for addition and one for subtraction.
  • new Thread.Yield: Allows you to yield execution to another thread that is ready to run on the current processor.
  • new System.Guid: Has got two new methods, TryParse and TryParseExact to allow for testing of the parsing.
  • new Microsoft.Win32.RegistryView: This allows you to request 64bit or 32bit views of the registry.
  • new Environment: Now contains two properties to identify 64bit scenarios:
    • Is64BitOperatingSystem: To identify if the OS is 64bit.
    • Is64BitProcess: To identify if the process is 64bit.
  • new System.Net.Mail.SmtpClient: Support for SSL

Improved

  • better Path.Combine: A new method overload to allow you to combine file paths.
  • better Compression.DeflateStream & Compression.GZipSteam: They have been improved so that they so no try to compress already compressed data.
  • better Compression.DeflateStream & Compression.GZipSteam: The 4Gb size limit has been removed.
  • better Monitor.Enter: A new overload has been added which allows you to pass in a reference boolean which returns true of the monitor was successfully entered.
  • better Microsoft.Win32.RegistryOptions: Now includes an option to specify a volatile key which is removed when the system restarts.
  • better Registry keys are no longer limited to 255 characters.
  • better System.Net.Mail.MaiMessage: Support for new headers
    • HeadersEncoding: Sets the type of text encoding used in the mail header.
    • ReplyToList: Sets the list of addresses to use when replying to a mail. This replaces ReplyTo which only supported one email address.
  • better System.Net.NetworkCredential: To improve security passwords can now be stored in a SecureString.
  • better ASP.NET Hashing: The default value has been changed from SHA1 to SHA256.
  • better ASP.NET Output caching: Previously setting the output cache to ServerAndClient also required calling SetOmitVaryStar to ensure it would be cached on the client. From .NET 4, calling of SetOmitVaryStar is no longer needed.
  • better TimeZoneInfo.Local & DateTime.Now: Both of these follow the OS daylight savings settings rather than using the .NET Framework settings.
  • better When running on Windows 7, locale info will be retrieved from the OS rather than being stored in the framework.
  • better Support for all 1400 characters of Unicode 5.1.
  • better ServiceInstaller.DelayedAutoStart: If you on a more modern OS (Vista, Win 7 etc…) then you can services can start as Automatic Delayed. This means they start, but after system boot so that the user gets in quickly. This is now possible for your .NET apps using the DelayedAutoStart property.

.NET 4 Baby Steps: Part XII - Numbers

22032010170 Note: This post is part of a series and you can find the rest of the parts in the series index.

A new namespace has arrived in .NET 4 for those who spend a lot of time with numbers, System.Numerics which has two classes: BigInteger and Complex – and they are exactly what they say they are. BigInteger is for big integers and Complex is complicated ;)

BigInteger

BigInteger is a class, not a type (like float), which allows you to have an integer with no theoretical upper and lower limits! Why is that cool? think about Int64 which can do up to: 9,223,372,036,854,775,807. If you have an Int64 which has that massive value, and you add one to it, the Int64 it overflows and becomes -9,223,372,036,854,775,806. That is not possible with BigInt since it has no upper limit!

Being a class means it has methods and properties you can use too, for example some of the properties

  • IsZero: Tells you if it equals zero.
  • IsEven: Tells you if it is an even number.

An example of using it:

BigInteger firstBigInt = new BigInteger(Int64.MaxValue);
BigInteger secondBigInt = new BigInteger(Int64.MaxValue);

Console.WriteLine("First BigInt is even? {0}", firstBigInt.IsEven);
Console.WriteLine("First BigInt = 1? {0}", firstBigInt.IsOne);
Console.WriteLine("First BigInt is power of twp? {0}", firstBigInt.IsPowerOfTwo);
Console.WriteLine("First BigInt = 0? {0}", firstBigInt.IsZero);
Console.WriteLine("First BigInt is positive (1), zero (0), or negative (-1)? {0}", firstBigInt.Sign);
Console.WriteLine("{0} multipled by {0} is {1}", Int64.MaxValue, BigInteger.Multiply(firstBigInt, secondBigInt));

You can also use the standard operators (-, +, * etc…) with it.

This gives the following output (look at the size of the number from the multiplication!):

image 

BigRational

What if you want to work with rational numbers with no limits, rather than integers? Then you can use the BigRational class the BCL team has made available at http://bcl.codeplex.com/

Complex

A complex number is a number that comprises a real number part and an imaginary number part. A complex number z is usually written in the form z = x + yi, where x and y are real numbers, and i is the imaginary unit that has the property i2 = -1.

That snippet is the first line from the documentation on System.Numeric.Complex and unfortunately I am not smart enough to know what they are talking about. So who should understand this?

  • Electrical engineers: Using Complex they can do the following: Resistance(R) and Reactance(X) to calculate the impedance Z.
  • Mathematicians: Vector Calculus as well as Graphs.
  • People using positional (mapping) info: X, Y coordinates on a  map or 2d plane.

For an example I will just wimp out and show you what the MSDN documentation has:

// Create a complex number by calling its class constructor.
Complex c1 = new Complex(12, 6);
Console.WriteLine(c1);

// Assign a Double to a complex number.
Complex c2 = 3.14;
Console.WriteLine(c2);

// Cast a Decimal to a complex number.
Complex c3 = (Complex)12.3m;
Console.WriteLine(c3);

// Assign the return value of a method to a Complex variable.
Complex c4 = Complex.Pow(Complex.One, -1);
Console.WriteLine(c4);

// Assign the value returned by an operator to a Complex variable.
Complex c5 = Complex.One + Complex.One;
Console.WriteLine(c5);

// Instantiate a complex number from its polar coordinates.
Complex c6 = Complex.FromPolarCoordinates(10, .524);
Console.WriteLine(c6);

That produces:

image

Some info on complex is from: http://www.dotnetspider.com/resources/36681-Examples-On-Complex-Class-C-New-Feature.aspx

.NET 4 Baby Steps - Part XI: Special folders

15052010218 Note: This post is part of a series and you can find the rest of the parts in the series index.

Environment.SpecialFolder

If you are building an application which takes advantage of special folders in Windows (special folders are folders like My Documents), you will be happy to know that .NET 4 has expanded the number of special folders it support, by adding 25 new options to the Environment.SpecialFolder enum.

The new options are:

  1. AdminTools
  2. CDBurning
  3. CommonAdminTools
  4. CommonDesktopDirectory
  5. CommonDocuments
  6. CommonMusic
  7. CommonOemLinks
  8. CommonPictures
  9. CommonProgramFilesX86
  10. CommonPrograms
  11. CommonStartMenu
  12. CommonStartup
  13. CommonTemplates
  14. CommonVideos
  15. Fonts
  16. LocalizedResources
  17. MyVideos
  18. NetworkShortcuts
  19. PrinterShortcuts
  20. ProgramFilesX86
  21. Resources
  22. SystemX86
  23. Templates
  24. UserProfile
  25. Windows

Usage is:

Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos));

GetFolderPath

The GetFolderPath method has also gotten an update with a new overload which takes a second enum, SpecialFolderOption. This has three values

  • None: Returns the path, but does not verify whether the path exists. If the folder is located on a network, specifying this option can reduce lag time.
  • Create: Verifies the folder path. If the folder does not exist, an empty string is returned. This is the default behavior.
  • DoNotVerify: Forces the folder to be created if it does not already exist.

Super fast network option:

Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos, Environment.SpecialFolderOption.None));

Visual Studio ALM Ranger Champions for 2010!

Group of Blue Men Tossing Another Into the Air Clipart Illustration I am a proud contributor to the Microsoft Visual Studio ALM Rangers (see this post for who they are) and each year, the Rangers have a vote for who they believe are helping the Rangers initiatives the most. The top four from the votes are honoured with the title of Champion! I was honoured in 2009 to be included in the list of the four champions and even more honoured that I have again been listed in the top 4!

Congrats to the other three champions and especially to Mathias Olausson, who was also re-awarded!

For more details on the latest Rangers champions see: http://blogs.msdn.com/willy-peter_schaub/archive/2010/05/12/external-visual-studio-alm-rangers-the-votes-have-been-tallied-and-the-2010-champions-are-have-been-known.aspx

DevDays Durban Slides and Bits

I had a great time in Durban this week presenting at the DevDays event. I was a bit nervous for my first keynote but calmed down once I was up there. I was much less nervous for the sessions and they turned out to be great fun.

Knowing is half the battle

As part of my prep I did fully script the demos and those scripts are included in hidden slides in the slide shows – so if you are looking to recreate the demos please download the slides and have a look.

For both my sessions I made use of the excellent (but I’m biased) Rule 18 tool. So if you looking for the actual code, which I referred to in my scripts with Rule 18 key presses, you should really download that too.

All the demos were done using Visual Studio 2010.

What’s new in ASP.NET 4?

What’s new in .NET 4?