AsyncOperation(
            ReachSerializerContext context
            )
        {
            if (context != null)
            {
                switch (context.Action)
                {
                case SerializerAction.endPersistObjectData:
                {
                    EndPersistObjectData();
                    break;
                }

                case SerializerAction.endSerializeReachFixedPage:
                {
                    ReachFixedPageSerializerContext thisContext = context as ReachFixedPageSerializerContext;
                    if (thisContext == null)
                    {
                    }
                    EndSerializeReachFixedPage(thisContext);
                    break;
                }

                default:
                {
                    base.AsyncOperation(context);
                    break;
                }
                }
            }
        }
Exemple #2
0
        AsyncOperation(
            ReachSerializerContext context
            )
        {
            switch (context.Action)
            {
            case SerializerAction.endPersistObjectData:
            {
                EndPersistObjectData();
                break;
            }

            case SerializerAction.endSerializeDocumentPage:
            {
                ReachFixedPageSerializerContext thisContext = context as ReachFixedPageSerializerContext;
                _syncSerializer.EndSerializeDocumentPage(thisContext.TreeWalker);
                break;
            }

            default:
            {
                base.AsyncOperation(context);
                break;
            }
            }
        }
Exemple #3
0
        PersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            DocumentPage    dp         = (DocumentPage)serializableObjectContext.TargetObject;
            ReachTreeWalker treeWalker = _syncSerializer.BeginSerializeDocumentPage(serializableObjectContext);

            ReachSerializerContext context = new ReachFixedPageSerializerContext(this,
                                                                                 serializableObjectContext,
                                                                                 SerializerAction.endSerializeDocumentPage,
                                                                                 false,
                                                                                 treeWalker);

            _xpsOMSerializationManagerAsync.OperationStack.Push(context);

            _syncSerializer.SerializeChild(dp.Visual, serializableObjectContext);
        }
        EndSerializeDocumentPage(
            ReachSerializerContext context
            )
        {
            ReachFixedPageSerializerContext thisContext = context as ReachFixedPageSerializerContext;

            if(thisContext != null)
            {
                ((XpsSerializationManager)SerializationManager).PackagingPolicy.PreCommitCurrentPage();

                //copy hyperlinks into stream
                thisContext.TreeWalker.CommitHyperlinks();

                XmlWriter.WriteEndElement();
                XmlWriter = null;
                //
                // Free the image table in use for this page
                //
                ((XpsSerializationManagerAsync)SerializationManager).ResourcePolicy.CurrentPageImageTable = null;
                //
                // Free the colorContext table in use for this page
                //
                ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageColorContextTable = null;

                ((IXpsSerializationManager)SerializationManager).VisualSerializationService.ReleaseVisualTreeFlattener();

                if( SerializationManager is IXpsSerializationManager)
                {
                    (SerializationManager as IXpsSerializationManager).RegisterPageEnd();
                }
                //
                // Signal to any registered callers that the Page has been serialized
                //
                XpsSerializationProgressChangedEventArgs progressEvent = 
                new XpsSerializationProgressChangedEventArgs(XpsWritingProgressChangeLevel.FixedPageWritingProgress,
                                                             0,
                                                             0,
                                                             null);

                ((IXpsSerializationManager)SerializationManager).OnXPSSerializationProgressChanged(progressEvent);
            }

        }
        PersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            ReachTreeWalker treeWalker;
            bool            needEndVisual = _syncSerializer.BeginPersistObjectData(serializableObjectContext, out treeWalker);

            if (serializableObjectContext.IsComplexValue)
            {
                ReachSerializerContext context = new ReachFixedPageSerializerContext(this,
                                                                                     serializableObjectContext,
                                                                                     SerializerAction.endSerializeReachFixedPage,
                                                                                     needEndVisual,
                                                                                     treeWalker);

                _xpsOMSerializationManagerAsync.OperationStack.Push(context);

                SerializeObjectCore(serializableObjectContext);
            }
            else
            {
                throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_WrongPropertyTypeForFixedPage));
            }
        }
        EndSerializeReachFixedPage(
            ReachFixedPageSerializerContext context
            )
        {
            ReachFixedPageSerializerContext thisContext = context as ReachFixedPageSerializerContext;

            if (thisContext != null)
            {
                if (thisContext.EndVisual)
                {
                    XmlWriter pageWriter = ((XpsSerializationManagerAsync)SerializationManager).
                                           PackagingPolicy.AcquireXmlWriterForPage();

                    XmlWriter resWriter = ((XpsSerializationManagerAsync)SerializationManager).
                                          PackagingPolicy.AcquireXmlWriterForResourceDictionary();


                    Size fixedPageSize            = ((IXpsSerializationManager)SerializationManager).FixedPageSize;
                    VisualTreeFlattener flattener = ((IXpsSerializationManager)SerializationManager).
                                                    VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
                                                                                                          pageWriter,
                                                                                                          fixedPageSize);

                    flattener.EndVisual();
                }


                ((XpsSerializationManagerAsync)SerializationManager).PackagingPolicy.PreCommitCurrentPage();

                //
                // Copy hyperlinks into stream
                //
                thisContext.TreeWalker.CommitHyperlinks();

                XmlWriter.WriteEndElement();
                //
                //Release used resources
                //
                XmlWriter = null;
                //
                // Free the image table in use for this page
                //
                ((XpsSerializationManagerAsync)SerializationManager).ResourcePolicy.CurrentPageImageTable = null;
                //
                // Free the colorContext table in use for this page
                //
                ((XpsSerializationManagerAsync)SerializationManager).ResourcePolicy.CurrentPageColorContextTable = null;

                //
                // Signal to any registered callers that the Page has been serialized
                //
                XpsSerializationProgressChangedEventArgs progressEvent =
                    new XpsSerializationProgressChangedEventArgs(XpsWritingProgressChangeLevel.FixedPageWritingProgress,
                                                                 0,
                                                                 0,
                                                                 null);

                ((IXpsSerializationManager)SerializationManager).OnXPSSerializationProgressChanged(progressEvent);
                ((IXpsSerializationManager)SerializationManager).VisualSerializationService.ReleaseVisualTreeFlattener();
                if (SerializationManager is IXpsSerializationManager)
                {
                    (SerializationManager as IXpsSerializationManager).RegisterPageEnd();
                }
            }
        }
        PersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            if (serializableObjectContext == null)
            {
                throw new ArgumentNullException("serializableObjectContext");
            }

            FixedPage fixedPage = serializableObjectContext.TargetObject as FixedPage;

            if (SerializationManager is IXpsSerializationManager)
            {
                (SerializationManager as IXpsSerializationManager).RegisterPageStart();
            }

            ReachTreeWalker treeWalker = new ReachTreeWalker(this);

            treeWalker.SerializeLinksInFixedPage((FixedPage)serializableObjectContext.TargetObject);

            String xmlnsForType = SerializationManager.GetXmlNSForType(serializableObjectContext.TargetObject.GetType());

            if (xmlnsForType == null)
            {
                XmlWriter.WriteStartElement(serializableObjectContext.Name);
            }
            else
            {
                XmlWriter.WriteStartElement(serializableObjectContext.Name);

                XmlWriter.WriteAttributeString(XpsS0Markup.Xmlns, xmlnsForType);
                XmlWriter.WriteAttributeString(XpsS0Markup.XmlnsX, XpsS0Markup.XmlnsXSchema);

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

                SerializationManager.Language = language;

                XmlWriter.WriteAttributeString(XpsS0Markup.XmlLang, language.ToString());
            }
            {
                Size fixedPageSize = new Size(fixedPage.Width, fixedPage.Height);
                ((IXpsSerializationManager)SerializationManager).FixedPageSize = fixedPageSize;

                //
                // Before we serialize any properties on the FixedPage, we need to
                // serialize the FixedPage as a Visual
                //
                Visual fixedPageAsVisual = serializableObjectContext.TargetObject as Visual;

                bool needEndVisual = false;

                if (fixedPageAsVisual != null)
                {
                    needEndVisual = SerializePageAsVisual(fixedPageAsVisual);
                }

                if (serializableObjectContext.IsComplexValue)
                {
                    ReachSerializerContext context = new ReachFixedPageSerializerContext(this,
                                                                                         serializableObjectContext,
                                                                                         SerializerAction.endSerializeReachFixedPage,
                                                                                         needEndVisual,
                                                                                         treeWalker);

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

                    PrintTicket printTicket = ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket;

                    if (printTicket != null)
                    {
                        PrintTicketSerializer serializer = new PrintTicketSerializer(SerializationManager);
                        serializer.SerializeObject(printTicket);
                        ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket = null;
                    }


                    SerializeObjectCore(serializableObjectContext);
                }
                else
                {
                    throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_WrongPropertyTypeForFixedPage));
                }
            }
        }
        PersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            if (SerializationManager is IXpsSerializationManager)
            {
               (SerializationManager as IXpsSerializationManager).RegisterPageStart();
            }

            //
            // A DocumentPage is persisted as a FixedPage
            //
            DocumentPage dp = (DocumentPage)serializableObjectContext.TargetObject;

            ReachTreeWalker treeWalker = new ReachTreeWalker(this);
            treeWalker.SerializeLinksInDocumentPage(dp);

            XmlWriter.WriteStartElement(XpsS0Markup.FixedPage);

            String xmlnsForType = SerializationManager.GetXmlNSForType(typeof(FixedPage));
            if (xmlnsForType != null)
            {
                XmlWriter.WriteAttributeString(XpsS0Markup.Xmlns, xmlnsForType);
                XmlWriter.WriteAttributeString(XpsS0Markup.XmlnsX, XpsS0Markup.XmlnsXSchema);

                if (SerializationManager.Language != null)
                {
                    XmlWriter.WriteAttributeString(XpsS0Markup.XmlLang, SerializationManager.Language.ToString());
                }
                else
                {
                    XmlWriter.WriteAttributeString(XpsS0Markup.XmlLang, XpsS0Markup.XmlLangValue);
                }
            }

            XpsSerializationPrintTicketRequiredEventArgs e = 
            new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedPagePrintTicket,
                                                                                     0);

            ((IXpsSerializationManager)SerializationManager).OnXPSSerializationPrintTicketRequired(e);

            PrintTicket printTicket = null;
            if(e.Modified)
            {
                printTicket = e.PrintTicket;
            }
            
            Size size = Toolbox.ValidateDocumentSize(dp.Size, printTicket);
            ((IXpsSerializationManager)SerializationManager).FixedPageSize = size;

            //
            //write length and width elements
            //
            WriteAttribute(XmlWriter, XpsS0Markup.PageWidth, size.Width);
            WriteAttribute(XmlWriter, XpsS0Markup.PageHeight, size.Height);

            ReachSerializerContext context = new ReachFixedPageSerializerContext(this,
                                                                                 serializableObjectContext,
                                                                                 SerializerAction.endSerializeDocumentPage,
                                                                                 false,
                                                                                 treeWalker);

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

            //
            // Serialize the data for the PrintTicket
            //
            if (printTicket != null)
            {
                PrintTicketSerializerAsync serializer = new PrintTicketSerializerAsync(SerializationManager);
                serializer.SerializeObject(printTicket);
            }
   
            SerializeChild(dp.Visual, serializableObjectContext);
            
        }