locked
WF4 TrackData? RRS feed

  • Question

  • What is the WF4 equivalent to the 3.5 TrackData method?
    Wednesday, March 9, 2011 10:14 PM

Answers

  • Hi,

    The equivalent tracking method to WF3/3.4 TrackData method is: Track(). here is a example:

        public sealed class MyTrackingActivity : CodeActivity {
            protected override void Execute(CodeActivityContext context) {
                CustomTrackingRecord myRecord = new CustomTrackingRecord("customTrackingRecordName");
                myRecord.Data.Add("name""andrew");
                myRecord.Data.Add("gender""male");
                context.Track(myRecord);
            } 
        }

    To enable custom tracking, we can create a Tracking Participant and add it to host instance. sample code:

    public class MyTrackingParticipant:TrackingParticipant {
            protected override void Track(TrackingRecord record, TimeSpan timeout) {
                Console.WriteLine("-------------Tracking Started------------------");
                //tracking workflow instance
                WorkflowInstanceRecord wfInstanceRecord = record as WorkflowInstanceRecord;
                if (wfInstanceRecord != null) {
                    Console.WriteLine("Workflow:" + wfInstanceRecord.InstanceId + " is " + wfInstanceRecord.State);
                }

                //tracking activity state
                ActivityStateRecord activityStateRecord = record as ActivityStateRecord;
                if (activityStateRecord != null) {
                    Console.WriteLine("Activity Name:" + activityStateRecord.Activity.Name);
                    Console.WriteLine("Acrivity State:"+activityStateRecord.State);
                }

                //tracking custom record
                CustomTrackingRecord customTrackingRecord = record as CustomTrackingRecord;
                if ((customTrackingRecord != null) && (customTrackingRecord.Data.Count > 0)) {
                    foreach (string data in customTrackingRecord.Data.Keys) {
                        Console.WriteLine(data+":"+customTrackingRecord.Data[data]);
                    }
                }
                Console.WriteLine("-----------------Tracking End------------------");
            }
        }
            private static MyTrackingParticipant SetupMyTrackingParticipant2() {
                TrackingProfile myTrackingProfile = new TrackingProfile();
                myTrackingProfile.Queries.Add(new WorkflowInstanceQuery {
                    States = { "*" }
                });

                MyTrackingParticipant2 myTrackingParticipant2 = new MyTrackingParticipant2();
                myTrackingParticipant2.TrackingProfile = myTrackingProfile;
                return myTrackingParticipant2;
            }

    Add custom tracking participant to host instance:

      wfApp.Extensions.Add(SetupMyTrackingParticipant());
    wfApp is a instance of WorkflowApplication.

    Hope this helps
    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Monday, March 14, 2011 3:24 AM

All replies

  • TrackData is supported in 4.0, why do you need another method? or I misunderstand your question?
    Thursday, March 10, 2011 3:51 AM
  • Ok.. I am not finding it. Would it be the Track() method on the CodeActivityContext object?
    Friday, March 11, 2011 5:56 PM
  • sorry, not sure if I understand what you want, but here is some information.

    1. you can still use TrackData in .Net 4.0, see here: http://msdn.microsoft.com/en-us/library/ms606504(v=VS.100).aspx

    2. if you want to do tracking in .Net 4.0, here is the framework with samples by using Track:http://msdn.microsoft.com/en-us/library/ee513992.aspx

    3. if you want to do tracking in .Net3.0/3.5, here is a sample by using TrackData: http://www.codeproject.com/KB/WF/WWF__Tracking_Service.aspx

    hope that helps

     

     

    Sunday, March 13, 2011 8:15 AM
  • Hi,

    The equivalent tracking method to WF3/3.4 TrackData method is: Track(). here is a example:

        public sealed class MyTrackingActivity : CodeActivity {
            protected override void Execute(CodeActivityContext context) {
                CustomTrackingRecord myRecord = new CustomTrackingRecord("customTrackingRecordName");
                myRecord.Data.Add("name""andrew");
                myRecord.Data.Add("gender""male");
                context.Track(myRecord);
            } 
        }

    To enable custom tracking, we can create a Tracking Participant and add it to host instance. sample code:

    public class MyTrackingParticipant:TrackingParticipant {
            protected override void Track(TrackingRecord record, TimeSpan timeout) {
                Console.WriteLine("-------------Tracking Started------------------");
                //tracking workflow instance
                WorkflowInstanceRecord wfInstanceRecord = record as WorkflowInstanceRecord;
                if (wfInstanceRecord != null) {
                    Console.WriteLine("Workflow:" + wfInstanceRecord.InstanceId + " is " + wfInstanceRecord.State);
                }

                //tracking activity state
                ActivityStateRecord activityStateRecord = record as ActivityStateRecord;
                if (activityStateRecord != null) {
                    Console.WriteLine("Activity Name:" + activityStateRecord.Activity.Name);
                    Console.WriteLine("Acrivity State:"+activityStateRecord.State);
                }

                //tracking custom record
                CustomTrackingRecord customTrackingRecord = record as CustomTrackingRecord;
                if ((customTrackingRecord != null) && (customTrackingRecord.Data.Count > 0)) {
                    foreach (string data in customTrackingRecord.Data.Keys) {
                        Console.WriteLine(data+":"+customTrackingRecord.Data[data]);
                    }
                }
                Console.WriteLine("-----------------Tracking End------------------");
            }
        }
            private static MyTrackingParticipant SetupMyTrackingParticipant2() {
                TrackingProfile myTrackingProfile = new TrackingProfile();
                myTrackingProfile.Queries.Add(new WorkflowInstanceQuery {
                    States = { "*" }
                });

                MyTrackingParticipant2 myTrackingParticipant2 = new MyTrackingParticipant2();
                myTrackingParticipant2.TrackingProfile = myTrackingProfile;
                return myTrackingParticipant2;
            }

    Add custom tracking participant to host instance:

      wfApp.Extensions.Add(SetupMyTrackingParticipant());
    wfApp is a instance of WorkflowApplication.

    Hope this helps
    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Monday, March 14, 2011 3:24 AM