示例#1
0
        /// <summary>
        /// Loads prepared pages from a stream.
        /// </summary>
        /// <param name="stream">The stream to load from.</param>
        public void Load(Stream stream)
        {
            Clear();

            bool compressed = Compressor.IsStreamCompressed(stream);

            if (compressed)
            {
                stream = Compressor.Decompress(stream, false);
            }

            try
            {
                using (XmlDocument doc = new XmlDocument())
                {
                    doc.Load(stream);

                    XmlItem sourcePages = doc.Root.FindItem("sourcepages");
                    SourcePages.Load(sourcePages);

                    XmlItem dictionary = doc.Root.FindItem("dictionary");
                    Dictionary.Load(dictionary);

                    XmlItem bookmarks = doc.Root.FindItem("bookmarks");
                    Bookmarks.Load(bookmarks);

                    XmlItem outline = doc.Root.FindItem("outline");
                    Outline.Xml = outline;

                    XmlItem blobStore = doc.Root.FindItem("blobstore");
                    BlobStore.Load(blobStore);

                    XmlItem pages = doc.Root.FindItem("pages");
                    while (pages.Count > 0)
                    {
                        XmlItem      pageItem     = pages[0];
                        PreparedPage preparedPage = new PreparedPage(null, this);
                        FPreparedPages.Add(preparedPage);
                        preparedPage.Xml = pageItem;
                    }
                }
            }
            finally
            {
                if (compressed)
                {
                    stream.Dispose();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Loads prepared pages from a stream.
        /// </summary>
        /// <param name="stream">The stream to load from.</param>
        public void Load(Stream stream)
        {
            Clear();

            if (!stream.CanSeek)
            {
                MemoryStream tempStream = new MemoryStream();
                FileUtils.CopyStream(stream, tempStream);
                tempStream.Position = 0;
                stream = tempStream;
            }

            if (stream.Length == 0)
            {
                return;
            }

            bool compressed = Compressor.IsStreamCompressed(stream);

            if (compressed)
            {
                stream = Compressor.Decompress(stream, false);
            }

            try
            {
                using (XmlDocument doc = new XmlDocument())
                {
                    doc.Load(stream);

                    XmlItem sourcePages = doc.Root.FindItem("sourcepages");
                    SourcePages.Load(sourcePages);

                    XmlItem dictionary = doc.Root.FindItem("dictionary");
                    Dictionary.Load(dictionary);

                    XmlItem bookmarks = doc.Root.FindItem("bookmarks");
                    Bookmarks.Load(bookmarks);

                    XmlItem outline = doc.Root.FindItem("outline");
                    Outline.Xml = outline;

                    XmlItem blobStore = doc.Root.FindItem("blobstore");
                    BlobStore.LoadDestructive(blobStore);

                    XmlItem pages = doc.Root.FindItem("pages");
                    while (pages.Count > 0)
                    {
                        XmlItem      pageItem     = pages[0];
                        PreparedPage preparedPage = new PreparedPage(null, this);
                        preparedPages.Add(preparedPage);
                        preparedPage.Xml = pageItem;
                    }

                    // load ReportInfo
                    Report.ReportInfo.Name        = doc.Root.GetProp("ReportInfo.Name");
                    Report.ReportInfo.Author      = doc.Root.GetProp("ReportInfo.Author");
                    Report.ReportInfo.Description = doc.Root.GetProp("ReportInfo.Description");
                    DateTime createDate;
                    if (DateTime.TryParse(doc.Root.GetProp("ReportInfo.Created"), out createDate))
                    {
                        Report.ReportInfo.Created = createDate;
                    }
                    if (DateTime.TryParse(doc.Root.GetProp("ReportInfo.Modified"), out createDate))
                    {
                        Report.ReportInfo.Modified = createDate;
                    }
                    Report.ReportInfo.CreatorVersion = doc.Root.GetProp("ReportInfo.CreatorVersion");
                }
            }
            finally
            {
                if (compressed)
                {
                    stream.Dispose();
                }
            }
        }