BeginSerializeObject(
            Object serializedObject
            )
        {
            FixedDocumentSequence fds = serializedObject as FixedDocumentSequence;

            if (!NgcSerializationManager.IsPrintTicketEventHandlerEnabled)
            {
                //NgcSerializationManager.FdsPrintTicket = fds.PrintTicket as PrintTicket;
            }
            else
            {
                XpsSerializationPrintTicketRequiredEventArgs e =
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,
                                                                     0);
                NgcSerializationManager.OnNGCSerializationPrintTicketRequired(e);
            }

            NgcSerializationManager.StartDocument(fds, false);

            NGCSerializerContext context = new NGCSerializerContext(this,
                                                                    null,
                                                                    SerializerAction.endPersistObjectData);

            NgcSerializationManager.OperationStack.Push(context);


            ReachSerializer serializer = NgcSerializationManager.GetSerializer(fds.References);

            serializer.SerializeObject(fds.References);
        }
Пример #2
0
        StartPage()
        {
            bool bManulStartDoc = false;

            if (_startDocCnt == 0)
            {
                StartDocument(null, true);
                bManulStartDoc = true;
            }

            if (!_isStartPage)
            {
                if (_isPrintTicketMerged == false)
                {
                    XpsSerializationPrintTicketRequiredEventArgs e =
                        new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedPagePrintTicket,
                                                                         0);
                    OnNGCSerializationPrintTicketRequired(e);
                }

                _device.StartPage(_printTicketManager.ConsumeActivePrintTicket(true));
                _isStartPage = true;
            }

            return(bManulStartDoc);
        }
        SerializePage(
            SerializableObjectContext serializableObjectContext
            )
        {
            FixedPage fixedPage = Toolbox.GetPageRoot(serializableObjectContext.TargetObject);

            if (fixedPage != null)
            {
                ReachSerializer serializer = SerializationManager.GetSerializer(fixedPage);

                if (serializer != null)
                {
                    NgcSerializationManagerAsync manager = SerializationManager as NgcSerializationManagerAsync;

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

                    Toolbox.Layout(fixedPage, manager.GetActivePrintTicket());

                    serializer.SerializeObject(fixedPage);
                }
                else
                {
                    throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoSerializer));
                }
            }
        }
        BeginPersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            if (serializableObjectContext == null)
            {
                throw new ArgumentNullException(nameof(serializableObjectContext));
            }

            _xpsOMSerializationManager.RegisterDocumentStart();

            if (serializableObjectContext.IsComplexValue)
            {
                XpsSerializationPrintTicketRequiredEventArgs e =
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentPrintTicket,
                                                                     0);

                _xpsOMSerializationManager.OnXPSSerializationPrintTicketRequired(e);

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

            _xpsOMSerializationManager.StartNewDocument();
        }
        SimulateBeginFixedDocument(
            )
        {
            _xpsOMSerializationManager.RegisterDocumentStart();

            // Build the Image Table

            _xpsOMSerializationManager.ResourcePolicy.ImageCrcTable = new Dictionary <UInt32, Uri>();

            _xpsOMSerializationManager.ResourcePolicy.ImageUriHashTable = new Dictionary <int, Uri>();

            //
            // Build the ColorContext Table
            //
            _xpsOMSerializationManager.ResourcePolicy.ColorContextTable = new Dictionary <int, Uri>();


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

            SimulatePrintTicketRaisingEvent(e);

            _xpsOMSerializationManager.StartNewDocument();


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

            if (SerializationManager is XpsSerializationManager)
            {
                (SerializationManager as XpsSerializationManager).RegisterDocumentStart();
            }

            String xmlnsForType = SerializationManager.GetXmlNSForType(typeof(FixedDocument));

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

            {
                if (serializableObjectContext.IsComplexValue)
                {
                    ReachSerializerContext context = new ReachSerializerContext(this,
                                                                                SerializerAction.endPersistObjectData);

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

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

                    ((IXpsSerializationManager)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);
                        }
                    }

                    SerializeObjectCore(serializableObjectContext);
                }
                else
                {
                    throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_WrongPropertyTypeForFixedDocument));
                }
            }
        }
        StartDocument(
            Object o,
            bool documentPrintTicketRequired
            )
        {
            if (documentPrintTicketRequired)
            {
                XpsSerializationPrintTicketRequiredEventArgs e =
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentPrintTicket,
                                                                     0);
                OnNGCSerializationPrintTicketRequired(e);
            }

            if (_startDocCnt == 0)
            {
                JobName = PrintQueue.CurrentJobSettings.Description;

                if (JobName == null)
                {
                    JobName = NgcSerializerUtil.InferJobName(o);
                }

                _device = new MetroToGdiConverter(PrintQueue);

                _device.StartDocument(_jobName, _printTicketManager.ConsumeActivePrintTicket(true));
            }
            _startDocCnt++;
        }
        SerializePage(
            SerializableObjectContext serializableObjectContext
            )
        {
            FixedPage fixedPage = Toolbox.GetPageRoot(serializableObjectContext.TargetObject);

            if (fixedPage != null)
            {
                ReachSerializer serializer = SerializationManager.GetSerializer(fixedPage);

                if (serializer != null)
                {
                    XpsSerializationPrintTicketRequiredEventArgs e =
                        new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedPagePrintTicket,
                                                                         0);
                    ((IXpsSerializationManager)SerializationManager).OnXPSSerializationPrintTicketRequired(e);

                    PrintTicket printTicket = null;
                    if (e.Modified)
                    {
                        printTicket = e.PrintTicket;
                    }
                    Toolbox.Layout(fixedPage, printTicket);

                    ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket = printTicket;

                    serializer.SerializeObject(fixedPage);
                }
                else
                {
                    throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoSerializer));
                }
            }
        }
