June 2006 - Posts

Notifying the Runtime Host Of A Workflow's Current State

Not sure how to get your UI host to reflect the current state of a persisted workflow? I found a way to get your tracking service to send this information to the hosted runtime from the workflow. Tracking services can track information like previous, current and next state for workflows. When a workflow is hydrated, the hosted runtime needs information about the current state to update the UI, so it makes sense to send state information about the workflow to the hosted runtime using a tracking service.

Host

  1. Build a tracking service for the workflow. There is a great example of this in the Hands On Lab's.
  2. Add the Tracking Service to the workflow runtime using the AddService() method
  3. To see that the tracking service returns the current state, add the following code

        void m_wfRuntime_WorkflowLoaded(object sender, WorkflowEventArgs e)
        {
            RentalCore.RentalTrackingService TrackSvc = (RentalCore.RentalTrackingService)m_wfRuntime.GetService(typeof(RentalCore.RentalTrackingService));
            MessageBox.Show(TrackSvc.CurrentActivity);
        }

Workflow

  1. Open up the workflow(.xoml) and override the following method

        protected override void OnActivityExecutionContextLoad(IServiceProvider provider)
        {
             RentalCore.RentalTrackingService TrackSvc = (RentalCore.RentalTrackingService)provider.GetService(typeof(RentalCore.RentalTrackingService));
             TrackSvc.CurrentActivity = base.CurrentStateName;
        }

    The code above grabs the tracking service from the workflow and sets a custom tracking service property, "CurrentActivity" to the workflow's "CurrentStateName". When the workflow is hydrated this method will run. When you run your solution, there should be a pop up demonstrating that the CurrentStateName is returned to the runtime host from the workflow.

 

 

 

Another Successful Code Camp

The Tallahassee User Group and Joe Healy did a great job putting together the Tallahassee Code Camp, this past weekend. These code camps are always fun, and I expecially had a great time explaining and showing off WF at my sessions. I also received some positive feedback from many that attended my sessions who plan to start messing around with the framework now that they have some insight! This was very rewarding to hear, since I had some trouble with one of my VPC images, during my last session. The crowd was very understanding, and instead, I turned my last session into a "chalk talk". I will webcast the demos that I did not get a chance to show, and I will make sure to put them up for viewing.

On a sad note,  my family and I returned home from Code Camp today, to find that our cat, "Solley" had passed away... "We miss you buddy!"

Free Intro To WF and State Machine Workflow Sessions

This Saturday, I will be spending my time at the Tallahassee Code Camp, sharing and demonstrating the power of Windows Workflow Foundation. My first session, "Intro To Workflow Foundation" will be a primer to familiarize the importance of WF with demos showing off powerful capabilities like how to communicate, build custom hosts and persist idle workflows. My second session, "People vs. Machine" is all dedicated to building and tracking State Machine styled workflows.

I cannot think of a better way to spend a Saturday... Of course, I could be hanging at the beach checking out the scene, but with a free all day geek fest event, why? WF is going to revolutionize business process development, so what could be more important then learning how? Come check out this free event if you are in the FSU area!

WF Tracking

Have you spent anytime with Windows Workflow's Tracking Services? I just finished spending the past view evenings trying to get up to speed for Tally's Code Camp, on July 17, 2006. I am sure there are going to be some questions about tracking, and luckily I found Moustafa Khalil Ahmed's blog which really helped me out. I wanted to share some info about tracking within areas that I struggled with and that were not to obvious.

TRACKING BACKGROUND:

Tracking is handled through the System.Workflow.Runtime.WorkflowRuntime. Custom services that inherit from System.WorkflowRuntime.Tracking.TrackingService are added to the hosting runtime just like any other service by using the runtime's AddService method.

Tracking Profiles can be customized to return what information is needed to be tracked.

  • Workflow Events
  • Activity Events
  • User Events

CUSTOM TRACKING SERVICES

To Building custom tracking services requires two things...

  • A custom Tracking Service object that inherits from the abstract class TrackingService
    • This is the service that is added to the workflow runtime
  • A Tracking Channel object that inherits from the abstract class TrackingChannel.
    •  Used to channel the tracked information back

BUILDING THE CUSTOM SERVICE

Override the TryReloadProfile function of the TrackingService object.

  • This function will be called by the runtime when changes are made.
  • This is also where code needs to be written for building a custom profile.

Override the GetTrackingChannel method of the TrackingService object.

  • This method is what passes the TrackingParameters to the TrackingChannel object

BUILDING THE TRACKING CHANNEL

Now for the TrackingChannel Object...

Override it's Send method

  • This is the method that passes the TrackRecord
    • The TrackRecord is built by the custom profile and holds the information about the workflow

Once the custom TrackingService is working, it can be customized even more to return exact information needed by the workflow host. Bottom line, tracking worklows is a must and should be considered part of building a workflow.

Happy Tracking!

WF Code Conditions

Here is a quick tip for using Code Conditions which are powerful for data driven results...

1. Use ConditionalEventArgs within the  parameter signature for routines

  • private void MovieIsLate(object sender, ConditionalEventArgs args)

2. Make sure to the condition  returns a boolean and that it is set to the ConditionalEventArgs "Result" property

  • args.Result = ((code==code))

These code conditions can be used for activities like ConditionActivityGroups which will execute contained activities based on the UntilCondition property and WhenCondition property of activities contained within it.

Tallahassee Code Camp 2006

Get ready for the next Florida code camp that is sure to answer questions you have on some of the latest technologies Microsoft has to offer. This year's Tallahassee Code Camp is scheduled for June 17, 2006... Register Now!!