Tuesday, 11 September 2007

Some might remember that I was amongst the first to b*tch about not having a datepicker for wpf. Kevin Moore did his trick, and published a datepicker a long time ago. I'm very happy to see that a rich community is building around wpf. That has led to these two datepickers:

  • Farsi Library FX by Hadi Eskandari (here)
  • The datepicker from wpf contrib by Marlon (here)

Have fun with these!!

Tuesday, 11 September 2007 14:45:50 (Romance Standard Time, UTC+01:00)  #    Comments [1]  |  Trackback
 Tuesday, 04 September 2007

Monday morning, our application went live!! Hooray!!

All seems to be going well, although one user had problems when starting the application:

System.Windows.Markup.XamlParseException: Cannot convert string '0,0' in attribute 'StartPoint' to object of type 'System.Windows.Point'. Premature string termination encountered. Error at object 'LinearGradientBrush_1' in markup file 'PresentationUI;V3.0.0.0;31bf3856ad364e35;component/installationprogress.xaml'. ---> System.InvalidOperationException: Premature string termination encountered.

The problem occured even before our application had downloaded. Notice the component/installationprogress.xaml: That's not ours, but belongs to the framework.

I have seen these problems from time to time. We tried to fix it by re-installing the framework. (Sometimes, people have 6.715 instead of 6.920). That didn't work.

In the end, we simply had to discard the users profile. I made a copy of the profile, so maybe I'll find the time to look into the issue in-depth, but I wanted to blog about it, because someone might be running into the same issue.

Tuesday, 04 September 2007 11:18:24 (Romance Standard Time, UTC+01:00)  #    Comments [3]  |  Trackback
 Monday, 03 September 2007

This is turning into a hassle. I must confess that I feel that Microsoft does not have a good story on this one!

When thinking about versioning within the realm of workflow, there are a few things you have to know:

  • You will need to use strong signing for your processes, the activities, the External Data Exchange services and the items you put on the queue (we use these to correlate commands to queues, bypassing the weirdness of correlation in WF)
  • What is persisted to the datastore is a blob. That blob is created using serialization surrogates and use the normal binary serialization format. However, because of the surrogates, it is difficult (although not impossible) to touch your workflow instance directly, instead of going through the runtime. The surrogates are there for a reason: the serialization process of a workflowinstance is not a straight-forward process: all the activity contexts have to be serialized as well, as do the dependency properties etc.
  • The blob does not only persist your fields, but persists the complete structure of your running instance, called a template. So all the activities (initialized or not) are in that template.
  • Timers and their delays are persisted in a separate list by the surrogate. So, if your workflow instance is in a delay with 9 days left, this information is written in a timerCollectionList, with a guid pointing to the delay (remember, that delay is instantiated in a particular activityContext). It is not simple to correlate these. They are the main problem when you wish to just update your process.

Microsoft does not offer a smart way to upgrade version 1.0 to 2.0 of your workflow instance. When you have version 1.0 in your database, and make one little change to your process, dehydration will not work because of an index-out-of-bounds exception: remember that the persisted blob has the full template of the instance. So when you changed your process and added or removed an activity anywhere, the dehydration process is trying to map the persisted template to a type in your assembly and fails because of the different activity tree.

Therefor, you can do two things:

  1. Run both assemblies Side by Side
  2. Use workflow changes to change your current version to a 2.0 compatible version. 

Let's start by discussing option 2. Say you have created version 2.0 of your instance and try to rehydrate. Since you strongnamed, the runtime will throw an exception because it can not find your old assembly. You can place an assembly redirect in your config, telling the clr to try to use version 2.0 assemblies to instantiate your 1.0 blob. This will then fail because of that changed structure of your template.
The solution at hand is to use workflow changes to get in there, and change the structure of that 1.0 template to match that of a 2.0 version. You can of course only do this by loading in the old assembly side-by-side, but now you only have to do that once during an update-batch. After that, your normal application is able to use your 2.0 assembly to instantiate your 1.0 (but now structurally modified) instance.

The problem here, is that you have to build big workflow change scripts. I have not yet seen someone automate that (do a diff on the templates and generate the workflow changes). If that were available and rock-stable, this might be a good strategy to take. Until then, it's way too much work. (Let me know if this turns out to be super-simple!)

Option 1 is bad as well. Sure, loading in your old assemblies is possible. But what Microsoft forgot is that I want to change my external data exchange service as well (if only in version number) and the objects that I put in my queue. Since your old 1.0 process is expecting a 1.0 service to talk to, or 1.0 version commands, it will not be able to communicate!! This can be mitigated by adding the 1.0 External service to the runtime when loading the 1.0 assemblies, and maybe only using bcl types on the queues, but it's really a shame to have to do that. Certainly when you have processes that last 5 years, and you have 20 versions to keep up with.....

My advise is to really try to understand the way your application will use workflow. For us, I was able to make these assumptions:

  • There are a few states that need to be monitored by a delay activity of say 20 days.. When after that 20 days our process has not moved out of that state, something needs to happen.
  • Most states do not need that. Therefor, I can actually bring the process to a completed state. That actually is not what I prefer, however, since the state of a process can be derived from my domain objects, I can always construct the process at will and bring it in the correct state (with the new version!!). By completing the processes whenever possible, I will have a much smaller amount of processes to deal with in the datastore.
  • Most importantly: I found out that after processing an external event, the process will always return back into a state. It will never start a delay of more then a few minutes within a sequence. So I can guarantee that my workflow, when persisted, is not waiting inside a while-loop or whatever. All long delays are the first child within an eventdriven activity.

The last point reduces our problem big time, because it would be nearly impossible to build an update for a workflow instance that is waiting in the middle of a sequence. Basically, that is what we will be doing in our project: Build an update batch, that will load version 1.0 instances, kill them, create 2.0 version instances and write back to the database with the same guid.

The steps to build an update batch are:

  1. use workflow tracking or something to write the version of your process to your datastore. We have an oracle persistence layer. When we build it, we constructed a new column 'type' in the database and write the fullname of the type in there (which includes version number).
  2. load your old assembly so you can instantiate the blob
  3. instantiate the blob using reflection to directly get access to your instance
  4. do an export of your fields and other stuff you need. You know your processes intimately, so this should not be a problem
  5. delete the row from the datastore  (remember to start a transaction!)
  6. create a new type, using the runtime and the guid of the old instance
  7. call an import event or whatever, that the process will use to bring itself to the correct state
  8. persist

The hard part are the delays. Basically, you can find the list of timers using reflection. However, it is cumbersome to correlate the guids to the correct delay activities. My solution would be the following: during state changes within your process, keep a dictionary of the statename and the moment (Datetime) you transitioned to it. When importing, use this list and the delay.timeoutdurationEvent to setup your timer: normally, it would be DateTime.Now.Add(timeoutlenght). This time, you will use the original DateTime, and your delay activity will not have been 'reset'.

It's not pretty, and it will be necessary to put constraints on your processes. But it might work just fine for you! Let me know..

Monday, 03 September 2007 18:59:38 (Romance Standard Time, UTC+01:00)  #    Comments [7]  |  Trackback