As some of you may have noticed I have been writing a number of custom Data Generators for the VSTS Database Edition over the last couple of months.
During this time I have learnt quite a bit about the way these work and about writing these components. There is scarce documentation and I couldn't find too much information around writing these in the blogosphere too. Any information out there seems to be put out when VSTS Database edition was released and obviously a lot has changed since then with the release of multiple updates (with the latest being GDR R2).
One of the things that makes a lot of sense to me is to try and reuse some the Generators that Microsoft has written to create more complex Generators. One of the most interesting Generators is the RegEx Generator. I did quite a bit of searching around and am yet to find any code/freeware that does the equivalent and from a data generation perspective it is absolutely important to have the ability to generate random data based on a pattern.
The class that does this work is called RegExString. (I look at the Microsoft.Data.Schema.Generators.Extensions.xml found in the VSTSDB\Extensions directory will give you this information). If you search around for information on this class you will find a lone MSDN entry and most probably one of my forum posts.
If you just add the dll specified in the Microsoft.Data.Schema.Generators.Extensions.xml to your reference you will find no RegExString Class that you can use. A little bit of sleuthing will show you that the namespaces between the Dll and the MSDN entry are wrong. Well this is because, the namespaces have changed with GDR R2(I am not sure if it changed with R2 or GDR R1) and now all Generators are internal (or friend) and not public. So only Visual Studio can create instances of these classes.
Well now what about the MSDN documentation, which does not talk about the class being internal. Well that is for the older DLL, Microsoft.VisualStudio.TeamSystem.Data.Generators.dll. You should still be able to find this dll in the DBPRo\Extensions directory inside Microsoft Visual Studio 9.0. This is the older version where the Generators are still public.
So I decided to use those in one of the newer Generators I am writing (hope to get a new release out sometime later this week). I know this is a risk as most probably this is going to disappear when moving to VS 2010, but as of now, this is the easiest way for me to generate some pattern based data.
This Dll also requires a reference to the Microsoft.VisualStudio.TeamSystem.Data.dll, which can be found in the DBPro directory.
Once this is referenced you should be able to create an instance of the class. So I created an instance and took the class for a spin,
regx.Expression = exp regx.MaximumLength = length regx.GenerateNextValues() value=regx.Result
Well this looks like this should work. If you try this you will get an "Object reference not set to an instance of an object" error. Searches and forum posts did not turn up any solution.
I had almost given up on this when I actually found the solution when playing around with the code searching for something else. The secret is to Initialize the Generator:
So once the Generator is initialized, everything should work fine. This actually is true for some of the other inbuilt generators I tried too…
I really hope Microsoft makes the inbuilt Generators public again so that it is easier for people to develop custom generators and not reinvent the wheel every time.