ProWF 4: Chapter 8 errata
A problem with the code for one of the examples has just been brought to my attention. The code for the ProblemReporting example in Chapter 8 is missing several lines. This code can be found on page 309 of the first edition of the book. The missing lines synchronize the code that is assigned to the Notification event with the Idle event of the workflow instance. Without this code, the code assigned to the Notification event may execute before the workflow is idle and before the bookmarks have been created.
Here is the revised section of code for the Program.cs file of the ProblemReporting project. The lines that should be added are highlighted below:
static void Main(string[] args)
{
try
{
AutoResetEvent syncEvent = new AutoResetEvent(false);
AutoResetEvent idleEvent = new AutoResetEvent(false);
WorkflowApplication wfApp =
new WorkflowApplication(new ProblemReporting());
wfApp.Completed = delegate(
WorkflowApplicationCompletedEventArgs e)
{
syncEvent.Set();
};
wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
idleEvent.Set(); //signal that the workflow is idle
Console.WriteLine("Workflow is idle");
};
wfApp.OnUnhandledException = delegate(
WorkflowApplicationUnhandledExceptionEventArgs e)
{
Console.WriteLine(e.UnhandledException.Message.ToString());
return UnhandledExceptionAction.Terminate;
};
HostEventNotifier extension = new HostEventNotifier();
extension.Notification += delegate(
Object sender, HostNotifyEventArgs e)
{
Console.WriteLine(e.Message);
idleEvent.WaitOne(2000); //wait until the workflow is idle
var bookmarks = wfApp.GetBookmarks();
if (bookmarks != null && bookmarks.Count > 0)
{
Console.WriteLine("Select one of these available actions:");
foreach (BookmarkInfo bookmark in bookmarks)
{
Console.WriteLine("->{0}", bookmark.BookmarkName);
}
}
Boolean isWaitingForChoice = true;
while (isWaitingForChoice)
{
String newAction = Console.ReadLine();
if (IsBookmarkValid(wfApp, newAction))
{
isWaitingForChoice = false;
wfApp.ResumeBookmark(newAction, null);
}
else
{
Console.WriteLine("Incorrect choice!");
}
}
};
wfApp.Extensions.Add(extension);
wfApp.Run();
syncEvent.WaitOne();
}
catch (Exception exception)
{
Console.WriteLine("Error: {0}", exception.Message);
}
}
Workflow and Custom Activity Best Practices
I’m catching up on my backlog of interesting bookmarks. Among them are a couple of endpoint.tv video sessions with Leon Welicki and Ron Jacobs. Leon is reviewing a set of best practices for WF4 including when to use each base activity class, and so on. Good stuff. Definitely worth a viewing:
ProWF 4 Publish Date
I’ve had a few emails from readers asking when my ProWF 4 book will be available. It was supposed to be available on June 30 (today) but for some reason it’s not. I’m not sure exactly why it’s held up — I know it’s been printed since I have my author copies in front of me right now. My best guess is that it should be available any day now from Amazon and perhaps a bit longer for other outlets.
WF 4.0, Dublin and Oslo Oh My!
No, I’m not attending the Microsoft love fest known as PDC (although I would have loved to go, I just couldn’t arrange it). So instead, I get to stay at home and read all about the cool new products and frameworks that Microsoft is announcing (and download the CTPs too).
Unless you’ve been hiding under a rock for the last year or so, you’ve heard something about “Oslo”. Although like me, you’ve probably not been able to fully understand just where MS was going with all of this. Well they’re finally starting to present more of their vision for the future of development.
Here’s a link to a good overview that MS has just published (written by David Chappell). It provides a high-level overview of how some of these future pieces will fit together. The pieces in this case are WF 4.0, Dublin (Windows Server extensions) and Oslo (Modeling repository).
The books are here
The author copies of my new Pro WF for .NET 3.5 book arrived today. They look great! So if you’ve pre-ordered the book from your favorite on-line book seller, they should be shipping any day now. The official release date is next Monday the 23rd.
Pro WF for .NET 3.5
So my last post to this blog was back in November. I’ve been very busy working on an updated version of my Pro WF book. The new edition of my book was originally scheduled for availability in late July, but that date has now been moved up to June 23rd.
The new edition provides coverage of the new WF features in .NET 3.5 and includes two new chapters. One of the new chapters covers WF and WCF integration (workflow services). The other new chapter provides better coverage of building custom composite activities and handling long-running tasks. I’ve also reviewed and updated all of the example code, the text and the screen shots.
Visual Studio 2008 now available
After a long wait, Visual Studio 2008 (formerly known as Orcas) is now available. I’ve been using beta 2 for some time now and it’s been very stable. .NET 3.5 is also included with VS 2008. I’ll now have to find a spare day to uninstall the beta and install RTM.
Here are a few pertinent links:
http://msdn2.microsoft.com/en-us/vstudio/default.aspx
http://msdn2.microsoft.com/en-us/subscriptions/bb608344.aspx
http://www.microsoft.com/express/
Let the downloading begin!
.NET Framework Source Code to be released
Microsoft announced today that it will be releasing the source code for the .NET Framework in the VS 2008 time frame later this year. No, it’s not going open source — instead it will be covered by something called the Microsoft Reference License. The intent is to allow us lowly developers a peek into the inner workings of the framework for debugging purposes.
VS 2008 will also provide an integrated debugging environment where missing bits of source code are downloaded automatically.
Pro WF on sale at Bookpool
Bookpool.com has all Apress books on sale at 50% off list price. It’s a great time to pick up my Pro WF book if you don’t already have it. Since it’s also published by Apress, my .NET Interop recipes book is also on sale.
Activity Validation for Bound Properties
One of the readers (Andrew) of my Pro WF book recently had a question about page 114 of the book. This page contains the code for a custom activity validator class that enforces design-time requirements. In this example, I wanted to make sure that two properties of the target activity were set at design-time.
Andrew pointed out that the code only accepts statically set values for the properties. If you set these dependency properties by binding them to another property, the validation fails. He’s right. That particular example code only demonstrates how to validate against statically set values.
To solve the problem, all you need to do is call the IsBindingSet method of the base Activity class. Here is the revised code from page 114 (Listing 3-11) that now works for statically set or bound property values:
using System;
using System.Workflow.ComponentModel.Compiler;
namespace CustomActivityComponents
{
/// <summary>
/// Validator for MyCustomActivity
/// </summary>
public class MyCustomActivityValidator : ActivityValidator
{
public override ValidationErrorCollection Validate(
ValidationManager manager, object obj)
{
ValidationErrorCollection errors = base.Validate(manager, obj);
//only validate a single custom activity type
if (obj is MyCustomActivity)
{
MyCustomActivity activity = obj as MyCustomActivity;
//only do validation when the activity is in a workflow
if (activity.Parent != null)
{
if (activity.MyInt == 0)
{
if (!activity.IsBindingSet(MyCustomActivity.MyIntProperty))
{
errors.Add(
ValidationError.GetNotSetValidationError(
"MyInt"));
}
}
if (activity.MyString == null ||
activity.MyString.Length == 0)
{
if (!activity.IsBindingSet(MyCustomActivity.MyStringProperty))
{
errors.Add(new ValidationError(
"MyString Property is incorrect", 501));
}
}
}
}
return errors;
}
}
}