TrackingProfileSerializer.Serialize Method (TextWriter, TrackingProfile)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Serializes the tracking profile into an XML document by using the tracking profile XML Schema definition (XSD).

Namespace:   System.Workflow.Runtime.Tracking
Assembly:  System.Workflow.Runtime (in System.Workflow.Runtime.dll)

public void Serialize(
	TextWriter writer,
	TrackingProfile profile
)

Parameters

writer
Type: System.IO.TextWriter

A valid TrackingProfile.

profile
Type: System.Workflow.Runtime.Tracking.TrackingProfile

When this method returns, contains a TextWriter that holds the XML document. The parameter is passed uninitialized.

Exception Condition
ArgumentNullException

profile is null.

-or-

writer is null.

ArgumentException

profile is not a valid tracking profile.

Serialization refers to the process of creating a well-formed XML document from a valid TrackingProfile. Serialize uses the tracking profile Schema to serialize the tracking profile. profile must be a valid TrackingProfile that contains at least one valid track point. Validation on the tracking profile is performed during serialization, and, if the tracking profile is not valid, an ArgumentException is thrown. You can catch this exception and examine its message property to determine the cause of the validation error. If there are any unhandled exceptions while serializing the tracking profile, then the workflow instance for which the tracking profile was requested is terminated.

The following code example demonstrates how you can create a TrackingProfileSerializer using the TrackingProfileSerializer constructor to serialize a TrackingProfile. The code also uses the Serialize method.

This code example is part of the Query using SQLTrackingService SDK sample from the Program.cs file. For more information, see Query Using SQLTrackingService.

private static void CreateAndInsertTrackingProfile()
{
    TrackingProfile profile = new TrackingProfile();
    ActivityTrackPoint activityTrack = new ActivityTrackPoint();
    ActivityTrackingLocation activityLocation = new ActivityTrackingLocation(typeof(Activity));
    activityLocation.MatchDerivedTypes = true;
    IEnumerable<ActivityExecutionStatus> statuses = Enum.GetValues(typeof(ActivityExecutionStatus)) as IEnumerable<ActivityExecutionStatus>;
    foreach (ActivityExecutionStatus status in statuses)
    {
        activityLocation.ExecutionStatusEvents.Add(status);
    }

    activityTrack.MatchingLocations.Add(activityLocation);
    profile.ActivityTrackPoints.Add(activityTrack);
    profile.Version = version;

    WorkflowTrackPoint workflowTrack = new WorkflowTrackPoint();
    WorkflowTrackingLocation workflowLocation = new WorkflowTrackingLocation();
    IEnumerable<TrackingWorkflowEvent> eventStatuses = Enum.GetValues(typeof(TrackingWorkflowEvent)) as IEnumerable<TrackingWorkflowEvent>;
    foreach (TrackingWorkflowEvent status in eventStatuses)
    {
        workflowLocation.Events.Add(status);
    }

    workflowTrack.MatchingLocation = workflowLocation;
    profile.WorkflowTrackPoints.Add(workflowTrack);

    TrackingProfileSerializer serializer = new TrackingProfileSerializer();
    StringWriter writer = new StringWriter(new StringBuilder(), CultureInfo.InvariantCulture);
    serializer.Serialize(writer, profile);
    String trackingprofile = writer.ToString();
    InsertTrackingProfile(trackingprofile);
}

.NET Framework
Available since 3.0
Return to top
Show: