public void CanRetrieveContentOfFakeTempFile_ButOnlyUntilDisposed()
        {
            using (var server = CreateImageServer())
            {
                var html = @"<html ><head></head><body>here it is</body></html>";
                var dom  = new HtmlDom(html);
                dom.BaseForRelativePaths = _folder.Path.ToLocalhost();
                string url;
                using (var fakeTempFile = EnhancedImageServer.MakeSimulatedPageFileInBookFolder(dom))
                {
                    url = fakeTempFile.Key;
                    var transaction = new PretendRequestInfo(url);

                    // Execute
                    server.MakeReply(transaction);

                    // Verify
                    // Whitespace inserted by CreateHtml5StringFromXml seems to vary across versions and platforms.
                    // I would rather verify the actual output, but don't want this test to be fragile, and the
                    // main point is that we get a file with the DOM content.
                    Assert.That(transaction.ReplyContents,
                                Is.EqualTo(TempFileUtils.CreateHtml5StringFromXml(dom.RawDom)));
                }
                var transactionFail = new PretendRequestInfo(url);

                // Execute
                server.MakeReply(transactionFail);

                // Verify
                Assert.That(transactionFail.StatusCode, Is.EqualTo(404));
            }
        }
示例#2
0
        private SimulatedPageFile MakeFinalHtmlForPdfMaker()
        {
            PdfFilePath = GetPdfPath(Path.GetFileName(_currentlyLoadedBook.FolderPath));

            var dom = BookSelection.CurrentSelection.GetDomForPrinting(BookletPortion, _currentBookCollectionSelection.CurrentSelection, _bookServer);

            AddStylesheetClasses(dom.RawDom);

            //we do this now becuase the publish ui allows the user to select a different layout for the pdf than what is in the book file
            SizeAndOrientation.UpdatePageSizeAndOrientationClasses(dom.RawDom, PageLayout);
            PageLayout.UpdatePageSplitMode(dom.RawDom);

            XmlHtmlConverter.MakeXmlishTagsSafeForInterpretationAsHtml(dom.RawDom);
            dom.UseOriginalImages = true;             // don't want low-res images or transparency in PDF.
            return(EnhancedImageServer.MakeSimulatedPageFileInBookFolder(dom));
        }
        private PretendRequestInfo CreateServerMakeSimPageMakeReply(HtmlDom dom, bool simulateCallingFromJavascript = false)
        {
            PretendRequestInfo transaction;

            using (var server = CreateImageServer())
            {
                using (var fakeTempFile = EnhancedImageServer.MakeSimulatedPageFileInBookFolder(dom, simulateCallingFromJavascript))
                {
                    var url = fakeTempFile.Key;
                    transaction = new PretendRequestInfo(url, forPrinting: false, forSrcAttr: simulateCallingFromJavascript);

                    // Execute
                    server.MakeReply(transaction);
                }
            }
            return(transaction);
        }
示例#4
0
        private SimulatedPageFile MakeFinalHtmlForPdfMaker()
        {
            PdfFilePath = GetPdfPath(Path.GetFileName(_currentlyLoadedBook.FolderPath));

            var dom = BookSelection.CurrentSelection.GetDomForPrinting(BookletPortion, _currentBookCollectionSelection.CurrentSelection, _bookServer);

            AddStylesheetClasses(dom.RawDom);

            //we do this now becuase the publish ui allows the user to select a different layout for the pdf than what is in the book file
            SizeAndOrientation.UpdatePageSizeAndOrientationClasses(dom.RawDom, PageLayout);

            if (BookSelection.CurrentSelection.GetLayout().SizeAndOrientation.IsLandScape !=
                PageLayout.SizeAndOrientation.IsLandScape)
            {
                // Need to update the xmatter in the print dom...it may use different images.
                // Make sure we do this AFTER setting PageOrientation in Dom.
                BookSelection.CurrentSelection.UpdateBrandingForCurrentOrientation(dom);
            }
            PageLayout.UpdatePageSplitMode(dom.RawDom);

            XmlHtmlConverter.MakeXmlishTagsSafeForInterpretationAsHtml(dom.RawDom);
            dom.UseOriginalImages = true;             // don't want low-res images or transparency in PDF.
            return(EnhancedImageServer.MakeSimulatedPageFileInBookFolder(dom, source: "pub"));
        }
