ReachDocumentSequenceSerializerAsync.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Print / Reach / Serialization / manager / ReachDocumentSequenceSerializerAsync.cs / 1 / ReachDocumentSequenceSerializerAsync.cs

                            /*++ 

    Copyright (C) 2004- 2005 Microsoft Corporation
    All rights reserved.
 
    Module Name:
        ReachDocumentSequenceSerializerAsync.cs 
 
    Abstract:
 
    Author:
        [....] ([....]) 25-May-2005

    Revision History: 
--*/
 
using System; 
using System.Collections;
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
{ 
    ///  
    ///
    ///  
    internal class DocumentSequenceSerializerAsync :
                   ReachSerializerAsync
    {
        ///  
        ///
        ///  
        public 
        DocumentSequenceSerializerAsync(
            PackageSerializationManager   manager 
            ):
        base(manager)
        {
 
        }
 
        public 
        override
        void 
        AsyncOperation(
            ReachSerializerContext context
            )
        { 
            if(context == null)
            { 
 
            }
 
            switch (context.Action)
            {
                case SerializerAction.endPersistObjectData:
                { 
                    EndPersistObjectData();
                    break; 
                } 

                default: 
                {
                    base.AsyncOperation(context);
                    break;
                } 
            }
        } 
 
        /// 
        /// 
        /// 
        internal
        override
        void 
        PersistObjectData(
            SerializableObjectContext   serializableObjectContext 
            ) 
        {
            String xmlnsForType = SerializationManager.GetXmlNSForType(typeof(FixedDocumentSequence)); 

            if( SerializationManager is XpsSerializationManager)
            {
               (SerializationManager as XpsSerializationManager).RegisterDocumentSequenceStart(); 
            }
 
            if(xmlnsForType == null) 
            {
                XmlWriter.WriteStartElement(serializableObjectContext.Name); 
            }
            else
            {
                XmlWriter.WriteStartElement(serializableObjectContext.Name, 
                                            xmlnsForType);
            } 
 
            {
                ReachSerializerContext context = new ReachSerializerContext(this, 
                                                                            SerializerAction.endPersistObjectData);

                ((XpsSerializationManagerAsync)SerializationManager).OperationStack.Push(context);
 
                if(serializableObjectContext.IsComplexValue)
                { 
                    XpsSerializationPrintTicketRequiredEventArgs e = 
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,
                                                                     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 
                {

                }
            } 
        }
 
        internal 
        override
        void 
        EndPersistObjectData(
            )
        {
            XmlWriter.WriteEndElement(); 
            XmlWriter = null;
 
            // 
            // Signal to any registered callers that the Sequence has been serialized
            // 
            XpsSerializationProgressChangedEventArgs progressEvent =
            new XpsSerializationProgressChangedEventArgs(XpsWritingProgressChangeLevel.FixedDocumentSequenceWritingProgress,
                                                         0,
                                                         0, 
                                                         null);
 
            if( SerializationManager is XpsSerializationManager) 
            {
               (SerializationManager as XpsSerializationManager).RegisterDocumentSequenceEnd(); 
            }
            ((XpsSerializationManager)SerializationManager).OnXPSSerializationProgressChanged(progressEvent);
        }
 

        ///  
        /// 
        /// 
        public 
        override
        XmlWriter
        XmlWriter
        { 
            get
            { 
                if(base.XmlWriter == null) 
                {
                    base.XmlWriter = SerializationManager.AcquireXmlWriter(typeof(FixedDocumentSequence)); 
                }

                return base.XmlWriter;
            } 

            set 
            { 
                base.XmlWriter = null;
                SerializationManager.ReleaseXmlWriter(typeof(FixedDocumentSequence)); 
            }
        }

        ///  
        ///
        ///  
        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);
            }
        } 

        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;
        }
    }; 
}
 
 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK