TrackingProfileSerializer.Serialize(TextWriter, TrackingProfile) 方法

定义

通过使用跟踪配置文件 XML 架构定义 (XSD) 将跟踪配置文件序列化为 XML 文档。Serializes the tracking profile into an XML document by using the tracking profile XML Schema definition (XSD).

public:
 void Serialize(System::IO::TextWriter ^ writer, System::Workflow::Runtime::Tracking::TrackingProfile ^ profile);
public void Serialize (System.IO.TextWriter writer, System.Workflow.Runtime.Tracking.TrackingProfile profile);
member this.Serialize : System.IO.TextWriter * System.Workflow.Runtime.Tracking.TrackingProfile -> unit
Public Sub Serialize (writer As TextWriter, profile As TrackingProfile)

参数

writer
TextWriter

有效的 TrackingProfileA valid TrackingProfile.

profile
TrackingProfile

此方法返回时将包含容纳 XML 文档的 TextWriterWhen this method returns, contains a TextWriter that holds the XML document. 参数未经初始化即被传递。The parameter is passed uninitialized.

例外

profilenullprofile is null.

-or- writernullwriter is null.

profile 不是有效的跟踪配置文件。profile is not a valid tracking profile.

示例

下面的代码示例演示如何使用 TrackingProfileSerializer 构造函数创建 TrackingProfileSerializer,以便序列化 TrackingProfileThe following code example demonstrates how you can create a TrackingProfileSerializer using the TrackingProfileSerializer constructor to serialize a TrackingProfile. 代码还使用 Serialize 方法。The code also uses the Serialize method.

此代码示例摘自 Program.cs 文件中的“使用 SQLTrackingService 查询”SDK 示例。This code example is part of the Query using SQLTrackingService SDK sample from the Program.cs file. 有关详细信息,请参阅 使用 SQLTrackingService 查询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);
}
Shared Sub CreateAndInsertTrackingProfile()
    Dim profile As TrackingProfile = New TrackingProfile()

    Dim activityTrack As ActivityTrackPoint = New ActivityTrackPoint()
    Dim activityLocation As ActivityTrackingLocation = New ActivityTrackingLocation(GetType(Activity))
    activityLocation.MatchDerivedTypes = True
    Dim statuses As IEnumerable(Of ActivityExecutionStatus) = CType(System.Enum.GetValues(GetType(ActivityExecutionStatus)), IEnumerable(Of ActivityExecutionStatus))
    For Each status As ActivityExecutionStatus In statuses
        activityLocation.ExecutionStatusEvents.Add(status)
    Next

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

    Dim workflowTrack As WorkflowTrackPoint = New WorkflowTrackPoint()
    Dim workflowLocation As WorkflowTrackingLocation = New WorkflowTrackingLocation()
    Dim eventStatuses As IEnumerable(Of TrackingWorkflowEvent) = CType(System.Enum.GetValues(GetType(TrackingWorkflowEvent)), IEnumerable(Of TrackingWorkflowEvent))
    For Each status As TrackingWorkflowEvent In eventStatuses
        workflowLocation.Events.Add(status)
    Next

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

    Dim serializer As TrackingProfileSerializer = New TrackingProfileSerializer()
    Dim writer As StringWriter = New StringWriter(New StringBuilder(), CultureInfo.InvariantCulture)
    serializer.Serialize(writer, profile)
    Dim trackingProfile As String = writer.ToString()
    InsertTrackingProfile(trackingProfile)
End Sub

注解

序列化是指依据有效的 TrackingProfile 创建格式良好的 XML 文档的过程。Serialization refers to the process of creating a well-formed XML document from a valid TrackingProfile. Serialize 使用跟踪配置文件 Schema 来序列化跟踪配置文件。Serialize uses the tracking profile Schema to serialize the tracking profile. profile 必须是包含至少一个有效跟踪点的有效 TrackingProfileprofile must be a valid TrackingProfile that contains at least one valid track point. 跟踪配置文件验证是在序列化过程中执行的,并且,如果跟踪配置文件无效,则会引发 ArgumentExceptionValidation 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.

适用于