Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intercepting/Decorating Activities in Windows Workflow

Does Windows Workflow Foundation offer a way to intercept or decorate activities for purposes such as logging? For example to create logs for every activity entry and exit point (ideally including the activity name) without modifying all the existing project code.

For example, I have a workflow with a single activity that prints "Hello world". Without making modification to the XAML file I would like to capture the entry and exit of the activity. I would like to print "Entering Hello World Activity" before entering the activity and after the activity has printed "Hello World", I would like to print "Completed Hello World Activity".

Does Windows Workflow offer a mechanism for hooking into entry and exit of an activity?


@Richard210363 has already added to the comments that this feature is supported by Windows Workflow Foundation - please can the users who chose to close this question consider reversing their decision as the question clearly has a very specific answer using the framework in question?

like image 568
thangamanikasi Avatar asked Aug 27 '14 13:08

thangamanikasi


1 Answers

Have a look at the workflow TrackingParticipant class.

It acts across all Activities in the workflow similar to AOP in scope.

It emits information about the entry and exit of activities.

Create a class that inherits from TrackingParticipant and override the Track method:

protected override void Track(TrackingRecord record, TimeSpan timeout)
    {
        ActivityStateRecord activityStateRecord = record as ActivityStateRecord;
        string CurrentActivityName = activityStateRecord.Activity.Name,
    }

Then attach your tracking class to the workflow before it runs.

_workflowApplication.Extensions.Add(_yourWorkFlowTrackingClass);
_workflowApplication.Run();

You can also cast a TrackingRecord to a WorkflowInstanceRecord. Between them, ActivityStateRecord and WorkflowInstanceRecord supply a lot of info about the workflow and its activities.

like image 53
Richard210363 Avatar answered Sep 28 '22 07:09

Richard210363