Modifying the Service Factory

Topics: Service Factory Modeling Edition Forum
Nov 8, 2007 at 10:34 PM
I noticed that the Hands-On Labs that used to talk about tailoring the Service Factory are missing. I also noticed that the source code version only registers itself in the Experimental Hive. Are there plans to provide tailoring guidelines at a later time? I had tailored the earlier versions of the CTP to tailor it for our internal project structure as well as add some new item and project templates. I am hoping I'll be able to do the same with the final release.
Developer
Nov 8, 2007 at 10:59 PM
Yes! We are finalizing the Extensibility Hands-on Labs (Hands-on Lab: Creating Your Version of the Service Factory) this week and we will post them next week.
Nov 9, 2007 at 4:03 AM
Great to hear! I'm loving what you have done to the factory and all of the new extensibility enhancements. I'll keep watching for them.
Nov 13, 2007 at 10:53 AM
I have tried tweaking and understanding the source code and I think that customizing the "Service Factory Guidance Package Files.wxs" file (i need to generate a lot of new guids for this one) under the setup project is needed to somehow register it to the msi being created during the build. I tried doing this and the msi created the customized projects I have added in the service factory solution. I tried deploying the msi generated from the rebuild of the customized solution (but deploy first the requirements like GuidanceAutomationExtensions.msi, DSLToolsRedist.msi and ProjectAggregator2.msi) and it was successful and it put the customized projects I have created in the folder where I placed it in the installation wizard. I have deployed this to my test vpc image that has VSTS on it with NO experimental hive. Just has VSTS, .net framework 3.0 and the required installation softwares from the deployment documentation of the V3 binary release. I followed the deployment as how it was documented in the binary release msi for the service factory and only replaced the msi with the customized msi that I have created.

Now the problem. When I tried to run my visual studio and create a model project, its giving me an error that I need to have some Package Load Key for the Microsoft.Practices.ServiceFactory.VsPkg.ModelProjectPackage.dll. I tried registering in the VSIP site and doing the change in the source code(uncommenting the ProvideLoadKey attribute in the class of ModelProjectPackage.cs and adding the generated package load key from the VSIP site to the resource file) and redoing all the reinstallation with a fresh vpc image, however I'm still getting the package loading error. I haven't done development that uses package load key and I think this is causing my error.

I haven't detail here how I customized it since I just want to know if I'm on the right track. I hope the how-to document would be released soon so I know if I'm still at the right track or not or if the service factory guys can give me something if I'm on the right track on this one and if I'm on the right track, hopefully you can give me some early direction on how to fix this one. Thanks.
Nov 13, 2007 at 11:43 AM
I think I made it work. I noticed that the company name and product name under the OS's registery --> HKLM\Software\Microsoft\VisualStudio\<version>\Packages\<Package GUID> didnt register the correct values as what I registered in the VSIP site. I tried manually changing the values on the registry and doing a "devenv /noVSIP /log" command on the VS command prompt and my custom service factory worked! I would try to test this more and hopefully when the how-to document gets release, I can cross-check the documentation where I miss that configuration.
Nov 14, 2007 at 3:00 AM
I've been trying to add a couple of additional projects to the service factory for workflows and workflow activities. I thought I’d try to use the same techniques that the service factory is using to dynamically bind the menu options using the ProjectIsInRoleReference helper in the Binding.xml recipe.

So I’ve done the following so far:

1. Added new roles WorkflowRole and ActivitiesRole to the file WSSF\Modeling.CodeGeneration\Source\Enums\ServiceFactoryRoleType.cs.
2. Added the project templates to Templates\Projects.
3. Added the project in the WCF and ASMX.vstemplate files.
4. Added new item templates to create a starter workflow and starter activity
5. Added unbound recipes to unfold the templates. I used the CreateTranslator recipe as an example.
6. Added actions to the Binding.xml using the RefCreator and the ProjectIsInRoleReference just like the action for the CreateTranslator recipe.

When I create a new ASMX or WCF Implementation project, the new projects get created without issue. But when I right click on either the workflow or activities project I do not see the menu options to launch the recipes on the context menu.

At first I thought maybe the ProjectIsInRoleReference helper was not working, but I added debug output to indicate whether it found a match or not and everything is showing up correctly. So I am at a loss as to why the menu options don’t show up. I even tried to bind the recipes to the projects but still no luck.

