TrackingProfileSerializer.Serialize(TextWriter, TrackingProfile) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用追蹤設定檔 XML 結構描述定義 (XSD) 將追蹤設定檔序列化為 XML 文件。
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
有效的 TrackingProfile。
- profile
- TrackingProfile
當這個方法傳回時,包含存有 XML 文件的 TextWriter。 參數是以未初始化的狀態傳遞。
例外狀況
profile
不是有效的追蹤設定檔。
範例
下列程式碼範例將示範如何使用 TrackingProfileSerializer 建構函式建立 TrackingProfileSerializer 以序列化 TrackingProfile。 此程式碼也會使用 Serialize 方法。
這個程式碼範例是 Program.cs 檔案中<使用 SQLTrackingService 查詢 SDK>範例的一部分。 如需詳細資訊,請參閱 使用 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 文件的程序。
Serialize 會使用追蹤設定檔 Schema,將追蹤設定檔序列化。
profile
必須是有效的 TrackingProfile,包含至少一個有效的追蹤點。 序列化期間會在追蹤設定檔上執行驗證,如果追蹤設定檔無效,則擲回 ArgumentException。 您可以捕捉此例外狀況,並檢查它的訊息屬性以判斷驗證錯誤的原因。 如果在序列化追蹤設定檔的期間有任何未處理的例外狀況,將終止要求追蹤設定檔的工作流程執行個體。