EventArgs Tracking Sample
This sample demonstrates the use of the SQL tracking service that is provided by Windows Workflow Foundation to track the execution of a workflow.
The workflow runtime raises certain events while it is executing a workflow. The tracking service can catch these events and store information about them in a SQL Server database that can be queried.
The tracking runtime defines TrackingWorkflowTerminatedEventArgs, TrackingWorkflowSuspendedEventArgs, and TrackingWorkflowExceptionEventArgs types to hold information about workflow termination, suspension, and exceptions respectively. WorkflowEventArgs are sent with the WorkflowTrackingRecord for their corresponding events. For example, TrackingWorkflowTerminatedEventArgs are sent with WorkflowTrackingRecord when the workflow status reaches a WorkflowTerminated state.
The SqlTrackingService receives these various EventArgs objects as they arrive, serializes them, and saves them to the tracking database together with their events if the tracking profile asks for those events. The serialized form can then be deserialized and consumed by tracking users. The tracking profile that is used is the SqlTrackingService default tracking profile.
The time value in a WorkflowTrackingRecord is in Coordinated Universal Time (Greenwich Mean Time).
The sample is a workflow console application and consists of two workflows:
ExceptionWorkflow. A simple workflow with a code handler, in which an exception is thrown. The exception is unhandled and results in terminating the workflow.
SuspendedWorkflow. A simple workflow with a suspend activity. The workflow should reach a suspended state.
The main entry for the sample is in the Program class, which has the following logic:
Creates a connectionString to the SqlTrackingService database.
Adds SqlTrackingService to the workflow runtime as follows:
Runs the workflows as follows:
WorkflowInstance exceptionWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(ExceptionWorkflow)); exceptionWorkflowInstance.Start();
Creates event handlers to wait for the workflow to finish or terminate (depending on the type of the workflow).
Queries the SqlTrackingService for specific WorkflowEvents and retrieves the binary-serialized object of the TrackingWorkflowTerminatedEventArgs, TrackingWorkflowSuspendedEventArgs, and TrackingWorkflowExceptionEventArgs.
Deserializes the data and writes their contents to the console.
Creating the SqlTrackingService Database
The SQL services that are installed by Windows Workflow Foundation use Microsoft SQL Server to store information. You can use Microsoft SQL Server 2005 Express, SQL Server 2000 or later versions, or SQL Server 2000 Desktop Engine (MSDE) for these tasks.
Windows Workflow Foundation Setup does not install the databases that are required by these services; however, Setup installs the SQL scripts for creating and configuring the databases for these services.
To create the SQL tracking database
Using Microsoft SQL Server 2005 Express, SQL Server 2000 or later versions, or SQL Server 2000 Desktop Engine (MSDE), create a new database named Tracking by using the SQL query statement:
CREATE DATABASE Tracking
In the SQL Query Analyzer workspace, select the database that you created in step 1 in the list of available databases.
On the File menu, click Open and open the SQL script %WINDIR%\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\<language>\Tracking_Schema.sql.
Execute the query by clicking Execute or by pressing F5 to create the SQL Tracking Service tables.
On the File menu, click Open and open the SQL script %WINDIR%\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\<language>\Tracking_Logic.sql.
Execute the query by clicking Execute or by pressing F5 to create the SQL Tracking Service stored procedures.
To build the sample
Download the sample by clicking Download Sample.
This extracts the sample project to your local hard disk.
Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.
Go to the source directory of the sample.
At the command prompt, type MSBUILD <Solution file name>.
To run the sample
In the SDK Command Prompt window, run the .exe file in the EventArgsTrackingSample\bin\debug folder (or the EventArgsTrackingSample\bin folder for the VB version of the sample), which is located below the main folder for the sample.
Other ResourcesTracking Samples
Simple Tracking Sample
Query Using SQLTrackingService Sample
Tracking Using User Track Points Sample
Query Using SQLTrackingService Sample
File Tracking Service and Query Sample
Using the Tracking Profile Object Model Sample
SQL Data Maintenance Sample
Windows Workflow Tracking Services