Just after the .net 4.0 framework and VS10 were famously released without state machine, the activities team has also released the missing state machine activity onto codeplex. It’s available as both a user-friendly installable package and an open source download. Of course I’m going to download the source straight away and have a play with it. (First day I’ve seen the thing.)
Of course I’m interested in the source code too, more than the installed package. One thing I notice about the source straight away is that they are using the two rhyming assemblies, Microsoft.Activities.StateMachine and Microsoft.Activities.StateMachine.Design, to get runtime designer separation while still ensuring that the .Design dll can be loaded by the designer.
The third assembly there is a VS integration which lets the installer add the StateMachine to the VS10 toolbox. Looks like this source code should serve as a great example of how you can publish your activities for customers to use.
So what if you just want to try out the source code, build the activity, and play with it in VS without installing the package onto your machine? Happy to report it works, but there are a couple little weirdnesses with that – State and FinalState won’t show up in the toolbox. You can work around this by using copy/paste to copy existing states, or to create your own IActivityTemplateFactory for generating a more fully populated state machine.
-I found it weird that you can’t see anything inside the states inside the state diagram
-I’m getting weird validation errors about Trigger being null that don’t make any sense to me. I don’t know how to edit the triggers, the Transitions I mean….
Aha! Light dawns:
To see the transition you have to double-click on the links between states:
And then you can see the detailed transition view:
Besides it taking me ages to find the trigger view, a couple other things bugged me about the experience so far, which I hope they will improve in future releases:
-Validation errors only show up on the StateMachine itself, it would be better if they were on the specific State with a validation problem.
-You have to double-click on everything inside it to see any of the logic of your state machine (except conditions, which aren’t really interesting)
-Can’t set breakpoints on states or transition links. Can only set breakpoints on activities within the states, or on transitions.
-This means that when hitting breakpoints, you only see breadcrumbed views into states, you really can’t see where you are in execution of the top level statemachine, even if you breadcrumb back out.
One more thing I’ll mention is when I tried building from source code inside VS, I got exceptions when I ran my simple test workflow! What’s going on?
System.Xaml.XamlObjectWriterException was unhandled
Message=The invocation of the constructor on type 'ActivityLibrary1.Activity1' that matches the specified binding constraints threw an exception.
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object args)
Message=Could not load file or assembly 'Microsoft.Activities.StateMachine.Design, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Well, it turns out that it’s really no big deal. My StateMachine assemblies are
1) not gac’d
2) not in the same folder as my Executable and ActivityLibrary1 test assemblies which I’m using to run the thing.
All I need to do is adjust the build output paths of my test assemblies to be in the same folder as state machine assemblies.