Пример #9
0
        OnXPSSerializationPrintTicketRequired(
            object operationState
            )
        {
            XpsSerializationPrintTicketRequiredEventArgs e = operationState as XpsSerializationPrintTicketRequiredEventArgs;

            if (XpsSerializationPrintTicketRequired != null)
            {
                e.Modified = true;

                XpsSerializationPrintTicketRequired(this, e);
            }
        }
Пример #10
0
        ForwardUserPrintTicket(
            Object sender,
            XpsSerializationPrintTicketRequiredEventArgs e
            )
        {
            Boolean mustCallXpsDriverDocEvent = true;

            _printTicket      = e.PrintTicket;
            _printTicketLevel = e.PrintTicketLevel;

            switch (_printTicketLevel)
            {
            case PrintTicketLevel.FixedDocumentSequencePrintTicket:
            {
                _currentCount  = _currentDocSequence;
                _documentEvent = XpsDocumentEventType.AddFixedDocumentSequencePrintTicketPre;
                break;
            }

            case PrintTicketLevel.FixedDocumentPrintTicket:
            {
                _currentCount  = _currentFixedDocument;
                _documentEvent = XpsDocumentEventType.AddFixedDocumentPrintTicketPre;
                break;
            }

            case PrintTicketLevel.FixedPagePrintTicket:
            {
                _currentCount  = _currentPage + 1;
                _documentEvent = XpsDocumentEventType.AddFixedPagePrintTicketPre;
                break;
            }

            default:
            {
                mustCallXpsDriverDocEvent = false;
                break;
            }
            }

            if (mustCallXpsDriverDocEvent)
            {
                XpsSerializationXpsDriverDocEventArgs xpsEventArgs = OnXpsDriverDocEvent();

                if (xpsEventArgs.Modified)
                {
                    e.PrintTicket = xpsEventArgs.PrintTicket;
                }
            }
        }
