Interception / execution of actions in the Windows workflow

Does the Windows Workflow Foundation provide the ability to intercept or decorate activities for purposes such as logging? For example, to create logs for each activity and exit record (ideally including an activity name) without changing all existing project code.

For example, I have a workflow with one action that prints "Hello world". Without making changes to the XAML file, I would like to commit a record and exit from it. I would like to print “Enter Hello World Activity” before entering this activity, and after the activity printed “Hello World”, I would like to print “Completed Hello World Activity”.

Does Windows Workflow provide a mechanism to enter and exit an action?


@ Richard210363 already added to the comments that this feature is supported by the Windows Workflow Foundation - please, can users who decide to close this question consider canceling their decision, since the question clearly has a very specific answer using the structure in question?

+7
c # aop workflow-foundation-4
source share
2 answers

Take a look at the TrackingParticipant workflow class.

He acts in all activities in the workflow similar to AOP in the field.

It emits information about entering and exiting actions.

Create a class that inherits from TrackingParticipant and overrides 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 starts.

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

You can also enable TrackingRecord in WorkflowInstanceRecord. Between them, ActivityStateRecord and WorkflowInstanceRecord provide a lot of information about the workflow and its actions.

+3
source share

I wrote the following code that can track all work processes and activities.

 public class ActivityTracker : TrackingParticipant { protected override void Track(TrackingRecord record, TimeSpan timeout) { if (record != null) { if (record is WorkflowInstanceRecord) { WorkflowInstanceRecord instanceRecord = record as WorkflowInstanceRecord; Console.WriteLine("Workflow Record: Instance: {0} - State: {1} - Definition Identity: {2}", instanceRecord.ActivityDefinitionId, instanceRecord.State, instanceRecord.WorkflowDefinitionIdentity); } else if (record is ActivityStateRecord) { ActivityStateRecord instanceRecord = record as ActivityStateRecord; Console.WriteLine("Activity Record: Name: {0} - State: {1}", instanceRecord.Activity.Name, instanceRecord.State); } } } } 
+5
source share

All Articles