Esempio n. 1
0
        EndPersistObjectData(bool needEndVisual, ReachTreeWalker treeWalker)
        {
            if (needEndVisual)
            {
                XmlWriter pageWriter = SerializationManager.
                                       PackagingPolicy.AcquireXmlWriterForPage();

                XmlWriter resWriter = SerializationManager.
                                      PackagingPolicy.AcquireXmlWriterForResourceDictionary();

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

                flattener.EndVisual();
            }

            SerializationManager.PackagingPolicy.PreCommitCurrentPage();

            //
            // Copy hyperlinks into stream
            //
            treeWalker.CommitHyperlinks();

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

            _xpsOMSerializationManager.VisualSerializationService.ReleaseVisualTreeFlattener();

            _xpsOMSerializationManager.RegisterPageEnd();

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

            _xpsOMSerializationManager.OnXPSSerializationProgressChanged(progressEvent);
        }
Esempio n. 2
0
        EndSerializeDocumentPage(
            ReachTreeWalker treeWalker
            )
        {
            _xpsOMSerializationManager.PackagingPolicy.PreCommitCurrentPage();

            //copy hyperlinks into stream
            treeWalker.CommitHyperlinks();

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

            IXpsSerializationManager xpsSerializationManager = ((IXpsSerializationManager)SerializationManager);

            xpsSerializationManager.VisualSerializationService.ReleaseVisualTreeFlattener();

            xpsSerializationManager.RegisterPageEnd();

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

            xpsSerializationManager.OnXPSSerializationProgressChanged(progressEvent);
        }
        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);

            //
            // Serialize the data for the PrintTicket
            //
            if (printTicket != null)
            {
                PrintTicketSerializer serializer = new PrintTicketSerializer(SerializationManager);
                serializer.SerializeObject(printTicket);
            }

            SerializeChild(dp.Visual, serializableObjectContext);

            ((XpsSerializationManager)SerializationManager).PackagingPolicy.PreCommitCurrentPage();

            //copy hyperlinks into stream
            treeWalker.CommitHyperlinks();

            XmlWriter.WriteEndElement();
            XmlWriter = null;
            //
            // Free the image table in use for this page
            //
            ((XpsSerializationManager)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
            )
        {
            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSerializationBegin);

            if (serializableObjectContext == null)
            {
                throw new ArgumentNullException("serializableObjectContext");
            }

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

            FixedPage fixedPage = serializableObjectContext.TargetObject as FixedPage;

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

                if (needEndVisual)
                {
                    XmlWriter pageWriter = ((XpsSerializationManager)SerializationManager).
                                           PackagingPolicy.AcquireXmlWriterForPage();

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


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

                    flattener.EndVisual();
                }
            }

            ((XpsSerializationManager)SerializationManager).PackagingPolicy.PreCommitCurrentPage();

            //
            // Copy hyperlinks into stream
            //
            treeWalker.CommitHyperlinks();

            XmlWriter.WriteEndElement();
            //
            //Release used resources
            //
            XmlWriter = null;
            //
            // Free the image table in use for this page
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageImageTable = null;
            //
            // Free the colorContext table in use for this page
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageColorContextTable = null;
            //
            // Free the resourceDictionary table in use for this page
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageResourceDictionaryTable = 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);

            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSerializationEnd);
        }