Пример #11
0
        BeginConfirmToXPSStructure(
            bool mode
            )
        {
            //
            // In case we have a FixedPage or a Visual as a root, we have to simulate
            // a containing FixedDocument-FixedPage ... etc.
            //
            if ((_serializedObject.GetType() == typeof(System.Windows.Documents.FixedDocument)) ||
                (typeof(System.Windows.Documents.DocumentPaginator).IsAssignableFrom(_serializedObject.GetType()) &&
                 (_serializedObject.GetType() != typeof(System.Windows.Documents.FixedDocumentSequence))))
            {
                //
                // Build the necessary wrapper for a FixedDocument
                //
                _documentSequenceXmlWriter = SimulateBeginFixedDocumentSequence();
            }
            else if (_serializedObject.GetType() == typeof(System.Windows.Documents.FixedPage))
            {
                //
                // Build the necessary wrapper for a FixedPage
                //
                _documentSequenceXmlWriter = SimulateBeginFixedDocumentSequence();
                _documentXmlWriter         = SimulateBeginFixedDocument();
                XpsSerializationPrintTicketRequiredEventArgs e =
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedPagePrintTicket,
                                                                     0);
                ((IXpsSerializationManager)_serializationManager).OnXPSSerializationPrintTicketRequired(e);
                XpsOMSerializationManager xpsOMSerializationManager = _serializationManager as XpsOMSerializationManager;

                PrintTicket printTicket = null;
                if (e.Modified)
                {
                    printTicket = e.PrintTicket;
                }
                Toolbox.Layout(_serializedObject as FixedPage, printTicket);

                ((IXpsSerializationManager)_serializationManager).FixedPagePrintTicket = printTicket;
            }
            else if (typeof(System.Windows.Media.Visual).IsAssignableFrom(_serializedObject.GetType()))
            {
                _documentSequenceXmlWriter = SimulateBeginFixedDocumentSequence();
                _documentXmlWriter         = SimulateBeginFixedDocument();
                if (!mode)
                {
                    _pageXmlWriter = SimulateBeginFixedPage();
                }
            }
        }
Пример #12
0
        SimulateBeginFixedDocument(
            )
        {
            XmlWriter xmlWriter = null;

            if (_serializationManager is XpsSerializationManager)
            {
                (_serializationManager as XpsSerializationManager).RegisterDocumentStart();
            }
            //
            // Build the Image Table
            //
            _serializationManager.ResourcePolicy.ImageCrcTable = new Dictionary <UInt32, Uri>();

            _serializationManager.ResourcePolicy.ImageUriHashTable = new Dictionary <int, Uri>();

            //
            // Build the ColorContext Table
            //
            _serializationManager.ResourcePolicy.ColorContextTable = new Dictionary <int, Uri>();
            //
            // Get the correct namespace
            //
            String xmlnsForType = _serializationManager.GetXmlNSForType(typeof(FixedDocument));

            //
            // Pick the correct XmlWriter
            //
            xmlWriter = _serializationManager.AcquireXmlWriter(typeof(FixedDocument));
            //
            // Write the start element and the namespace
            //
            if (xmlnsForType == null)
            {
                xmlWriter.WriteStartElement("FixedDocument");
            }
            else
            {
                xmlWriter.WriteStartElement("FixedDocument", xmlnsForType);
            }

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

            SimulatePrintTicketRaisingEvent(e);

            return(xmlWriter);
        }
        BeginPersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            if (_xpsOMSerializationManager != null)
            {
                _xpsOMSerializationManager.RegisterDocumentStart();
                XpsSerializationPrintTicketRequiredEventArgs e =
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentPrintTicket,
                                                                     0);

                _xpsOMSerializationManager.OnXPSSerializationPrintTicketRequired(e);

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

                _xpsOMSerializationManager.StartNewDocument();
            }

            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;

            return(paginator);
        }
        PersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            if (serializableObjectContext.IsComplexValue)
            {
                //SerializeObjectCore(serializableObjectContext);

                FixedPage fixedPage = Toolbox.GetPageRoot(serializableObjectContext.TargetObject);

                if (fixedPage != null)
                {
                    ReachSerializer serializer = SerializationManager.GetSerializer(fixedPage);

                    if (serializer != null)
                    {
                        //Get FixedPage Print Ticket and cache it inside of the SerializationManager
                        //so we can get it inside of
                        XpsSerializationPrintTicketRequiredEventArgs e =
                            new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedPagePrintTicket,
                                                                             0);
                        ((IXpsSerializationManager)SerializationManager).OnXPSSerializationPrintTicketRequired(e);

                        PrintTicket printTicket = null;
                        if (e.Modified)
                        {
                            printTicket = e.PrintTicket;
                        }
                        Toolbox.Layout(fixedPage, printTicket);

                        ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket = printTicket;

                        serializer.SerializeObject(fixedPage);
                    }
                    else
                    {
                        throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoSerializer));
                    }
                }
            }
            else
            {
                throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_WrongPropertyTypeForPageContent));
            }
        }
