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

                            /*++ 

    Copyright (C) 2004- 2005 Microsoft Corporation
    All rights reserved.
 
    Module Name:
        ReachDocumentReferenceCollectionSerializerAsync.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 ReachDocumentReferenceCollectionSerializerAsync :
                   ReachSerializerAsync
    {
        ///  
        /// Creates new serializer for a DocumentReferenceCollection
        ///  
        /// serialization manager for this seriaizer 
        public
        ReachDocumentReferenceCollectionSerializerAsync( 
            PackageSerializationManager manager
            ):
        base(manager)
        { 

        } 
 
        public
        override 
        void
        AsyncOperation(
            ReachSerializerContext context
            ) 
        {
            switch (context.Action) 
            { 
                case SerializerAction.endPersistObjectData:
                { 
                    EndPersistObjectData();
                    break;
                }
 
                case SerializerAction.serializeNextDocumentReference:
                { 
                    DocumentReferenceCollectionSerializerContext thisContext = 
                    context as DocumentReferenceCollectionSerializerContext;
 
                    if(thisContext != null)
                    {
                        SerializeNextDocumentReference(thisContext.Enumerator,
                                                       thisContext.ObjectContext); 
                    }
 
                    break; 
                }
 
                default:
                {
                    base.AsyncOperation(context);
                    break; 
                }
            } 
        } 

        ///  
        ///
        /// 
        internal
        override 
        void
        PersistObjectData( 
            SerializableObjectContext   serializableObjectContext 
            )
        { 
            if (serializableObjectContext == null)
            {
                throw new ArgumentNullException("serializableObjectContext");
            } 

            // get DocumentReferenceCollection 
            System.Collections.Generic.IEnumerable enumerableObject = serializableObjectContext.TargetObject as System.Collections.Generic.IEnumerable; 

            if (enumerableObject == null) 
            {
                throw new XpsSerializationException(ReachSR.Get(ReachSRID.MustBeOfType, "serializableObjectContext.TargetObject", typeof(System.Collections.Generic.IEnumerable)));
            }
 
            SerializeDocumentReferences(serializableObjectContext);
        } 
 
        internal
        override 
        void
        EndPersistObjectData(
            )
        { 
            //
            // do nothing in this stage 
            // 
        }
 
        /// 
        /// This is being called to serialize the DocumentReference items
        /// contained within the colleciton
        ///  
        private
        void 
        SerializeDocumentReferences( 
            SerializableObjectContext   serializableObjectContext
            ) 
        {
            IEnumerator enumerator =
            ((System.Collections.Generic.IEnumerable)serializableObjectContext.TargetObject).
            GetEnumerator(); 

            enumerator.Reset(); 
 
            DocumentReferenceCollectionSerializerContext
            context = new DocumentReferenceCollectionSerializerContext(this, 
                                                                       serializableObjectContext,
                                                                       enumerator,
                                                                       SerializerAction.serializeNextDocumentReference);
 
            ((XpsSerializationManagerAsync)SerializationManager).OperationStack.Push(context);
        } 
 
        private
        void 
        SerializeNextDocumentReference(
            IEnumerator                 enumerator,
            SerializableObjectContext   serializableObjectContext
            ) 
        {
            if(enumerator.MoveNext()) 
            { 

                DocumentReferenceCollectionSerializerContext 
                context = new DocumentReferenceCollectionSerializerContext(this,
                                                                           serializableObjectContext,
                                                                           enumerator,
                                                                           SerializerAction.serializeNextDocumentReference); 

 
                ((XpsSerializationManagerAsync)SerializationManager).OperationStack.Push(context); 

                object documentReference = enumerator.Current; 

                SerializeDocumentReference(documentReference);
            }
        } 

 
        ///  
        ///     Called to serialize a single DocumentReference
        ///  
        private
        void
        SerializeDocumentReference(
            object documentReference 
            )
        { 
            ReachSerializer serializer = SerializationManager.GetSerializer(documentReference); 

            if(serializer!=null) 
            {
                serializer.SerializeObject(documentReference);
            }
            else 
            {
                // should we throw if this is not a DocumentReference or just not do anything? 
                throw new XpsSerializationException(ReachSR.Get(ReachSRID.ReachSerialization_NoSerializer)); 
            }
        } 
    };


    internal class DocumentReferenceCollectionSerializerContext : 
                   ReachSerializerContext
    { 
        public 
        DocumentReferenceCollectionSerializerContext(
            ReachSerializerAsync        serializer, 
            SerializableObjectContext   objectContext,
            IEnumerator                 enumerator,
            SerializerAction            action
            ): 
            base(serializer,objectContext,action)
        { 
            this._enumerator = enumerator; 
        }
 

        public
        IEnumerator
        Enumerator 
        {
            get 
            { 
                return _enumerator;
            } 
        }

        private
        IEnumerator     _enumerator; 
    };
} 

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