Workflow Monitor Sample
The Workflow Monitor is a tool for displaying workflow and activity status information about completed and currently executing workflows. The monitor reads tracking information from the tracking database and displays current workflow and activity state and also current workflow execution by using the workflow designer control.
For the Workflow Monitor to work properly, any workflow types that have tracking information in the database should be either in the GAC or the same directory as the Workflow Monitor executable. If any types are missing, you will get an error while loading the workflow definition. Additionally, you will need to create a new tracking database and run the workflows in order for the Workflow Monitor to properly discover the workflow types.
See the following sections on how to add the SQL tracking service to your workflow runtime so that the tracking events will be tracked to the SQL tracking database.
Setting up a Host for Monitoring
For the monitor to display workflows and activities, the designer and serialization code must be available to it. All workflow and activity types must be registered in the global assembly cache (GAC) by using gacutil.exe, or put in the same directory as WorkflowMonitor.exe. Additionally, access to the types is required by the SqlTrackingQuery to read workflows, activity information, and workflow definition from the SqlTrackingService tables.
The following procedure demonstrates how to configure the tracking database that is used by the Workflow Monitor application.
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
Note When using both the SqlTrackingService and the SqlWorkflowPersistenceService in a workflow application, it is recommended that you use a single database for both persistence and 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.
Configuring the Host Application
To configure a host application to use SqlTrackingService, add the SqlTrackingService service to the WorkflowRuntime collection of services either programmatically or through a configuration file. Set the ConnectionString property for the server name and database. Set the IsTransactional property of the SqlTrackingService service to false, so that the data available to the monitor is current (if the IsTransactional property is set to true, information is batched before it is written to the database.)
To add the SqlTrackingService service programmatically, use the following code example:
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
SqlTrackingService sqlTrackingService = new SqlTrackingService("Initial Catalog=Tracking;Data Source=localhost;Integrated Security=SSPI;");
sqlTrackingService.IsTransactional = false;
Dim workflowRuntime As New WorkflowRuntime()
Dim sqlTrackingService As New SqlTrackingService("Initial Catalog=Tracking;Data Source=localhost;Integrated Security=SSPI;")
sqlTrackingService.IsTransactional = false
To add the SqlTrackingService service via a configuration file, the host application code must specify the configuration section name in the WorkflowRuntime constructor, and the configuration file (for example, app.config) must contain the WorkflowRuntime configuration information. For example:
C#: WorkflowRuntime workflowRuntime = new WorkflowRuntime("WorkflowRuntimeConfigurationSection"); workflowRuntime.StartRuntime(); Visual Basic: Dim workflowRuntime As New WorkflowRuntime("WorkflowRuntimeConfigurationSection") workflowRuntime.StartRuntime()
<configuration> <configSections> <section name="WorkflowRuntimeConfigurationSection" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </configSections> <WorkflowRuntimeConfigurationSection Name="WorkflowRuntimeConfigurationSectionName" UnloadOnIdle="false"> <Services> <add type="System.Workflow.Runtime.Tracking.SqlTrackingService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ConnectionString="Initial Catalog=TrackingStore;Data Source=localhost;Integrated Security=SSPI;" IsTransactional="false" UseDefaultProfile="true" /> </Services> </WorkflowRuntimeConfigurationSection> </configuration>
Monitor User Interface
The monitor interface contains three primary panes:
Workflow View pane.
The monitor reads all workflows that have been tracked. To specify the computer name and database, use the Settings dialog box. To open this dialog box, click Settings on the Monitor menu, or click the Settings toolbar button.
Workflows Search Option Toolbar
This toolbar displays search options for the tool. You can search by using a combination of workflow status and time interval when the status occurred, and by tracking data item values. You can also search by workflow ID. As an example, you can search for terminated workflows that were terminated yesterday where the tracking data item PurchaseAmount had a value of 500 in the CheckCredit activity.
By default, the SqlTrackingService default tracking profile extracts all workflow, activities, and user track point events. It does not extract any workflow tracking data. Therefore, you cannot search by Tracking Data Item until you update either the default tracking profile or the tracking profile that is associated with the specific type that you are running. You can use a SQL script that is available with this sample, UpdateV1DefaultTrackingProfile.sql, to update the default tracking profile to extract the Name property from activities.
You do this with the following item in the tracking profile:
<Extracts> <WorkflowDataTrackingExtract> <Member>Name</Member> </WorkflowDataTrackingExtract> </Extracts>
This pane displays all workflows in the tracking database together with the status of each workflow. When a workflow is selected, the tracking database is queried for the current status of all completed and executing activities for that workflow, and these activities are displayed in the Activity pane.
This pane displays all the activities and activity status for the workflow that is selected in the Workflows pane.
Workflow View Pane
This pane hosts the workflow designer control that is shipped as part of Windows Workflow Foundation. It lets the user expand and collapse composite activities and change the workflow view (between the main view, exceptions, events, and compensation). When a workflow is selected in the Workflow pane, the Workflow pane displays a check mark on all completed activities, and a "Play" icon on all the currently executing activities.
The menu options for the Workflow Monitor are as follows:
Exit - Exits the program.
Workflow Details - If enabled, shows the Workflow and Activity panes.
Start/Stop - Starts or stops the monitoring.
Settings - Displays the Settings dialog box.
The toolbar buttons for the Workflow Monitor are as follows:
Settings - Shows the Settings dialog box (for more information,see the "Settings" section).
Monitor On - Starts monitoring the tracking database (See "Using the Monitor").
Monitor Off - Stops monitoring the tracking database (See "Using the Monitor").
Expand All - Expands all the composite activities in the workflow view.
Collapse All - Collapses all the composite activities in the workflow view.
Workflow Zoom Level - Sets the zoom level of the workflow view.
You use the Settings dialog box to configure the monitor. You can specify the following fields:
SQL Server - The local or remote computer that is running SQL Server.
Tracking Database - The database that is used to store the tracking information.
Polling Interval - The number of milliseconds to wait before repolling the database.
Auto-Select Latest When Polling - When selected, the Workflows pane auto-selects the latest workflow that is executing.
The server name and database name also appear in the status bar.
Using the Monitor
The Workflow Monitor polls the tracking database and automatically shows the status of the workflow and activities in the Workflows and Activities panes and the progress of the workflow in the Workflow View pane. To turn on monitoring, use the Monitor On toolbar button or click Start on the Monitor menu. Use the Settings dialog box to set the polling interval. While you are monitoring a tracking database, it is useful to show the latest workflow that is currently executing. To do this, select the Auto-Select Latest When Polling check box in the Settings dialog box.
When monitoring is turned on, the word “Monitoring” appears in the status bar.
The Workflow Monitor uses the SqlTrackingQuery APIs for querying functionality. The list of workflows and activities are retrieved via SqlTrackingQuery APIs. The searching functionalities use the SqlTrackingQuery APIs.
Multiple Definitions of the Same Workflow Type
The SqlTrackingService persists the workflow definition the first time a new workflow type is used. However, if the definition changes and the type version remains the same, a new record is not persisted in the tracking database. Therefore, the monitor always shows the first definition of a workflow type.
The Workflow Monitor saves settings (SQL Server, database, polling interval) in the workflowmonitor.config file in the following directory: \Documents and Settings\<user>\Local Settings\Application Data\Microsoft Corporation\Windows Workflow Foundation SDK Application Samples\126.96.36.199.
© 2007 Microsoft Corporation. All rights reserved.