Beispiel #1
0
        SaveAsXaml(
            Object serializedObject
            )
        {
            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsBegin);

            XmlWriter pageXmlWriter = null;

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

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

            if (serializedObject is DocumentPaginator)
            {
                // Prefast complains that serializedObject is not tested for null
                // It is tested a few lines up
                #pragma warning suppress 56506
                if ((serializedObject as DocumentPaginator).Source is FixedDocument &&
                    serializedObject.GetType().ToString().Contains("FixedDocumentPaginator"))
                {
                    serializedObject = (serializedObject as DocumentPaginator).Source;
                }
                else
                if ((serializedObject as DocumentPaginator).Source is FixedDocumentSequence &&
                    serializedObject.GetType().ToString().Contains("FixedDocumentSequencePaginator"))
                {
                    serializedObject = (serializedObject as DocumentPaginator).Source;
                }
            }

            if (_simulator == null)
            {
                _simulator = new ReachHierarchySimulator(this,
                                                         serializedObject);
            }

            if (!_isSimulating)
            {
                _simulator.BeginConfirmToXPSStructure(_isBatchMode);
                _isSimulating = true;
            }

            if (_isBatchMode)
            {
                pageXmlWriter = _simulator.SimulateBeginFixedPage();
            }

            ReachSerializer reachSerializer = GetSerializer(serializedObject);

            if (reachSerializer != null)
            {
                //
                // Things that need to be done at this stage
                // 1. Setting the stack context
                // 2. Setting the root of the graph for future references
                //
                reachSerializer.SerializeObject(serializedObject);

                if (_isBatchMode)
                {
                    _simulator.SimulateEndFixedPage(pageXmlWriter);
                }
                else
                {
                    _simulator.EndConfirmToXPSStructure(_isBatchMode);
                }
            }
            else
            {
                throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoSerializer));
            }

            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsEnd);
        }
        SaveAsXaml(
            Object serializedObject
            )
        {
            if (serializedObject == null)
            {
                throw new ArgumentNullException("serializedObject");
            }

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

            if (Simulator == null)
            {
                Simulator = new ReachHierarchySimulator(this,
                                                        serializedObject);
            }

            if (!IsSimulating)
            {
                Simulator.BeginConfirmToXPSStructure(IsBatchMode);
                IsSimulating = true;
            }

            if (IsBatchMode)
            {
                //
                // Add the Visual received in to the queue
                //
                BatchOperationWorkItem batchOperationWorkItem = new BatchOperationWorkItem(BatchOperationType.batchWrite,
                                                                                           serializedObject);
                _batchOperationQueue.Enqueue(batchOperationWorkItem);
                PostSerializationTask(new DispatcherOperationCallback(InvokeSaveAsXamlBatchWorkItem));
            }
            else
            {
                ReachSerializer reachSerializer = GetSerializer(serializedObject);

                if (reachSerializer != null)
                {
                    //
                    // Prepare the context that is going to be pushed on the stack
                    //
                    SerializationManagerOperationContextStack
                        contextStack = new SerializationManagerOperationContextStack(reachSerializer,
                                                                                     serializedObject);
                    //
                    // At this stage, start calling another method which would peak at the stack
                    //
                    _operationStack.Push(contextStack);

                    PostSerializationTask(new DispatcherOperationCallback(InvokeSaveAsXamlWorkItem));
                }
                else
                {
                    throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoSerializer));
                }
            }
        }