Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C#

Windows Workflow Foundation: Say Hello to Tracking Service !!

Rate me:
Please Sign up or sign in to vote.
3.19/5 (22 votes)
15 Jan 2009GPL34 min read 95.3K   589   34  
This article explains the intricacies of implementing a custom tracking service in Windows Workflow Foundation.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Workflow.Runtime.Tracking;

namespace CustomTrackingService
{
    /// <summary>
    /// The workflow runtime engine requests a tracking channel from each tracking
    /// service that has provided a TrackingProfile for a workflow instance.This class
    /// implements the TrackingChannel class
    /// </summary>
	class MyTrackingChannel : TrackingChannel
	{
        /// <summary>
        /// When implemented in a derived class, notifies a receiver of data on the
        /// tracking channel that the workflow instance associated with the tracking
        /// channel has either completed or terminated. 
        /// We in our case , don't require it.
        /// </summary>
        protected override void InstanceCompletedOrTerminated()
        {
            
        }

        /// <summary>
        /// The runtime tracking infrastructure calls Send to deliver a TrackingRecord on
        /// the TrackingChannel when it matches a track point in a TrackingProfile.
        /// You can treat the tracking information sent on the TrackingChannel in whatever manner the requirements of your application dictate.
        /// In our case we are using the output window.
        /// </summary>
        /// <param name="record"></param>
        protected override void Send(TrackingRecord record)
        {
            // These are three different types of tracking records available.
            ActivityTrackingRecord atr = record as ActivityTrackingRecord;
            WorkflowTrackingRecord wtr = record as WorkflowTrackingRecord;
            UserTrackingRecord utr = record as UserTrackingRecord;

            Debug.WriteLine(string.Format("Received an tracking record [{0}]" , record.EventDateTime.ToShortDateString()));

            if( atr!= null)
            {
                Debug.WriteLine("\tReceived an activity tracking record");
                Debug.WriteLine(string.Format("\t\tName[{0}],Status[{1}]",atr.QualifiedName,atr.ExecutionStatus));
            }

            else if (wtr!= null)
            {
                Debug.WriteLine("\tReceived an workflow tracking record");
                Debug.WriteLine(string.Format("\t\tName[{0}]",wtr.TrackingWorkflowEvent.ToString()));
            }

            else if (utr!= null)
            {
                Debug.WriteLine("\tReceived an user tracking record");
                Debug.WriteLine(string.Format("\t\tName[{0}]",utr.UserData));
            }

        }


	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
India India
Akshay loves exploring new technologies. C# is his preferred mode of expression.

Comments and Discussions