Category Archives: Software Factories

Posted: Industry Vertical Episode 001

I am proud to present the first episode of Industry Vertical the twice monthly net cast about industrializing software development with Software Factories, Guidance Automation and Domain Specific Languages at http://tinyurl.com/aamnov. This episode starts out with the basics of Software Factories and trys to answer the question “What is a Software Factory”.

Industry Vertical Pre-Production Begins

I’ve decided to try my hand at webcasting. I’m in the stages of preparing a webcast series around using software factories, guidance automation and domain-specific languages called Industry Vertical. I’m planning on taking it slow starting out by providing some introductory material around what software factories are, their benefits and their life-cycle. Then I’ll take everyone step by step building out a software factory from the ground up. I’m hoping this will help everyone out there get started in industrializing software development.

 

So far, I’ve spent the last month getting my scripts together, creating graphics, setting up a new web site, purchasing audio equipment and I just found a great deal on a Sony HVR-A1 High Definition Camcorder, so once it arrives I’ll be ready to get down to business and start recording the first episode.

 

Hopefully, my busy work schedule will stay out of the way long enough to keep releases to a regular interval, but we’ll just have to wait and see what happens.

 

Don't call store.Dispose() if you didn't create it!

So, I’m happily plugging along, adding the ability to import a WSDL file into one of the DSLs for a new Software Factory we’re building at work. And after reading and re-reading the documentation and the DSL Book, I decide I need to call store.Dispose() in my code because I’m finished adding ModelElements to the model and I am leaving the command handler. You know, be neat and tidy when you exit a function dispose of any COM+ interfaces you’ve might have AddRef’d, etc.

 

So now I’m running the DSL and everything is working like it did before my single line of code, but now after adding the ModelElements to the model POOF! my model explodes! and I’ve lost everything in the model. I try it again a couple more times, kinda like pushing the car back up the hills to see if the brakes will fail for a second time after they did the first, you know typical programmer mentality and sure enough POOF! POOF! POOF! it keeps doing the same thing over and over.

 

So I trace through the code and notice that after I execute the store.Dispose() and exit the function, I get rerouted to the DocData class and it is trying to save the file and throws an Exception because the diagrams no longer exist.

 

So I go back and review my code and notice that I am not creating a new store and loading in the model, but I’m using the existing store that is opened by the DSL Editor and when I call store.Dispose(), I’m pulling the rug out from underneath me, the editor and Visual Studio as well.

 

So, I removed the single line of code that caused me an hour’s worth of grief and everything is working just hunky dory.

 

I guess it will always be engrained in my head, that unless I’m actually creating the store, I shouldn’t be disposing of it ,otherwise I’ll cause terrible things to happen.

 

Hopefully this will keep the rest of you from making the same mistake I did.

 

 

How to Create a Custom Editor for a Domain Model Element Property

Sometimes when defining a property for a domain model element you may need to use a complex type that has more than one property or can’t easily be displayed using a single text field or drop down in the property editor. A good example might be a class that holds a list of strings for a GUI interface or a Rich Text editor for a custom text field required by your framework.

 

To resolve this you can create a custom editor and hook it into your domain model that will provide a proper user interface to specify information for your property.

 

There are three steps you need to take in order to wire your domain property to display a custom editor:

 