示例#5
0
        /// <summary>
        /// Returns true if it make some attempt at an image, false if navigation is currently suppressed.
        /// </summary>
        /// <param name="order"></param>
        /// <param name="browser"></param>
        /// <param name="thumbnail"></param>
        /// <returns></returns>
        private bool CreateThumbNail(ThumbnailOrder order, GeckoWebBrowser browser, out Image thumbnail)
        {
            // runs on threadpool thread
            thumbnail = null;
            using (var temp = EnhancedImageServer.MakeSimulatedPageFileInBookFolder(order.Document))
            {
                order.Done  = false;
                browser.Tag = order;
                if (!OpenTempFileInBrowser(browser, temp.Key))
                {
                    return(false);
                }

                var browserSize = SetWidthAndHeight(browser);
                if (browserSize.Height == 0)          //happens when we run into the as-yet-unreproduced-or-fixed bl-254
                {
                    return(false);                    // will try again later
                }
                try
                {
                    Logger.WriteMinorEvent("HtmlThumNailer ({2}): browser.GetBitmap({0},{1})", browserSize.Width,
                                           (uint)browserSize.Height,
                                           Thread.CurrentThread.ManagedThreadId);
                    // This short sleep was added to fix BL-4170, a problem where thumbnails were often generated without
                    // images. We're not sure what changed or why it became necessary. Possibly there was a change in GeckoFx 45
                    // which caused it report document-complete before background images are sufficiently loaded to show up
                    // in a captured image. Testing indicated that our image server did finish returning the background
                    // images before the document-complete notification, but that doesn't prove they were fully rendered.
                    // Also casting doubt on this hypothesis, we tried delays (some much longer) in several seemingly
                    // more logical places where they didn't help, at least not without being unreasonably long.
                    // The length of the delay is of course problematic. Experiments on my fast desktop indicate that 10ms
                    // does not help; 20ms is enough for AOR images; 40ms for a 6mp/4M jpg photo; but somewhere between
                    // 100 and 200ms can be needed by a really large (24mp/14M) image. 200ms is based on hoping that
                    // most computers are no worse than five times slower than mine and accepting that the slower ones
                    // might have problems with huge images.
                    Thread.Sleep(200);
                    //BUG (April 2013) found that the initial call to GetBitMap always had a zero width, leading to an exception which
                    //the user doesn't see and then all is well. So at the moment, we avoid the exception, and just leave with
                    //the placeholder thumbnail.
                    if (browserSize.Width == 0 || browserSize.Height == 0)
                    {
                        var paperSizeName = GetPaperSizeName(order.Document.RawDom);
                        throw new ApplicationException("Problem getting thumbnail browser for document with Paper Size: " + paperSizeName);
                    }
                    using (Image fullsizeImage = CreateImage(browser))
                    {
                        if (_disposed)
                        {
                            return(false);
                        }
                        thumbnail = MakeThumbNail(fullsizeImage, order.Options);
                        return(true);
                    }
                }
                catch (Exception error)
                {
                    Logger.WriteEvent("HtmlThumbNailer ({0}) got {1}", Thread.CurrentThread.ManagedThreadId, error.Message);
                    Logger.WriteEvent("Disposing of all browsers in hopes of getting a fresh start on life");
                    foreach (var browserCacheForDifferentPaperSize in _browserCacheForDifferentPaperSizes)
                    {
                        try
                        {
                            Logger.WriteEvent("Disposing of browser {0}", browserCacheForDifferentPaperSize.Key);
                            browserCacheForDifferentPaperSize.Value.Dispose();
                        }
                        catch (Exception e2)
                        {
                            Logger.WriteEvent(
                                "While trying to dispose of thumbnailer browsers as a result of an exception, go another: " + e2.Message);
                        }
                    }
                    _browserCacheForDifferentPaperSizes.Clear();
#if DEBUG
                    _syncControl.Invoke((Action)(() => Debug.Fail(error.Message)));
#endif
                }
            }
            return(false);
        }