Exemple #1
0
        }// end:ReleaseXmlWriterForFixedDocument

        // ------------------- AcquireXmlWriterForFixedPage -------------------
        /// <Summary>
        ///   Acquires an XmlWriter for a FixedPage.</Summary>
        public override XmlWriter AcquireXmlWriterForFixedPage()
        {
            XmlWriter xmlWriter = null;

            if (_currentFixedPageHelper == null)
            {
                String fileName = FileHelper.GenerateFileName(XpsFileType.FixedPage, _path);
                _currentFixedPageHelper = new XmlWriterHelper(_path, fileName);

                //Need to allocate helper streams and writers for FixedPage
                _linkTargetStream            = new List <String>();
                _resourceDictionaryStream    = new StringWriter(CultureInfo.InvariantCulture);
                _resourceDictionaryXmlWriter = new XmlTextWriter(_resourceDictionaryStream);
                _pageStream    = new StringWriter(CultureInfo.InvariantCulture);
                _pageXmlWriter = new XmlTextWriter(_pageStream);

                //Need to figure out name for the relationship file for this FixedPage
                String path = _path + "/Pages/_rels/" + Path.GetFileName(fileName) + ".rels";
                _fixedPageRelationshipStream = new RelationshipStream(path);

                //Add FixedPage type to Content Type file
                _contentTypeFile.AddType(XpsFileType.FixedPage,
                                         FileHelper.GetExtension(XpsFileType.FixedPage));
            }

            xmlWriter = _currentFixedPageHelper.AcquireXmlWriter();

            return(xmlWriter);
        }
Exemple #2
0
        }// end:ReleaseXmlWriterForFixedDocumentSequence

        // ----------------- AcquireXmlWriterForFixedDocument -----------------
        /// <Summary>
        ///   Acquires an XmlWriter for a FixedDocument.</Summary>
        public override XmlWriter AcquireXmlWriterForFixedDocument()
        {
            XmlWriter xmlWriter = null;

            //Create a FixedDocumentHelper if one isn't already created.
            if (_currentFixedDocumentHelper == null)
            {
                String fileName = FileHelper.GenerateFileName(XpsFileType.FixedDocument, _path);
                _currentFixedDocumentHelper = new XmlWriterHelper(_path, fileName);

                //Add FixedDocument content type to ConentTypes file
                _contentTypeFile.AddType(XpsFileType.FixedDocument,
                                         FileHelper.GetExtension(XpsFileType.FixedDocument));

                //Need to figure out name for the relationship file for this FixedPage
                String path = _path + "/Documents/_rels/" + Path.GetFileName(fileName) + ".rels";
                _fixedDocumentRelationshipStream = new RelationshipStream(path);

                //Need to write DocumentReference markup to FixedDocument
                _currentDocumentSequenceHelper.WriteStartElement("DocumentReference");
                String relativePath = _currentFixedDocumentHelper.FileName;
                _currentDocumentSequenceHelper.WriteAttributeString("Source", relativePath);
                _currentDocumentSequenceHelper.WriteEndElement();
            }

            xmlWriter = _currentFixedDocumentHelper.AcquireXmlWriter();

            return(xmlWriter);
        }
Exemple #3
0
        // ------------- ReleaseXmlWriterForFixedDocumentSequence -------------
        /// <Summary>
        ///   Releases a reference to the current FixedDocumentSequence.</Summary>
        public override void ReleaseXmlWriterForFixedDocumentSequence()
        {
            if (_currentDocumentSequenceHelper != null)
            {
                _currentDocumentSequenceHelper.ReleaseXmlWriter();

                if (_currentDocumentSequenceHelper.FileRef == 0)
                {
                    //Create relationship stream and add starting part relationship to the file
                    String             relationshipsFileName = _path + "/_rels/.rels";
                    RelationshipStream relStream             = new RelationshipStream(relationshipsFileName);
                    String             startingPart          = "/" + _currentDocumentSequenceHelper.FileName;
                    relStream.CreateStartingPart(startingPart);
                    relStream.Close();

                    _contentTypeFile.Close();

                    _currentDocumentSequenceHelper = null;

                    // Since the FixedDocumentSequence is being closed we need
                    // to also close the current FixedDocument and FixedPage
                    // if they are still open.

                    //Release Fixed Document Writer
                    if (_currentFixedDocumentHelper != null)
                    {
                        _currentFixedDocumentHelper.ReleaseAll();
                        _currentFixedDocumentHelper = null;
                    }

                    //Release Fixed Page Writer
                    if (_currentFixedPageHelper != null)
                    {
                        _currentFixedPageHelper.ReleaseAll();
                        _currentFixedPageHelper = null;
                    }
                }
            }
            else
            {
                throw new XpsSerializationException("Cannot release XmlWriter");
            }
        }// end:ReleaseXmlWriterForFixedDocumentSequence