SaveAsXaml( Object serializedObject ) { if (serializedObject == null) { throw new ArgumentNullException(nameof(serializedObject)); } if (!XpsSerializationManager.IsSerializedObjectTypeSupported(serializedObject, IsBatchMode)) { throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NotSupported)); } if (Simulator == null) { Simulator = new XpsOMHierarchySimulator(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)); } } }
SaveAsXaml( object serializedObject ) { Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsBegin); if (_packagingPolicy.IsValid) { XmlWriter pageWriter = null; if (serializedObject == null) { throw new ArgumentNullException(nameof(serializedObject)); } if (!XpsSerializationManager.IsSerializedObjectTypeSupported(serializedObject, _isBatchMode)) { 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 XpsOMHierarchySimulator(this, serializedObject); } if (!_isSimulating) { _simulator.BeginConfirmToXPSStructure(_isBatchMode); _isSimulating = true; } if (_isBatchMode) { pageWriter = _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(pageWriter); } else { _simulator.EndConfirmToXPSStructure(_isBatchMode); } } else { throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoSerializer)); } } Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsEnd); }