Пример #15
0
        SerializeObject(
            Object serializedObject
            )
        {
            if (serializedObject == null)
            {
                throw new ArgumentNullException("serializedObject");
            }
            FixedDocumentSequence fds = serializedObject as FixedDocumentSequence;

            if (fds == null)
            {
                throw new ArgumentException(SR.Get(SRID.ReachSerialization_ExpectedFixedDocumentSequence));
            }

            NgcSerializationManager ngcManager = SerializationManager as NgcSerializationManager;

            if (!ngcManager.IsPrintTicketEventHandlerEnabled)
            {
                //ngcManager.FdsPrintTicket = fds.PrintTicket as PrintTicket;
            }
            else
            {
                XpsSerializationPrintTicketRequiredEventArgs printTicketEvent =
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,
                                                                     0);
                ngcManager.OnNGCSerializationPrintTicketRequired(printTicketEvent);
            }

            ngcManager.StartDocument(fds, false);

            ReachSerializer serializer = ngcManager.GetSerializer(fds.References);

            serializer.SerializeObject(fds.References);

            ngcManager.EndDocument();

            XpsSerializationProgressChangedEventArgs e =
                new XpsSerializationProgressChangedEventArgs(XpsWritingProgressChangeLevel.FixedDocumentSequenceWritingProgress,
                                                             0,
                                                             0,
                                                             null);

            ngcManager.OnNGCSerializationProgressChagned(e);
        }
Пример #16
0
        SimulatePrintTicketRaisingEvent(
            XpsSerializationPrintTicketRequiredEventArgs e
            )
        {
            (_serializationManager as IXpsSerializationManager)?.OnXPSSerializationPrintTicketRequired(e);

            //
            // Serialize the data for the PrintTicket
            //
            if (e.Modified)
            {
                if (e.PrintTicket != null)
                {
                    PrintTicketSerializer serializer = new PrintTicketSerializer(_serializationManager);
                    serializer.SerializeObject(e.PrintTicket);
                }
            }
        }
Пример #17
0
        IXpsSerializationManager.OnXPSSerializationPrintTicketRequired(
            object operationState
            )
        {
            XpsSerializationPrintTicketRequiredEventArgs e = operationState as XpsSerializationPrintTicketRequiredEventArgs;

            if (XpsSerializationPrintTicketRequired != null)
            {
                e.Modified = true;

                XpsSerializationPrintTicketRequired(this, e);

                if (XpsSerializationPrintTicketRequiredOnXpsDriverDocEvent != null)
                {
                    XpsSerializationPrintTicketRequiredOnXpsDriverDocEvent(this, e);
                }
            }
        }
Пример #18
0
        SimulateBeginFixedDocumentSequence(
            )
        {
            XmlWriter xmlWriter = null;

            if (_serializationManager is XpsSerializationManager)
            {
                (_serializationManager as XpsSerializationManager).RegisterDocumentSequenceStart();
            }

            //
            // Get the correct namespace
            //
            String xmlnsForType = _serializationManager.GetXmlNSForType(typeof(FixedDocumentSequence));

            //
            // Pick the correct XmlWriter
            //
            xmlWriter = _serializationManager.AcquireXmlWriter(typeof(FixedDocumentSequence));
            //
            // Write the start element and the namespace
            //
            if (xmlnsForType == null)
            {
                xmlWriter.WriteStartElement(XpsS0Markup.FixedDocumentSequence);
            }
            else
            {
                xmlWriter.WriteStartElement(XpsS0Markup.FixedDocumentSequence,
                                            xmlnsForType);
            }
            //
            // Pick the data for the PrintTicket if it existed
            //
            XpsSerializationPrintTicketRequiredEventArgs e =
                new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,
                                                                 0);

            SimulatePrintTicketRaisingEvent(e);

            return(xmlWriter);
        }
