by Keyvan Nayyeri via Keyvan Nayyeri on 10/20/2006 7:38:57 PM
In this post I talked about SqlTrackingService in Windows Workflow Foundation which helps you to track information about your workflows.
By default Windows Workflow Foundation uses a TrackingProfile object to track your workflows and stores all common and important information for you. But you can define your own TrackingProfile to track custom information about your workflow instances.
Data for default TrackingProfile and custom TrackingProfiles will be stored in TrackingProfile table in database.
In this post I talk about TrackingProfile to show how can you use a custom TrackingProfile to track your workflows.
Generally there are two ways to declare a custom TrackingProfile:
Actually second approach provides an XML file and can be considered as first one. So I discuss about second way and this will cover first one. In order to describe the process I'll define a custom TrackingProfile for the example I had provided in my post about SqlTrackingService to track Create and Start events only.
First step is to create a TrackingProfile object and set its properties. NewTrackingProfile() method in below code does this. It creates a new TrackingProfile, sets its version, adds a WorkflowTrackPoint and an ActivityTrackPoint to it and finally returns it.
public TrackingProfile NewTrackingProfile()
{
// Create new TrackingProfile
TrackingProfile profile = new TrackingProfile();
// Set version for TrackingProfile
profile.Version = new Version("1.0.0.2");
// Create a new WorkflowTrackPoint and
// add appropriate events to it
WorkflowTrackPoint workflowTrackpoint =
new WorkflowTrackPoint();
WorkflowTrackingLocation workflowTrackingLocation =
new WorkflowTrackingLocation();
workflowTrackingLocation.Events.Add
(TrackingWorkflowEvent.Created);
(TrackingWorkflowEvent.Started);
workflowTrackpoint.MatchingLocation =
workflowTrackingLocation;
profile.WorkflowTrackPoints.Add
(workflowTrackpoint);
// Create a new new ActivityTrackPoint and
ActivityTrackPoint activityTrackpoint =
new ActivityTrackPoint();
ActivityTrackingLocation activityTrackingLocation =
new ActivityTrackingLocation(typeof(MyWorkflow.Workflow1));
activityTrackingLocation.MatchDerivedTypes = true;
activityTrackingLocation.ExecutionStatusEvents.Add
(ActivityExecutionStatus.Initialized);
(ActivityExecutionStatus.Closed);
activityTrackpoint.MatchingLocations.Add
(activityTrackingLocation);
profile.ActivityTrackPoints.Add(activityTrackpoint);
return profile;
}
And finally you need to add the XML equivalent of your TrackingProfile to database. There is an UpdateTrackingProfile stored procedure which installs when you run SqlTrackingService scripts. It gets four parameters: FullName of your workflow instance type, Assembly FullName of your workflow instance type, version of your TrackingProfile and XML value of your Tracking profile. Note that you should increment version number for your TrackingProfile to be able to use new TrackingProfile. Default version is "1.0.0.0".
Now I add my TrackingProfile to database in a Button's click event (SampleTrackingProfile is the class which contains above functions):
void btnUpdateProfile_Click(object sender, RoutedEventArgs args)
SampleTrackingProfile sampleTracking =
new SampleTrackingProfile();
TrackingProfile profile =
sampleTracking.NewTrackingProfile();
String serializedProfile =
sampleTracking.SerializeProfile(profile);
Type type = typeof(MyWorkflow.Workflow1);
using (SqlConnection connection = new SqlConnection
("Data Source=KEYVANNAYYERI;Initial Catalog=SqlTrackingServiceSample;Integrated Security=True"))
SqlCommand command =
new SqlCommand("UpdateTrackingProfile", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue
("TypeFullName", type.FullName);
("AssemblyFullName", type.Assembly.FullName);
("Version", profile.Version.ToString());
("TrackingProfileXml", serializedProfile);
connection.Open();
command.ExecuteNonQuery();
MessageBox.Show("Profile Updated");
Now it's time to check this TrackingProfile. Again I use my previous code to track my workflow changes and save them into database and check them with the application I had written. Now I have this result:
Compare it with previous result:
If you put a Breakpoint right after the line which gets your TrackingProfile serialized value:
And monitor serializedProfile variable, will see the XML equivalent of your TrackingProfile object that will be stored into database:
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<TrackingProfile xmlns="http://schemas.microsoft.com/winfx/2006/workflow/trackingprofile" version="1.0.0.2">
<TrackPoints>
<WorkflowTrackPoint>
<MatchingLocation>
<WorkflowTrackingLocation>
<TrackingWorkflowEvents>
<TrackingWorkflowEvent>Created</TrackingWorkflowEvent>
<TrackingWorkflowEvent>Started</TrackingWorkflowEvent>
</TrackingWorkflowEvents>
</WorkflowTrackingLocation>
</MatchingLocation>
</WorkflowTrackPoint>
<ActivityTrackPoint>
<MatchingLocations>
<ActivityTrackingLocation>
<Activity>
<Type>MyWorkflow.Workflow1, MyWorkflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</Type>
<MatchDerivedTypes>true</MatchDerivedTypes>
</Activity>
<ExecutionStatusEvents>
<ExecutionStatus>Initialized</ExecutionStatus>
<ExecutionStatus>Closed</ExecutionStatus>
</ExecutionStatusEvents>
</ActivityTrackingLocation>
</MatchingLocations>
</ActivityTrackPoint>
</TrackPoints>
</TrackingProfile>
Original Post: TrackingProfile in Windows Workflow Foundation
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.