Does anyone have any ideas why this is not working. Is it because I am running in the experimental hive or does the service factory use something completely different to add the menu options.
Nov 14, 2007 at 3:35 AM
Figured it out. In reading the older ExtensibilityWalkthroughs there is an example for adding a new recipe through the binding.xml file. It seems that because we are testing in the Experimental Hive you need to run the following command to reset the context menus; devenv /rootsuffix Exp /Setup.

Once I ran the command and then restarted VS under the experimental hive the menu options showed up.

This is not really apparent and I think that has a lot to do with the fact that running under the experimental hive is rather new for GAX/GAT.
Nov 15, 2007 at 3:34 PM
There are numerous cases where you can end up putting the hive into an inconsistent state when modifying the factory, especially around menus. The best way to clean up the (experimental) hive is to run the "Reset the Visual Studio 2005 Experimental Hive" tool (in the SDK tools program files shortcuts). This effectively copies the existing main hive settings into the experimental hive. You can also use the option you describe to reset menus etc but this isn't as complete as resetting the hive.

devenv /setup docs: http://msdn2.microsoft.com/en-us/library/ex6a2fad(VS.80).aspx

I would recommend resetting the hive after any major change to the factory or when I started to see unexpected behavior with my changes to it.
Nov 15, 2007 at 5:19 PM
Edited Nov 15, 2007 at 5:41 PM
I was reapplying the changes I made to the CTP version of the Service Factory as posted on my blog at http://geekswithblogs.net/jlavin/archive/2007/09/15/115376.aspx and all of a sudden the XsdSchema to Code generation quit working.

What is happening is as the ArtifactLinks are being evaluated, all of the ArtifactLinks for kicking off the XmlSchemaCodeGeneration are being ignored because they are matching up with the ArtifactLinks for the TextTemplateCodeGeneration.

I basically had to comment out a couple of lines in the GenerateArtifacts function of the Microsoft.Practices.Modeling.CodeGeneration.CodeGenerationService class as shown below:

SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")
public int GenerateArtifacts(ICollection<IArtifactLink> artifactLinks)
{
Guard.ArgumentNotNull(artifactLinks, "artifactLinks");

// reset the visited files list
this.visitedFiles = new StringDictionary();

// list to avoid duplicate code gen of an already visited link.
List<IArtifactLink> generatedLinks = new List<IArtifactLink>();
int generatedObjects = 0;

foreach (IArtifactLink link in artifactLinks)
{
//if(!generatedLinks.Contains(link))
//{
int generated = GenerateArtifact(link);
if (generated > 0)
{
generatedLinks.Add(link);
generatedObjects += generated;
}
//}
}
return generatedObjects;
}

What this did was allow all of the ArtifactLinks to be evaluated and the code was generated as expected. Only issue is now a lot of the code is being re-generated several times, but I can live with that since it is over writing the files.

What is strange is that I didn't mess with any of the classes other than the ObjectExtenders for the WCFOperationContract and ASMXOperationContract and the TextTemplate ServiceImplementation.tt, like I describe in my blog.

I went back and performed a diff between my current code base and the original source code release and I couldn't find anything that looked odd or out of place.

Does anyone know why the ArtifactLinks for the TextTemplateCodeGeneration and XmlSchemaCodeGeneration are being confused when they apply to the same model element?

And what is the best way to walk the factory through the debugger? I ended up following the same route that is used for DSLs. I set the GuidancePackage as the StartUp Project and have the debugger start devenv.exe with the command line arguments "/rootsuffix Exp". Is there a better way to do this?

Thanks
Nov 18, 2007 at 6:06 PM
Edited Nov 18, 2007 at 6:37 PM
I think most of this question was answered on your other thread:

http://www.codeplex.com/servicefactory/Thread/View.aspx?ThreadId=17913

In short you needed to add an artifact link for each artifact, rather than generating two artifacts by attaching additional strategies to the same link.

As for your debugging question. Yes, the simplest way to debug is to use the same settings a DSL project would use, or start VS in the Exp hive and simply attach the debugger to it.

If you're interested in modifying the Service Factory I've been blogging about some aspects of this:

http://www.ademiller.com/blogs/tech/category/microsoft/service-factory/

Ade