1. Create a class derived from System.Drawing.Design.UITypeEditor that will launch the custom dialog box as below:

 

   1: 
   2: using System;
   3: using System.Collections.Generic;
   4: using System.Text;
   5:
   6: // Need to add a reference to System.Drawing DLL.
   7: using System.Drawing.Design;
   8: using System.Security.Permissions;
   9: using Microsoft.VisualStudio.Modeling;
  10: using Microsoft.VisualStudio.Modeling.Design;
  11:
  12: namespace XXX.UIProcessDesigner.UIEditors
  13: {
  14:
  15:     // FxCop rule: must have same security demands as parent class
  16:     [PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust"),
  17:         PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")]
  18:     public class FormPromptUITypeEditor : System.Drawing.Design.UITypeEditor
  19:     {
  20:
  21:         /// <summary>
  22:         /// Overridden to specify that our editor is a modal form
  23:         /// </summary>
  24:         /// <param name="context"></param>
  25:         /// <returns></returns>
  26:         public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
  27:         {
  28:             return UITypeEditorEditStyle.Modal;
  29:         }
  30:
  31:
  32:         /// <summary>
  33:         /// Called by VS whenever the user clicks on the ellipsis in the 
  34:         /// properties window for a property to which this editor is linked.
  35:         /// </summary>
  36:         /// <param name="context"></param>
  37:         /// <param name="provider"></param>
  38:         /// <param name="value"></param>
  39:         /// <returns></returns>
  40:         public override object EditValue(
  41:             System.ComponentModel.ITypeDescriptorContext context,
  42:             IServiceProvider provider,
  43:             object value)
  44:         {
  45:
  46:             // Get a reference to the underlying property element
  47:             ElementPropertyDescriptor descriptor = context.PropertyDescriptor as ElementPropertyDescriptor;
  48:             ModelElement underlyingModelElent = descriptor.ModelElement;
  49:
  50:             // context.Instance also returns a model element, but this will either
  51:             // be the shape representing the underlying element (if you selected
  52:             // the element via the design surface), or the underlying element 
  53:             // itself (if you selected the element via the model explorer)
  54:             ModelElement element = context.Instance as ModelElement;
  55:
  56:             FormPromptUITypeEditorForm theForm = new FormPromptUITypeEditorForm();
  57:
  58:             theForm.Value = (string)value;
  59:
  60:             if (theForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  61:             {
  62:                 value = theForm.Value;
  63:             }
  64:
  65:             return value;
  66:         }
  67:
  68:     }
  69:
  70: }
  71:
  72: 

 

2. Create a Windows Form dialog that will be displayed when the editor is invoked, such as the one below:

 

SampleWindowsForm

 

3. Set the Custom Attributes for the Domain Property to reference the UITypeEditor class you have created.

 

The text is as follows: [System.ComponentModel.Editor(typeof(XXX.UIProcessDesigner.UIEditors.FormActionTypeUITypeEditor),typeof(System.Drawing.Design.UITypeEditor))]

 

The bold faced text is the full namespace of your class that derives from UITypeEditor.

 

SamplePropertiesForm

 

I normally store all code that I add to a DSL Designer in various folders such as; CustomCode, UIEditors, Validators, etc. That way it is easy to find when I am trying to reference it.

 

Also, you can debug the UITypeEditor and Dialog by setting breakpoints in the code before you start debugging.

 

 

Adventures in Extending the Service Factory – Part 2

Here’s a handy tip when you are trying to learn how the components of the Service Factory works. I’ve found it very useful over the last couple of weeks.

 

Since the Service Factory now gets registered under the Visual Studio Experimental Hive you can configure the solution so you can debug it. If you are familiar with debugging DSLs, this should be nothing new. Just follow the steps below:

  1. 1. Set the Service Factory Guidance Package as the Start-Up Project by right-clicking on the project and selecting “Set as Start-Up Project”.
  2. 2. Change the Service Factory Guidance Package Project’s debug settings to launch Visual Studio under the Experimental Hive:
      1. a. Right click on the Service Factory Guidance Package Project and select “Properties”.
    1. b. Select the Debug Tab
    2. c. Configure the Start Action to Start External Program and C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe or where ever you have installed Visual Studio for the program.
    3. d. Set the Start Options, Command Line Arguments to /rootsuffix Exp

 

Now you can set breakpoints in the Service Factory code and press F5 to walk through the code in the debugger.

 

 

Adventures in Extending the Service Factory

I’ve been trying to add a couple of additional projects and item templates to the Service Factory for workflows and workflow activities. I thought I’d try to use the same techniques that the Service Factory was using to dynamically bind the menu options using the ProjectIsInRoleReference helper in the Binding.xml recipe.

 

So I did the following:

  1. 1. Added new roles WorkflowRole and ActivitiesRole to the file WSSF\Modeling.CodeGeneration\Source\Enums\ServiceFactoryRoleType.cs. I did this so that the Project Mapping helpers would incorporate the new roles into the ProjectMappingTable and get picked up by the ProjectIsInRoleReference helper.
  2. 2. Added the project templates to Templates\Projects.
  3. 3. Added the projects to the WCF and ASMX.vstemplate files.
  4. 4. Added new item templates to Templates\Items to use when the user selects the menu option to create a workflow or activity.
  5. 5. Added unbound recipes to unfold the templates. I used the CreateTranslator recipe as an example.
  6. 6. Added actions to the Binding.xml using the RefCreator and the ProjectIsInRoleReference just like the action for the CreateTranslator recipe.

 

When I created a new ASMX or WCF Implementation project, the new projects templates got unfolded without issue. But when I right clicked on either the workflow or activities project I did 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 was showing up correctly.

 

So I was at a loss as to why the menu options didn’t show up. I even tried to bind the recipes to the projects but still no luck. I dug out the older Extensibility Walkthroughs from the Service Factory CTP and there was 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 Visual Studio under the experimental hive the menu options showed up.  This behavior is not really apparent and I couldn’t find anything in the GAX/GAT documentation. I think that has a lot to do with the fact that running under the experimental hive is rather new for GAX/GAT and until the Service Factory you had to use the Clarius SFT to run under the experimental hive.

 

Guidance Development Tools

Guidance includes so many different types of documents; Help, How-Tos, FAQs, Checklists, Code Examples, Design Patterns, and Guidelines to name just a few that coming up with a standard way to develop the needed guidance is a hard task to do from scratch. Luckily Microsoft’s patterns & practices group has a tool that can simplify a lot of this for you.

 

The Microsoft patterns & practice’s Guidance Explorer provides a one stop shop for discovering, developing and publishing high quality development guidance. The project web site is located at http://www.codeplex.com/guidanceExplorer. There you can find the latest release of the tool as well as links to existing guidance examples developed by the team.

 

The tool includes an editor which provides standardized templates for many of the types of guidance you may want to include in your factory. The editor also includes the ability to add custom data to each guidance item for filtering by Technology, Category, Topic and Rule Type.

 

How I see this tool being used is pretty simple. As part of the factory development process the guidance developer creates the various guidance items using Guidance Explorer and then exports them to HTML for inclusion into the factory contents. The factory developer then includes links to the files as part of the recipes using the <DocumentationLinks> tag. Now when ever a consumer of the factory invokes a recipe the Guidance Navigator can navigate to the document relating to the action just taken. This could be anything; a checklist of what steps need to be taken in the process; a how-to article on the use of a model just created or even code examples of how to use the library just added to the project.

 

Another way to apply this tool to factory development is by incorporating the web edition of the tool. It provides a read-only version of the Guidance Explorer that can utilize an on-line store allowing all of your guidance to be in one place. The web edition could be launched in a separate pane within Visual Studio to provide the full guidance library to the factory consumer as they use the factory. They can perform searches for specific topics, filter on a particular category or use the Guidance Navigation pane to browse all of the sections at their leisure.

In my opinion this is a must have tool in any factory developers toolkit, check it out.