Пример #19
0
        OnNGCSerializationPrintTicketRequired(
            object operationState
            )
        {
            XpsSerializationPrintTicketRequiredEventArgs e = operationState as XpsSerializationPrintTicketRequiredEventArgs;

            if (XpsSerializationPrintTicketRequired != null)
            {
                e.Modified = true;

                if (e.PrintTicketLevel == PrintTicketLevel.FixedPagePrintTicket)
                {
                    _isPrintTicketMerged = true;
                }

                XpsSerializationPrintTicketRequired(this, e);

                _printTicketManager.ConstructPrintTicketTree(e);
            }
        }
Пример #20
0
        StartDocument(
            Object o,
            bool documentPrintTicketRequired
            )
        {
            if (documentPrintTicketRequired)
            {
                XpsSerializationPrintTicketRequiredEventArgs e =
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentPrintTicket,
                                                                     0);
                OnNGCSerializationPrintTicketRequired(e);
            }

            if (_startDocCnt == 0)
            {
                JobName = _printQueue.CurrentJobSettings.Description;

                if (JobName == null)
                {
                    JobName = NgcSerializerUtil.InferJobName(o);
                }

                _device = new MetroToGdiConverter(PrintQueue);

                if (!_isSimulating)
                {
                    (new PrintingPermission(PrintingPermissionLevel.DefaultPrinting)).Assert();

                    try
                    {
                        JobIdentifier = _device.StartDocument(_jobName, _printTicketManager.ConsumeActivePrintTicket(true));
                    }
                    finally
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }

            _startDocCnt++;
        }
Пример #21
0
        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
            )
        {
            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);

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

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

                ((IXpsSerializationManager)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);

                ((IXpsSerializationManagerAsync)SerializationManager).OperationStack.Push(collectionContext);
            }
        }
        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);

                    ((IXpsSerializationManager)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();
            }
            ((IXpsSerializationManager)SerializationManager).OnXPSSerializationProgressChanged(progressEvent);
        }
Пример #24
0
        PersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            if (serializableObjectContext == null)
            {
                throw new ArgumentNullException("serializableObjectContext");
            }

            String xmlnsForType = SerializationManager.GetXmlNSForType(typeof(FixedDocument));

            if (SerializationManager is XpsSerializationManager)
            {
                (SerializationManager as XpsSerializationManager).RegisterDocumentStart();
            }

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

            {
                if (serializableObjectContext.IsComplexValue)
                {
                    XpsSerializationPrintTicketRequiredEventArgs e =
                        new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentPrintTicket,
                                                                         0);

                    ((IXpsSerializationManager)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
                {
                    throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_WrongPropertyTypeForFixedDocument));
                }
            }

            //
            // Clear off the table from the packaging policy
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageCrcTable = null;

            ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageUriHashTable = null;

            XmlWriter.WriteEndElement();
            XmlWriter = null;

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

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

            if (SerializationManager is XpsSerializationManager)
            {
                (SerializationManager as XpsSerializationManager).RegisterDocumentEnd();
            }
        }
