Esempio n. 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();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Saves prepared pages to a stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public void Save(Stream stream)
        {
            stream = Compressor.Compress(stream);

            using (XmlDocument doc = new XmlDocument())
            {
                doc.AutoIndent = true;
                doc.Root.Name  = "preparedreport";
                XmlItem pages = doc.Root.Add();
                pages.Name = "pages";

                // attach each page's xml to the doc
                foreach (PreparedPage page in FPreparedPages)
                {
                    pages.AddItem(page.Xml);
                }

                XmlItem sourcePages = doc.Root.Add();
                sourcePages.Name = "sourcepages";
                SourcePages.Save(sourcePages);

                XmlItem dictionary = doc.Root.Add();
                dictionary.Name = "dictionary";
                Dictionary.Save(dictionary);

                XmlItem bookmarks = doc.Root.Add();
                bookmarks.Name = "bookmarks";
                Bookmarks.Save(bookmarks);

                doc.Root.AddItem(Outline.Xml);

                XmlItem blobStore = doc.Root.Add();
                blobStore.Name = "blobstore";
                BlobStore.Save(blobStore);

                doc.Save(stream);

                // detach each page's xml from the doc
                foreach (PreparedPage page in FPreparedPages)
                {
                    page.Xml.Parent = null;
                }
                Outline.Xml.Parent = null;
            }

            stream.Dispose();
        }
Esempio n. 3
0
 /// <summary>
 /// Creates the pages of a prepared report
 /// </summary>
 /// <param name="report"></param>
 public PreparedPages(Report report)
 {
     this.report   = report;
     sourcePages   = new SourcePages(this);
     preparedPages = new List <PreparedPage>();
     dictionary    = new Dictionary(this);
     bookmarks     = new Bookmarks();
     outline       = new Outline();
     blobStore     = new BlobStore(report != null ? report.UseFileCache : false);
     pageCache     = new PageCache(this);
     macroValues   = new Dictionary <string, object>();
     if (this.report != null && this.report.UseFileCache)
     {
         tempFileName = Config.CreateTempFile("");
         tempFile     = new FileStream(tempFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
     }
 }
Esempio n. 4
0
 internal PreparedPages(Report report)
 {
     FReport        = report;
     FSourcePages   = new SourcePages(this);
     FPreparedPages = new List <PreparedPage>();
     FDictionary    = new Dictionary(this);
     FBookmarks     = new Bookmarks();
     FOutline       = new Outline();
     FBlobStore     = new BlobStore();
     FPageCache     = new PageCache(this);
     FMacroValues   = new Dictionary <string, object>();
     if (FReport != null && FReport.UseFileCache)
     {
         FTempFileName = Config.CreateTempFile("");
         FTempFile     = new FileStream(FTempFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
     }
 }
Esempio n. 5
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();
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Saves prepared pages to a stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public void Save(Stream stream)
        {
            if (Config.PreparedCompressed)
            {
                stream = Compressor.Compress(stream);
            }

            using (XmlDocument doc = new XmlDocument())
            {
                doc.AutoIndent = true;
                doc.Root.Name  = "preparedreport";

                // save ReportInfo
                doc.Root.SetProp("ReportInfo.Name", Report.ReportInfo.Name);
                doc.Root.SetProp("ReportInfo.Author", Report.ReportInfo.Author);
                doc.Root.SetProp("ReportInfo.Description", Report.ReportInfo.Description);
                doc.Root.SetProp("ReportInfo.Created", SystemFake.DateTime.Now.ToString());
                doc.Root.SetProp("ReportInfo.Modified", SystemFake.DateTime.Now.ToString());
                doc.Root.SetProp("ReportInfo.CreatorVersion", Report.ReportInfo.CreatorVersion);

                XmlItem pages = doc.Root.Add();
                pages.Name = "pages";

                // attach each page's xml to the doc
                foreach (PreparedPage page in preparedPages)
                {
                    page.Load();
                    pages.AddItem(page.Xml);
                }

                XmlItem sourcePages = doc.Root.Add();
                sourcePages.Name = "sourcepages";
                SourcePages.Save(sourcePages);

                XmlItem dictionary = doc.Root.Add();
                dictionary.Name = "dictionary";
                Dictionary.Save(dictionary);

                XmlItem bookmarks = doc.Root.Add();
                bookmarks.Name = "bookmarks";
                Bookmarks.Save(bookmarks);

                doc.Root.AddItem(Outline.Xml);

                XmlItem blobStore = doc.Root.Add();
                blobStore.Name = "blobstore";
                BlobStore.Save(blobStore);

                doc.Save(stream);

                // detach each page's xml from the doc
                foreach (PreparedPage page in preparedPages)
                {
                    page.Xml.Parent = null;
                    page.ClearUploadedXml();
                }
                Outline.Xml.Parent = null;
            }

            if (Config.PreparedCompressed)
            {
                stream.Dispose();
            }
        }