TrackingProfileSerializer.Serialize(TextWriter, TrackingProfile) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Membuat serialisasi profil pelacakan ke dalam dokumen XML dengan menggunakan definisi Skema XML profil pelacakan (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)
Parameter
- writer
- TextWriter
- profile
- TrackingProfile
Ketika metode ini kembali, berisi yang TextWriter menyimpan dokumen XML. Parameter diteruskan tanpa diinisialisasi.
Pengecualian
profile
bukan profil pelacakan yang valid.
Contoh
Contoh kode berikut menunjukkan bagaimana Anda dapat membuat TrackingProfileSerializer menggunakan TrackingProfileSerializer konstruktor untuk membuat TrackingProfileserialisasi . Kode ini juga menggunakan Serialize metode .
Contoh kode ini adalah bagian dari Kueri menggunakan sampel SQLTrackingService SDK dari file Program.cs. Untuk informasi selengkapnya, lihat Kueri Menggunakan 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
Keterangan
Serialisasi mengacu pada proses pembuatan dokumen XML yang terbentuk dengan baik dari yang valid TrackingProfile.
Serialize menggunakan profil Schema pelacakan untuk membuat serialisasi profil pelacakan.
profile
harus valid TrackingProfile yang berisi setidaknya satu titik trek yang valid. Validasi pada profil pelacakan dilakukan selama serialisasi, dan, jika profil pelacakan tidak valid, akan ArgumentException dilemparkan. Anda dapat menangkap pengecualian ini dan memeriksa properti pesannya untuk menentukan penyebab kesalahan validasi. Jika ada pengecualian yang tidak tertangani saat membuat serial profil pelacakan, maka instans alur kerja tempat profil pelacakan diminta dihentikan.