Пример #25
0
        SimulateBeginFixedPage(
            )
        {
            XmlWriter xmlWriter = null;

            (_serializationManager as IXpsSerializationManager)?.RegisterPageStart();
            //
            // Build the current Page Image Table
            //
            _serializationManager.ResourcePolicy.CurrentPageImageTable = new Dictionary <int, Uri>();
            //
            // Build the current Page ColorContext Table
            //
            _serializationManager.ResourcePolicy.CurrentPageColorContextTable = new Dictionary <int, Uri>();
            //
            // Get the correct namespace
            //
            String xmlnsForType = _serializationManager.GetXmlNSForType(typeof(FixedPage));

            //
            // Pick the correct XmlWriter
            //
            xmlWriter = _serializationManager.AcquireXmlWriter(typeof(FixedPage));

            Visual visual = _serializedObject as Visual;

            if (visual != null)
            {
                _treeWalker = new ReachTreeWalker(xmlWriter, _serializationManager);
                _treeWalker.SerializeLinksInVisual(visual);
            }

            //
            // Write the start element and the namespace
            //
            if (xmlnsForType == null)
            {
                xmlWriter.WriteStartElement(XpsS0Markup.FixedPage);
            }
            else
            {
                xmlWriter.WriteStartElement(XpsS0Markup.FixedPage);

                xmlWriter.WriteAttributeString(XpsS0Markup.Xmlns, xmlnsForType);
                xmlWriter.WriteAttributeString(XpsS0Markup.XmlnsX, XpsS0Markup.XmlnsXSchema);
                xmlWriter.WriteAttributeString(XpsS0Markup.XmlLang, XpsS0Markup.XmlLangValue);
            }

            //
            // Simulating the PrintTicket
            //
            XpsSerializationPrintTicketRequiredEventArgs e =
                new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedPagePrintTicket,
                                                                 0);

            SimulatePrintTicketRaisingEvent(e);

            //
            // Adding Width and Height being mandatory attributes on the FixedPage
            //
            Size size = SimulateFixedPageSize(visual, e.PrintTicket);

            ((IXpsSerializationManager)_serializationManager).FixedPageSize = size;

            xmlWriter.WriteAttributeString(XpsS0Markup.PageWidth,
                                           TypeDescriptor.GetConverter(size.Width).ConvertToInvariantString(size.Width));
            xmlWriter.WriteAttributeString(XpsS0Markup.PageHeight,
                                           TypeDescriptor.GetConverter(size.Height).ConvertToInvariantString(size.Height));

            return(xmlWriter);
        }
Пример #26
0
        PersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            String xmlnsForType = SerializationManager.GetXmlNSForType(typeof(FixedDocument));
            String nameForType  = XpsS0Markup.FixedDocument;

            if (SerializationManager is XpsSerializationManager)
            {
                (SerializationManager as XpsSerializationManager).RegisterDocumentStart();
            }

            if (xmlnsForType == null)
            {
                XmlWriter.WriteStartElement(nameForType);
            }
            else
            {
                XmlWriter.WriteStartElement(nameForType,
                                            xmlnsForType);
            }

            {
                XpsSerializationPrintTicketRequiredEventArgs e =
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentPrintTicket,
                                                                     0);

                ((IXpsSerializationManager)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);
                    }
                }

                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;

                for (int i = 0; !paginator.IsPageCountValid || (i < paginator.PageCount); i++)
                {
                    DocumentPage page = Toolbox.GetPage(paginator, i);

                    ReachSerializer serializer = SerializationManager.GetSerializer(page);

                    if (serializer != null)
                    {
                        serializer.SerializeObject(page);
                    }
                }
            }

            XmlWriter.WriteEndElement();
            XmlWriter = null;
            //
            // Clear off the table from the resource policy
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageCrcTable = null;

            ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageUriHashTable = null;
            //
            // Clear off the table from the resource policy
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.ColorContextTable = 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();
            }
            ((IXpsSerializationManager)SerializationManager).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);

            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);
            
        }
Пример #28
0
        BeginSerializeDocumentPage(
            SerializableObjectContext serializableObjectContext
            )
        {
            PrintTicket printTicket = null;

            _xpsOMSerializationManager.RegisterPageStart();

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

            _xpsOMSerializationManager.OnXPSSerializationPrintTicketRequired(e);

            if (e.Modified)
            {
                printTicket = e.PrintTicket;
            }

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

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



            Size size = Toolbox.ValidateDocumentSize(dp.Size, printTicket);

            _xpsOMSerializationManager.FixedPageSize = size;

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

            return(treeWalker);
        }
