ReachDocumentSequenceSerializer.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 / ReachDocumentSequenceSerializer.cs / 1 / ReachDocumentSequenceSerializer.cs

                            /*++ 

    Copyright (C) 2004- 2005 Microsoft Corporation
    All rights reserved.
 
    Module Name:
        ReachDocumentSequenceSerializer.cs 
 
    Abstract:
 
    Author:
        [....] ([....]) January 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 DocumentSequenceSerializer :
                   ReachSerializer
    {
        ///  
        ///
        ///  
        public 
        DocumentSequenceSerializer(
            PackageSerializationManager   manager 
            ):
        base(manager)
        {
 
        }
 
        ///  
        ///
        ///  
        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); 
            }
 
            { 
                if(serializableObjectContext.IsComplexValue)
                { 
                    //
                    // Pick the data for the PrintTicket if it existed
                    //
                    XpsSerializationPrintTicketRequiredEventArgs e = 
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,
                                                                     0); 
 
                    ((XpsSerializationManager)SerializationManager).OnXPSSerializationPrintTicketRequired(e);
 
                    //
                    // Serialize the data for the PrintTicket
                    //
                    if(e.Modified) 
                    {
                        if(e.PrintTicket != null) 
                        { 
                            PrintTicketSerializer serializer = new PrintTicketSerializer(SerializationManager);
                            serializer.SerializeObject(e.PrintTicket); 
                        }
                    }

                    SerializeObjectCore(serializableObjectContext); 
                }
                else 
                { 

                } 
            }

            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