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

                            /*++ 

    Copyright (C) 2004- 2005 Microsoft Corporation
    All rights reserved.
 
    Module Name:
        ReachIDocumentPaginatorSerializerAsync.cs 
 
    Abstract:
 
    Author:
        [....] ([....]) 10-June-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 
{ 
    /// 
    /// 
    /// 
    internal class DocumentPaginatorSerializerAsync :
                   ReachSerializerAsync
    { 

        ///  
        /// 
        /// 
        public 
        DocumentPaginatorSerializerAsync(
            PackageSerializationManager manager
            )
            : 
        base(manager)
        { 
 
        }
 
        #region Public Methods

        public
        override 
        void
        AsyncOperation( 
            ReachSerializerContext context 
            )
        { 
            if(context == null)
            {

            } 

            switch (context.Action) 
            { 
                case SerializerAction.endPersistObjectData:
                { 
                    EndPersistObjectData();
                    break;
                }
 
                case SerializerAction.serializeNextDocumentPage:
                { 
                    SerializeNextDocumentPage(context); 
                    break;
                } 

                default:
                {
                    base.AsyncOperation(context); 
                    break;
                } 
            } 
        }
 
        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();
            SerializableObjectContext serializableObjectContext = new SerializableObjectContext(serializedObject, null); 
            PersistObjectData(serializableObjectContext); 

        } 

        #endregion Public Methods

 

        ///  
        /// 
        /// 
        internal 
        override
        void
        PersistObjectData(
            SerializableObjectContext serializableObjectContext 
            )
        { 
            if( SerializationManager is XpsSerializationManager) 
            {
               (SerializationManager as XpsSerializationManager).RegisterDocumentStart(); 
            }
            String xmlnsForType = SerializationManager.GetXmlNSForType(typeof(FixedDocument));
            String nameForType = XpsS0Markup.FixedDocument;
 
            if (xmlnsForType == null)
            { 
                XmlWriter.WriteStartElement(nameForType); 
            }
            else 
            {
                XmlWriter.WriteStartElement(nameForType,
                                            xmlnsForType);
            } 
            {
 
                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);
                    } 
                }

                DocumentPaginator paginator = (DocumentPaginator)serializableObjectContext.TargetObject;
 
                XmlLanguage language = null;
 
                DependencyObject dependencyObject = paginator.Source as DependencyObject; 
                if (dependencyObject != null)
                { 
                    language = (XmlLanguage)dependencyObject.GetValue(FrameworkContentElement.LanguageProperty);
                }

                if (language == null) 
                {
                    //If the language property is null, assign the language to the default 
                    language = XmlLanguage.GetLanguage(XpsS0Markup.XmlLangValue); 
                }
 
                SerializationManager.Language = language;

                int index = 0;
 
                DocumentPaginatorSerializerContext
                collectionContext = new DocumentPaginatorSerializerContext(this, 
                                                                           serializableObjectContext, 
                                                                           paginator,
                                                                           index, 
                                                                           SerializerAction.serializeNextDocumentPage);

                ((XpsSerializationManagerAsync)SerializationManager).OperationStack.Push(collectionContext);
            } 
        }
 
 
        internal
        override 
        void
        EndPersistObjectData(
            )
        { 
            XmlWriter.WriteEndElement();
            XmlWriter = null; 
            // 
            // Clear off the table from the packaging policy
            // 
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageCrcTable = null;

            ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageUriHashTable = null;
 
            //
            // Signal to any registered callers that the Document has been serialized 
            // 
            XpsSerializationProgressChangedEventArgs progressEvent =
            new XpsSerializationProgressChangedEventArgs(XpsWritingProgressChangeLevel.FixedDocumentWritingProgress, 
                                                         0,
                                                         0,
                                                         null);
 
            if( SerializationManager is XpsSerializationManager)
            { 
               (SerializationManager as XpsSerializationManager).RegisterDocumentEnd(); 
            }
            ((XpsSerializationManager)SerializationManager).OnXPSSerializationProgressChanged(progressEvent); 
        }

        /// 
        /// 
        /// 
        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)); 
            } 
        }
 
        private
        void
        SerializeNextDocumentPage(
            ReachSerializerContext  context 
            )
        { 
 
            DocumentPaginatorSerializerContext paginatorContext = context as DocumentPaginatorSerializerContext;
 
            if(paginatorContext != null)
            {
                DocumentPaginator  paginator = paginatorContext.Paginator;
                int                index     = paginatorContext.Index; 

                if(!paginator.IsPageCountValid || 
                   (index < paginator.PageCount)) 
                {
                    index++; 


                    DocumentPaginatorSerializerContext
                    collectionContext = new DocumentPaginatorSerializerContext(this, 
                                                                               paginatorContext.ObjectContext,
                                                                               paginator, 
                                                                               index, 
                                                                               SerializerAction.serializeNextDocumentPage);
                    ((XpsSerializationManagerAsync)SerializationManager).OperationStack.Push(collectionContext); 

                    DocumentPage page = Toolbox.GetPage(paginator, index-1);

                    ReachSerializer serializer = SerializationManager.GetSerializer(page); 
                    if (serializer != null)
                    { 
                        serializer.SerializeObject(page); 
                    }
                } 
            }
            else
            {
 
            }
        } 
    }; 

    internal class DocumentPaginatorSerializerContext : 
                   ReachSerializerContext
    {
        public
        DocumentPaginatorSerializerContext( 
            ReachSerializerAsync        serializer,
            SerializableObjectContext   objectContext, 
            DocumentPaginator           paginator, 
            int                         index,
            SerializerAction            action 
            ):
            base(serializer,objectContext,action)
        {
            this._paginator = paginator; 
            this._index     = index;
        } 
 

        public 
        DocumentPaginator
        Paginator
        {
            get 
            {
                return _paginator; 
            } 
        }
 

        public
        int
        Index 
        {
            get 
            { 
                return _index;
            } 
        }


        private 
        DocumentPaginator   _paginator;
 
        private 
        int                 _index;
    }; 

}

 

// 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