Rehosting the WF designer in an application outside of Visual Studio is nothing new and since WF4, nothing particularly difficult. In fact the WF product team has gone out of its way to make rehosting the designer as easy an experience as possible and they’ve done a great job. The WCF and WF Samples for .NET Framework 4 provides code samples for rehosting the designer with its corresponding toolbox and properties grid. The samples also cover handling validation errors, executing workflows and providing some level of debugging through workflow tracking – most of what you need to write your own rehosted designer.
Here’s a rundown of its features and where appropriate I’ve provided references to sample code should you want to understand more about the implementation detail.
- Develop XAML Based Workflows And Workflow Services
Use the fully fledged WF designer to develop XAML based workflows and workflow services just as you would in Visual Studio. Interaction between the toolbox and properties box is just as in Visual Studio. For workflow services, add any WCF configuration to the Workflow Studio app config file. The solution comes with a test workflow service and client with appropriate configuration in the app config file as an example. Look at the Designer Rehosting example in WCF and WF Samples for .NET Framework 4 that demonstrates the basis for this implementation. Also, Pro WF Windows Workflow in .NET 4 by Bruce Bukovics has a great chapter on designer rehosting. Should you wish to execute other XAML based child workflows from a workflow then you can use the ExecuteXamlWorkflow custom activity I described in my previous post.
- Work On More Than One Workflow At The Same Time
Workflow Studio allows you to develop multiple workflows in a single application.
- Toolbox Support For All Standard WF Activities
All standard WF 4.0 activities are supported.
- Add Custom Activities To The Toolbox
To add custom activities to the toolbox, copy the custom activity DLL to the bin folder of Workflow Studio, select the “Add Reference …” option and locate the DLL file. The custom activity will then become available in the toolbox. If your workflow references custom activities then these will be automatically loaded and added to the toolbox when the workflow is loaded providing the referenced DLL has been previously copied to the bin folder. The section on designer rehosting in Pro WF Windows Workflow in .NET 4 by Bruce Bukovics, providing the details of toolbox manipulation that I used as basis for Workflow Studio.
- Execute Workflows Concurrently
You can execute one or more workflows or workflow services concurrently by either selecting “Start Debugging” or “Start Without Debugging” from the debug menu. Running workflows can be stopped by selecting “Abort” from the same menu. Each workflow has its own independent output window where WriteLine activity or exception stack trace output is written. You can also capture output through a trace source and associate a listener to log the output. We’re using standard .NET diagnostics here, so it’s totally flexible.
- Show Workflow Validation Errors
Any validation errors detected by the designer are displayed in the error window along with error code and severity. Each workflow has its own independent window.
- Debug Workflows
This isn’t fully fledged Visual Studio debugging – it’s workflow tracking. You’ll see the currently executing activity highlighted in the designer so you’ll be able to visually track the execution path of your workflow in real time. As each activity executes the activity name, id, state and workflow instance id are written to the workflow’s debug window. Clicking on a row in the debug window will focus the designer on the corresponding activity. Similar to workflow output, the debug window output is also captured through a trace source so that output can be logged. Check out Visual Workflow Tracking in WCF and WF Samples for .NET Framework 4 which demonstrates how to implement visual tracking in the designer.
- Visual Studio Like Window Docking And Pinning
One of the key features of Workflow Studio is to offer full window docking and pinning functionality that you find in Visual Studio. This functionality is provided by the AvalonDock open source WPF docking framework. This is a great framework but took some jumping through hoops to get working. I started out wanting to make this a pure MVVM application but soon discovered this wasn’t easy, if at all possible. Apparently this is addressed with the up and coming 2.0 release along with other improvements. Note that you’ll need to download and install AvalonDock independently of Workflow Studio since I don’t redistribute it here – don’t worry this is simple. Unfortunately there’s no NuGet package available as yet so please follow instructions below.
Controlling Debug Output
|PauseBetweenDebugStepsInMilliseconds||The number of milliseconds to pause before moving onto the next activity. This allows you to see the execution path more easily as the workflow executes in real time.|
|DisableDebugViewOutput||You may only be interested in tracking output sent to a file in which case you can disable interactive tracking by setting this value to true.|
- Download AvalonDock version 1.3.3571 from http://avalondock.codeplex.com/releases/48794/download/131885
- Run the installer. This will GAC the AvalonDock assembly.
Build the solution. You should not need to modify any references.
Hopefully you’ll find Workflow Studio a useful application for designing and debugging workflows in environments where Visual Studio is not a viable option. You can even use it for simple workflow hosting. It’ll save you writing a lot of boiler plate code and can serve as a starting point for your own implementation should you require something more specialized. I’d be interested to hear if you find Workflow Studio useful and welcome any feedback for possible enhancements. Also, please let me know of any bugs you may find.
Workflow Studio has been updated for .NET 4.5 to take advantage of some of the new designer improvements. If you are using .NET 4.5 and Visual Studio 2012 then it is recommended you use the version described in this post.
Written by Christopher Owczarek