Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Print / Reach / Serialization / manager / ReachFixedDocumentSerializerAsync.cs / 1 / ReachFixedDocumentSerializerAsync.cs
/*++ Copyright (C) 2004- 2005 Microsoft Corporation All rights reserved. Module Name: ReachFixedDocumentSerializerAsync.cs Abstract: This file contains the definition of a class that defines the common functionality required to serialize a FixedDocument Author: [....] ([....]) 25-May-2005 Revision History: --*/ using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.Diagnostics; using System.Reflection; using System.Xml; using System.IO; using System.Security; using System.Security.Permissions; using System.ComponentModel.Design.Serialization; using System.Windows.Xps.Packaging; using System.Windows.Documents; using System.Windows.Media; using System.Windows.Markup; namespace System.Windows.Xps.Serialization { ////// Class defining common functionality required to /// serialize a FixedDocument. /// internal class FixedDocumentSerializerAsync : ReachSerializerAsync { #region Constructor ////// Constructor for class FixedDocumentSerializer /// /// /// The serialization manager, the services of which are /// used later in the serialization process of the type. /// public FixedDocumentSerializerAsync( PackageSerializationManager manager ): base(manager) { } #endregion Constructor #region Public Methods public override void AsyncOperation( ReachSerializerContext context ) { if(context == null) { } switch (context.Action) { case SerializerAction.endPersistObjectData: { EndPersistObjectData(); break; } default: { base.AsyncOperation(context); break; } } } ////// The main method that is called to serialize a FixedDocument. /// /// /// Instance of object to be serialized. /// public override void SerializeObject( Object serializedObject ) { // // Create the ImageTable required by the Type Converters // The Image table at this time is shared / document // ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageCrcTable = new Dictionary(); ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageUriHashTable = new Dictionary (); // // Create the ColorContextTable required by the Type Converters // The Image table at this time is shared / document // ((XpsSerializationManagerAsync)SerializationManager).ResourcePolicy.ColorContextTable = new Dictionary (); base.SerializeObject(serializedObject); } #endregion Public Methods #region Internal Methods /// /// The main method that is called to serialize the FixedDocument /// and that is usually called from within the serialization manager /// when a node in the graph of objects is at a turn where it should /// be serialized. /// /// /// The context of the property being serialized at this time and /// it points internally to the object encapsulated by that node. /// internal override void SerializeObject( SerializablePropertyContext serializedProperty ) { // // Create the ImageTable required by the Type Converters // The Image table at this time is shared / document // ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageCrcTable = new Dictionary(); ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageUriHashTable = new Dictionary (); // // Create the ColorContextTable required by the Type Converters // The Image table at this time is shared / document // ((XpsSerializationManagerAsync)SerializationManager).ResourcePolicy.ColorContextTable = new Dictionary (); base.SerializeObject(serializedProperty); } /// /// The method is called once the object data is discovered at that /// point of the serizlization process. /// /// /// The context of the object to be serialized at this time. /// internal override void PersistObjectData( SerializableObjectContext serializableObjectContext ) { if(serializableObjectContext == null) { throw new ArgumentNullException("serializableObjectContext"); } if( SerializationManager is XpsSerializationManager) { (SerializationManager as XpsSerializationManager).RegisterDocumentStart(); } String xmlnsForType = SerializationManager.GetXmlNSForType(typeof(FixedDocument)); if(xmlnsForType == null) { XmlWriter.WriteStartElement(serializableObjectContext.Name); } else { XmlWriter.WriteStartElement(serializableObjectContext.Name, xmlnsForType); } { if(serializableObjectContext.IsComplexValue) { ReachSerializerContext context = new ReachSerializerContext(this, SerializerAction.endPersistObjectData); ((XpsSerializationManagerAsync)SerializationManager).OperationStack.Push(context); XpsSerializationPrintTicketRequiredEventArgs e = new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentPrintTicket, 0); ((XpsSerializationManagerAsync)SerializationManager).OnXPSSerializationPrintTicketRequired(e); // // Serialize the data for the PrintTicket // if(e.Modified) { if(e.PrintTicket != null) { PrintTicketSerializerAsync serializer = new PrintTicketSerializerAsync(SerializationManager); serializer.SerializeObject(e.PrintTicket); } } SerializeObjectCore(serializableObjectContext); } else { throw new XpsSerializationException(ReachSR.Get(ReachSRID.ReachSerialization_WrongPropertyTypeForFixedDocument)); } } } internal override void EndPersistObjectData( ) { // // Clear off the table from the packaging policy // ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageCrcTable = null; ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageUriHashTable = null; XmlWriter.WriteEndElement(); XmlWriter = null; // // Signal to any registered callers that the Document has been serialized // XpsSerializationProgressChangedEventArgs progressEvent = new XpsSerializationProgressChangedEventArgs(XpsWritingProgressChangeLevel.FixedDocumentWritingProgress, 0, 0, null); ((XpsSerializationManager)SerializationManager).OnXPSSerializationProgressChanged(progressEvent); if( SerializationManager is XpsSerializationManager) { (SerializationManager as XpsSerializationManager).RegisterDocumentEnd(); } } ////// This method is the one that writed out the attribute within /// the xml stream when serializing simple properties. /// /// /// The property that is to be serialized as an attribute at this time. /// internal override void WriteSerializedAttribute( SerializablePropertyContext serializablePropertyContext ) { if(serializablePropertyContext == null) { throw new ArgumentNullException("serializablePropertyContext"); } String attributeValue = String.Empty; attributeValue = GetValueOfAttributeAsString(serializablePropertyContext); if ( (attributeValue != null) && (attributeValue.Length > 0) ) { // // Emit name="value" attribute // XmlWriter.WriteAttributeString(serializablePropertyContext.Name, attributeValue); } } ////// Converts the Value of the Attribute to a String by calling into /// the appropriate type converters. /// /// /// The property that is to be serialized as an attribute at this time. /// internal String GetValueOfAttributeAsString( SerializablePropertyContext serializablePropertyContext ) { if(serializablePropertyContext == null) { throw new ArgumentNullException("serializablePropertyContext"); } String valueAsString = null; Object targetObjectContainingProperty = serializablePropertyContext.TargetObject; Object propertyValue = serializablePropertyContext.Value; if(propertyValue != null) { TypeConverter typeConverter = serializablePropertyContext.TypeConverter; valueAsString = typeConverter.ConvertToInvariantString(new XpsTokenContext(SerializationManager, serializablePropertyContext), propertyValue); if (typeof(Type).IsInstanceOfType(propertyValue)) { int index = valueAsString.LastIndexOf('.'); if (index > 0) { valueAsString = valueAsString.Substring(index + 1); } valueAsString = XpsSerializationManager.TypeOfString + valueAsString + "}"; } } else { valueAsString = XpsSerializationManager.NullString; } return valueAsString; } #endregion Internal Methods #region Public Properties ////// Queries / Set the XmlWriter for a FixedDocument /// public override XmlWriter XmlWriter { get { if(base.XmlWriter == null) { base.XmlWriter = SerializationManager.AcquireXmlWriter(typeof(FixedDocument)); } return base.XmlWriter; } set { base.XmlWriter = null; SerializationManager.ReleaseXmlWriter(typeof(FixedDocument)); } } #endregion Public Properties }; } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ArrayConverter.cs
- XmlCodeExporter.cs
- XmlSchemaExternal.cs
- ContentElement.cs
- PngBitmapDecoder.cs
- TreeNode.cs
- ClientBuildManagerCallback.cs
- PeerNodeTraceRecord.cs
- XsdBuilder.cs
- TableAdapterManagerGenerator.cs
- AuthenticationModulesSection.cs
- PriorityChain.cs
- InvalidOleVariantTypeException.cs
- DeviceSpecific.cs
- UserControlCodeDomTreeGenerator.cs
- XmlSchemaValidator.cs
- Query.cs
- FlowDocument.cs
- CornerRadius.cs
- DefaultValueTypeConverter.cs
- StateRuntime.cs
- WindowsGraphicsWrapper.cs
- ManipulationDevice.cs
- InternalsVisibleToAttribute.cs
- BaseTreeIterator.cs
- ProxyHelper.cs
- _DigestClient.cs
- StatusBarPanelClickEvent.cs
- BamlResourceSerializer.cs
- InputLanguageEventArgs.cs
- TextBoxView.cs
- EntityDataSourceDesigner.cs
- VisualProxy.cs
- SqlUserDefinedAggregateAttribute.cs
- MaskedTextProvider.cs
- DataGridColumnHeader.cs
- DialogResultConverter.cs
- LookupNode.cs
- NativeMethods.cs
- DynamicValueConverter.cs
- IndexedString.cs
- ADRole.cs
- SqlFormatter.cs
- TemplateBindingExpression.cs
- XmlnsDictionary.cs
- CodeParameterDeclarationExpression.cs
- LineBreak.cs
- XmlSchemaGroup.cs
- ApplicationSecurityManager.cs
- ColumnWidthChangedEvent.cs
- SafeHandle.cs
- DataBindingList.cs
- GZipStream.cs
- SqlUtil.cs
- ImpersonateTokenRef.cs
- XmlSchemaCollection.cs
- EventDescriptor.cs
- RequiredFieldValidator.cs
- DaylightTime.cs
- GridViewUpdatedEventArgs.cs
- EntityStoreSchemaFilterEntry.cs
- UntrustedRecipientException.cs
- MatrixTransform3D.cs
- GeneralTransform3DGroup.cs
- HierarchicalDataBoundControlAdapter.cs
- ItemMap.cs
- OuterGlowBitmapEffect.cs
- SafeEventLogWriteHandle.cs
- RoleService.cs
- StringConcat.cs
- XmlSchemaSubstitutionGroup.cs
- InkCanvasInnerCanvas.cs
- ValidationSummary.cs
- XmlSchemaComplexContent.cs
- _DigestClient.cs
- Encoder.cs
- ManagementPath.cs
- HtmlWindowCollection.cs
- XmlAtomicValue.cs
- Storyboard.cs
- ColorPalette.cs
- DataGridViewSelectedCellCollection.cs
- oledbmetadatacollectionnames.cs
- Partitioner.cs
- ObjectDataSourceSelectingEventArgs.cs
- SecureConversationDriver.cs
- PrintDialog.cs
- RowUpdatedEventArgs.cs
- ImageClickEventArgs.cs
- _NtlmClient.cs
- JulianCalendar.cs
- XAMLParseException.cs
- BadImageFormatException.cs
- QueryOptionExpression.cs
- CompositionTarget.cs
- StateMachine.cs
- EnumMember.cs
- TextPointerBase.cs
- EnumType.cs
- ToolStripDropDown.cs