I have to give kudos to the ASP.NET Team. I really love the Atlas programming
model. I’d like to tell you that my Atlas based Workflow Designer is ready –
but it isn’t. But – I did re-build the WF WorkflowMonitor sample application
tonight as an ASP.NET Atlas based application (oh – and I also did is as a non-Atlas
based ASP.NET application for those of you that are still suck doing flicker-based
PostBacks ;-)).
What is Workflow Monitor? Well the Windows Workflow Foundation runtime will
take advantage of a TrackingService – if one is found inside of the WF runtime.
The runtime ships with a SqlTrackingService – which by default tracks all Activity
events. See my post on the WF forums if you have never gotten tracking up and
running for the steps I think people should go through to get the zen of WF tracking
– http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=438583&SiteID=1.
One of the coolest steps is to use the Workflow Monitor sample that ships with the
WF SDK. It is a Windows Forms application that will (assuming you are using
the SqlTrackingService and have added your workflow assembly as a reference or into
the directory where Workflow Monitor is running) show you what has executed in terms
of your Workflows. If you set the SqlTrackingService.IsTransactional property
to false, you can even see this in semi-realtime as the SqlTrackingService will write
each event to the database as it happens rather than batch them (all writes are done
transactionally regardless of the IsTransactional property BTW).
Why is this cool? Well – to me it shows off one of the big features of using
WF – visibility. You can even show this to your pointy-haired
bosses and they might start to see the advantage of WF. Here is a screen
shot of Workflow Monitor in action:
So what’s so cool here? Well two of WF’s major features are being emphasized.
First – Visibility (sometimes referred to as Transparency – I like the simplier term).
At runtime and after runtime we can actually *see* what our processes have done.
The second major WF feature displayed is the designer re-hosting inside of another
application other than Visual Studio. Although the designer really plays into visiblity
– the fact that we can host the designer in any application royalty free I think is
a huge bonus feature of WF. Oh – not to mention tracking and the capabilities
of the out-of-box SqlTrackingService.
So given my recent perseveration with Atlas and the WF designer I thought – wow wouldn’t
that be a cool combination? Having the visibility into your WF processes for the masses
– even those who don’t have the WF runtime on their machines – or those who you don’t
want to have to deploy the Workflow Monitor sample (which could be made into a pretty
deployable click-once application very easily).
So here we go – unlike last nights tease post – not only will I show you a Workflow
Monitor application hosted in ASP.NET – I’ll post the code as well.
So here is my version of the Workflow Monitor in ASP.NET (which at the designer level
borrows alot of code from the Workflow Monitor sample just to keep it consistent with
what people have become used to). First let’s look at the Atlas version.
Why an Atlas version? Well first of all as I mentioned I think Atlas rocks.
But it rocks for a very good reason (and that reason isn’t that pointy-haired
bosses know the term AJAX now
and think they are so cool because of that).
Atlas and Ajax is cool because is gives the user the best browser
experience possible. Clearly the smart-client experience is going to be superior.
But if you have to go with a browser only application – why not make that application
as easy as possible to use – and as nice as possible to look at. I think AJAX
browser applications do do that better than non-AJAX ones, and I think that Atlas
is a great framework if you are building ASP.NET applications.
So in the spirit of cross-browser love – I am going to show you all the screen shots
in Firefox. 🙂
Here is my atlas/ajax based Workflow Monitor application in Firefox:
This is the ASP.NET Workflow Monitor in Firefox, before any workflow has been
selected from the list of tracked workflows in the GridView on the right side of the
page (to make this managable for more than a demo you’d want to restrict the time-frame
of the query for these instances or give the use the ability to restirct the query
– you can find how to do that from the Workflow Monitor sample itself). Once
I select an workflow from the list of tracked workflows on the left – I get the following
(because it is using Atlas and an UpdatePanel there is no post-back flicker – only
the workflow image itself is being updated:
Again – I have to tip my hat to the ASP.NET team on the job they did on Atlas, I never
would have believed I could just write my ASP.NET page using the declarative ASP.NET
model, add a few extra declarations and have a cross-browser AJAX application. But
I have to say wow – they did it. My contribution to this demo pretty much pales
in comparison to theirs.
So how does this code work? Well quite a while ago I posted about hosting the
WF desinger in ASP.NET using a control and a handler to render a workflow
as an pure image. The worklow designer (WorkflowView actually) makes this option
availlable as a public method. The post I made last night about a WF Atlas
based designer is also based on that code – as is this code (for honest disclosrure I
borrowed much of the Workflow Monitor code directly for the worklfow drawing and use
of the tracking API).
All that really happens is that each time you select a workflow from the list in the
right-side GridView, a post-back is done to the server. On the server-side some
code in the page executes and retrieves the tracked workflow from the SqlTrackingService
Query API (the same code that the Workflow Monitor example uses) based on its InstanceId. That
information (the SqlTrackingServiceInstance) is stored in ASP.NET session.
The HttpHandler – once it gets a request from the current session uses the
SqlTrackingService instance to generate the image for the current workflow (the code
from Workflow Monitor already decorated the current worklfow with special glyphs or
images based on the execution status).
Just like the in Windows Forms version, this version loads the workflow into the Workflow
Designer, but unlike that version which shows the results to the screen, this version
captures an image (you can do this from the Workflow menu in Visual Stuiod 2005 as
well when you are designing a workflow).
In the Atlas version there is no flicker and the browser app appears fairly close
to Workflow Monitor. With a Atlas timer – you could replicate the Workflow Monitor
fucntionality almost completely and always hightlght and select the most recent workflow.
Again – if you are unlucky enough to be stuck doing ASP.NET without Atlas – I built
a version that removes all the Atlas references and tags, and does work – just looks
pretty bad since there is lots of post-backs and white screens in the browser.
You can download – either version (or hey download both versions and see the beauty
of atlas – and remember you have to download and install the latest version of atlas for
this to work – as well as beta 2.2 of WF) :
AtlasWorkflowMonitor.zip
(697.68 KB)
NonAtlasWorkflowMonitor.zip
(292.61 KB)
If you are stuck not using Atlas – this might a good time to introduce your pointy-haird
boss to AJAX. I am sure you’ll be using Atlas in a very short amount of time
😉