Пример #29
0
        SaveAsXaml(
            Object serializedObject
            )
        {
            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsBegin);

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

            if (!IsSerializedObjectTypeSupported(serializedObject))
            {
                throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NotSupported));
            }

            if (_isBatchMode && !_isSimulating)
            {
                XpsSerializationPrintTicketRequiredEventArgs printTicketEvent =
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,
                                                                     0);
                OnNGCSerializationPrintTicketRequired(printTicketEvent);

                StartDocument(null, true);
                _isSimulating = true;
            }

            if (_isBatchMode)
            {
                StartPage();
            }

            if (!_isBatchMode &&
                IsDocumentSequencePrintTicketRequired(serializedObject))
            {
                XpsSerializationPrintTicketRequiredEventArgs printTicketEvent =
                    new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,
                                                                     0);
                OnNGCSerializationPrintTicketRequired(printTicketEvent);
            }


            ReachSerializer reachSerializer = GetSerializer(serializedObject);


            if (reachSerializer != null)
            {
                //
                // Call top-level type serializer, it will walk through the contents and
                // all CLR and DP properties of the object and invoke the proper serializer
                // and typeconverter respectively
                //

                reachSerializer.SerializeObject(serializedObject);

                if (_isBatchMode)
                {
                    EndPage();
                }
            }
            else
            {
                throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoSerializer));
            }

            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsEnd);
        }
Пример #30
0
        ConstructPrintTicketTree(
            XpsSerializationPrintTicketRequiredEventArgs args
            )
        {
            switch (args.PrintTicketLevel)
            {
            case PrintTicketLevel.FixedDocumentSequencePrintTicket:
            {
                if (args.PrintTicket != null)
                {
                    _fdsPrintTicket  = args.PrintTicket;
                    _rootPrintTicket = _fdsPrintTicket;
                }
                else
                {
                    _rootPrintTicket = new PrintTicket(_printQueue.UserPrintTicket.GetXmlStream());
                }

                _activePrintTicket = _rootPrintTicket;
                _isActiveUpdated   = true;

                break;
            }

            case PrintTicketLevel.FixedDocumentPrintTicket:
            {
                if (args.PrintTicket != null)
                {
                    _fdPrintTicket = args.PrintTicket;

                    if (_fdsPrintTicket != null)
                    {
                        //
                        // we have to merge the 2 print tickets
                        //
                        _rootPrintTicket = _printQueue.
                                           MergeAndValidatePrintTicket(_fdsPrintTicket, _fdPrintTicket).
                                           ValidatedPrintTicket;
                    }
                    else
                    {
                        _rootPrintTicket = _fdPrintTicket;
                    }
                }
                else
                {
                    _fdPrintTicket   = null;
                    _rootPrintTicket = _fdsPrintTicket;
                }

                if (_rootPrintTicket == null)
                {
                    _rootPrintTicket = new PrintTicket(_printQueue.UserPrintTicket.GetXmlStream());
                }

                _activePrintTicket = _rootPrintTicket;
                _isActiveUpdated   = true;

                break;
            }

            case PrintTicketLevel.FixedPagePrintTicket:
            {
                if (args.PrintTicket != null)
                {
                    _fpPrintTicket = args.PrintTicket;

                    // The NULL check might not be needed but just in case...
                    String printTicketPairXMLStr =
                        (_rootPrintTicket == null ? "" : _rootPrintTicket.ToXmlString()) +
                        (_fpPrintTicket == null ? "" : _fpPrintTicket.ToXmlString());

                    PrintTicket newActivePrintTicket;

                    if (!m_validatedPrintTicketCache.TryGetValue(printTicketPairXMLStr, out newActivePrintTicket))
                    {
                        //
                        // we have to merge the 2 print tickets
                        //
                        newActivePrintTicket = _printQueue.
                                               MergeAndValidatePrintTicket(_rootPrintTicket, _fpPrintTicket).
                                               ValidatedPrintTicket;

                        m_validatedPrintTicketCache.CacheValue(printTicketPairXMLStr, newActivePrintTicket);
                    }

                    // Ensure cache values are immutable.
                    _activePrintTicket = newActivePrintTicket.Clone();

                    _isActiveUpdated = true;
                }
                else
                {
                    if (_fpPrintTicket != null)
                    {
                        _fpPrintTicket     = null;
                        _activePrintTicket = _rootPrintTicket;
                        _isActiveUpdated   = true;
                    }
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }