added samples
[windows-sources.git] / sdk / samples / WPFSamples / DocumentSerialize / csharp / serializerwriter / rtfserializerwriter.cs
blob68ed65b64da4d8a39ebfd521938a4ab0f34dff5b
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.IO;
5 using System.Windows.Documents.Serialization;
6 using System.Windows.Documents;
7 using System.Windows.Markup;
8 using System.Windows.Media;
9 using System.Printing;
10 using System.Windows;
11 using System.Xml;
13 namespace SdkSample
15 class RtfSerializerWriter : SerializerWriter
17 public RtfSerializerWriter(Stream stream)
19 _stream = stream;
21 /// <summary>
22 /// Write a single Visual and close package
23 /// </summary>
24 public override void Write(Visual visual)
26 Write(visual, null);
29 /// <summary>
30 /// Write a single Visual and close package
31 /// </summary>
32 public override void Write(Visual visual, PrintTicket printTicket)
34 SerializeObjectTree(visual);
37 /// <summary>
38 /// Asynchronous Write a single Visual and close package
39 /// </summary>
40 public override void WriteAsync(Visual visual)
42 throw new NotSupportedException();
45 /// <summary>
46 /// Asynchronous Write a single Visual and close package
47 /// </summary>
48 public override void WriteAsync(Visual visual, object userState)
50 throw new NotSupportedException();
54 /// <summary>
55 /// Asynchronous Write a single Visual and close package
56 /// </summary>
57 public override void WriteAsync(Visual visual, PrintTicket printTicket)
59 throw new NotSupportedException();
63 /// <summary>
64 /// Asynchronous Write a single Visual and close package
65 /// </summary>
66 public override void WriteAsync(Visual visual, PrintTicket printTicket, object userState)
68 throw new NotSupportedException();
71 /// <summary>
72 /// Write a single DocumentPaginator and close package
73 /// </summary>
74 public override void Write(DocumentPaginator documentPaginator)
76 Write(documentPaginator, null);
79 /// <summary>
80 /// Write a single DocumentPaginator and close package
81 /// </summary>
82 public override void Write(DocumentPaginator documentPaginator, PrintTicket printTicket)
84 SerializeObjectTree(documentPaginator.Source);
87 /// <summary>
88 /// Asynchronous Write a single DocumentPaginator and close package
89 /// </summary>
90 public override void WriteAsync(DocumentPaginator documentPaginator)
92 throw new NotSupportedException();
95 /// <summary>
96 /// Asynchronous Write a single DocumentPaginator and close package
97 /// </summary>
98 public override void WriteAsync(DocumentPaginator documentPaginator, PrintTicket printTicket)
100 throw new NotSupportedException();
103 /// <summary>
104 /// Asynchronous Write a single DocumentPaginator and close package
105 /// </summary>
106 public override void WriteAsync(DocumentPaginator documentPaginator, object userState)
108 throw new NotSupportedException();
111 /// <summary>
112 /// Asynchronous Write a single DocumentPaginator and close package
113 /// </summary>
114 public override void WriteAsync(DocumentPaginator documentPaginator, PrintTicket printTicket, object userState)
116 throw new NotSupportedException();
119 /// <summary>
120 /// Write a single FixedPage and close package
121 /// </summary>
122 public override void Write(FixedPage fixedPage)
124 Write(fixedPage, null);
127 /// <summary>
128 /// Write a single FixedPage and close package
129 /// </summary>
130 public override void Write(FixedPage fixedPage, PrintTicket printTicket)
132 SerializeObjectTree(fixedPage);
135 /// <summary>
136 /// Asynchronous Write a single FixedPage and close package
137 /// </summary>
138 public override void WriteAsync(FixedPage fixedPage)
140 throw new NotSupportedException();
143 /// <summary>
144 /// Asynchronous Write a single FixedPage and close package
145 /// </summary>
146 public override void WriteAsync(FixedPage fixedPage, PrintTicket printTicket)
148 throw new NotSupportedException();
151 /// <summary>
152 /// Asynchronous Write a single FixedPage and close package
153 /// </summary>
154 public override void WriteAsync(FixedPage fixedPage, object userState)
156 throw new NotSupportedException();
159 /// <summary>
160 /// Asynchronous Write a single FixedPage and close package
161 /// </summary>
162 public override void WriteAsync(FixedPage fixedPage, PrintTicket printTicket, object userState)
164 throw new NotSupportedException();
168 /// <summary>
169 /// Write a single FixedDocument and close package
170 /// </summary>
171 public override void Write(FixedDocument fixedDocument)
173 Write(fixedDocument, null);
176 /// <summary>
177 /// Write a single FixedDocument and close package
178 /// </summary>
179 public override void Write(FixedDocument fixedDocument, PrintTicket printTicket)
181 SerializeObjectTree(fixedDocument);
184 /// <summary>
185 /// Asynchronous Write a single FixedDocument and close package
186 /// </summary>
187 public override void WriteAsync(FixedDocument fixedDocument)
189 throw new NotSupportedException();
192 /// <summary>
193 /// Asynchronous Write a single FixedDocument and close package
194 /// </summary>
195 public override void WriteAsync(FixedDocument fixedDocument, PrintTicket printTicket)
197 throw new NotSupportedException();
200 /// <summary>
201 /// Asynchronous Write a single FixedDocument and close package
202 /// </summary>
203 public override void WriteAsync(FixedDocument fixedDocument, object userState)
205 throw new NotSupportedException();
208 /// <summary>
209 /// Asynchronous Write a single FixedDocument and close package
210 /// </summary>
211 public override void WriteAsync(FixedDocument fixedDocument, PrintTicket printTicket, object userState)
213 throw new NotSupportedException();
216 /// <summary>
217 /// Write a single FixedDocumentSequence and close package
218 /// </summary>
219 public override void Write(FixedDocumentSequence fixedDocumentSequence)
221 Write(fixedDocumentSequence, null);
224 /// <summary>
225 /// Write a single FixedDocumentSequence and close package
226 /// </summary>
227 public override void Write(FixedDocumentSequence fixedDocumentSequence, PrintTicket printTicket)
229 SerializeObjectTree(fixedDocumentSequence);
232 /// <summary>
233 /// Asynchronous Write a single FixedDocumentSequence and close package
234 /// </summary>
235 public override void WriteAsync(FixedDocumentSequence fixedDocumentSequence)
237 throw new NotSupportedException();
240 /// <summary>
241 /// Asynchronous Write a single FixedDocumentSequence and close package
242 /// </summary>
243 public override void WriteAsync(FixedDocumentSequence fixedDocumentSequence, PrintTicket printTicket)
245 throw new NotSupportedException();
248 /// <summary>
249 /// Asynchronous Write a single FixedDocumentSequence and close package
250 /// </summary>
251 public override void WriteAsync(FixedDocumentSequence fixedDocumentSequence, object userState)
253 throw new NotSupportedException();
256 /// <summary>
257 /// Asynchronous Write a single FixedDocumentSequence and close package
258 /// </summary>
259 public override void WriteAsync(FixedDocumentSequence fixedDocumentSequence, PrintTicket printTicket, object userState)
261 throw new NotSupportedException();
264 /// <summary>
265 /// Cancel Asynchronous Write
266 /// </summary>
267 public override void CancelAsync()
269 throw new NotSupportedException();
272 /// <summary>
273 /// Create a SerializerWriterCollator to gobble up multiple Visuals
274 /// </summary>
275 public override SerializerWriterCollator CreateVisualsCollator()
277 throw new NotSupportedException();
280 /// <summary>
281 /// Create a SerializerWriterCollator to gobble up multiple Visuals
282 /// </summary>
283 public override SerializerWriterCollator CreateVisualsCollator(PrintTicket documentSequencePT, PrintTicket documentPT)
285 throw new NotSupportedException();
288 /// <summary>
289 /// This event will be invoked if the writer wants a PrintTicker
290 /// </summary>
291 public override event WritingPrintTicketRequiredEventHandler WritingPrintTicketRequired;
293 /// <summary>
294 /// This event will be invoked if the writer progress changes
295 /// </summary>
296 public override event WritingProgressChangedEventHandler WritingProgressChanged;
298 /// <summary>
299 /// This event will be invoked if the writer is done
300 /// </summary>
301 public override event WritingCompletedEventHandler WritingCompleted;
303 /// <summary>
304 /// This event will be invoked if the writer has been cancelled
305 /// </summary>
306 public override event WritingCancelledEventHandler WritingCancelled;
308 private void SerializeObjectTree(object objectTree)
310 TextWriter writer = new StreamWriter(_stream);
314 string fileContent = XamlRtfConverter.ConvertXamlToRtf(
315 XamlWriter.Save(objectTree));
316 writer.Write(fileContent);
318 finally
320 if (writer != null)
321 writer.Close();
326 private Stream _stream;