Bloom.HtmlThumbNailer.GetThumbnail C# (CSharp) Method

GetThumbnail() public method

A synchronous version of getting thumbnails, currently used by the image server to get thumbnails that are used in the add page dialog.
public GetThumbnail ( string key, HtmlDom document, ThumbnailOptions options ) : Image
key string Used to retrieve the thumbnail from a dictionary if we are asked for /// the same one repeatedly
document Bloom.Book.HtmlDom Whose rendering will produce the thumbnail content.
options ThumbnailOptions
return Image
        public Image GetThumbnail(string key, HtmlDom document, ThumbnailOptions options)
        {
            Image image;
            Image thumbnail = null;
            lock (this)
            {
                //In our cache?
                if (!String.IsNullOrWhiteSpace(key) && _images.TryGetValue(key, out image))
                {
                    Debug.WriteLine("Thumbnail Cache HIT: "+ key + " thread=" + Thread.CurrentThread.ManagedThreadId);
                    return image;
                }
                Debug.WriteLine("Thumbnail Cache MISS: " + key + " thread=" + Thread.CurrentThread.ManagedThreadId);

                _backgroundColorOfResult = options.BackgroundColor;
                XmlHtmlConverter.MakeXmlishTagsSafeForInterpretationAsHtml(document.RawDom);

                var browser = GetBrowserForPaperSize(document.RawDom);
                if (browser == null)
                    return Resources.PagePlaceHolder;

                var order = new ThumbnailOrder()
                {
                    Options = options,
                    Document = document
                };
                for (int i = 0; i < 4; i++)
                {
                    if (CreateThumbNail(order, browser, out thumbnail))
                        break;
                    // For some reason...possibly another navigation was in progress...we can't do this just now.
                    // Try a few times.
                }
                if (thumbnail == null) // just can't get it.
                {
                    return Resources.PagePlaceHolder; // but don't save it...try again if we get another request.
                }
                if (!String.IsNullOrWhiteSpace(key))
                    _images[key] = thumbnail;
            }
            return thumbnail;
        }

Same methods

HtmlThumbNailer::GetThumbnail ( string folderForThumbNailCache, string key, HtmlDom document, ThumbnailOptions options, Action callback, Action errorCallback, bool async ) : void

Usage Example

Esempio n. 1
0
        private void GetThumbNailOfBookCover(Book.Book book, HtmlThumbNailer.ThumbnailOptions thumbnailOptions, Action <Image> callback, Action <Exception> errorCallback, bool async)
        {
            if (book is ErrorBook)
            {
                callback(Resources.Error70x70);
                return;
            }
            try
            {
                if (book.HasFatalError)                 //NB: we might not know yet... we don't fully load every book just to show its thumbnail
                {
                    callback(Resources.Error70x70);
                    return;
                }
                GenerateImageForWeb(book);

                Image thumb;
                if (book.Storage.TryGetPremadeThumbnail(thumbnailOptions.FileName, out thumb))
                {
                    callback(thumb);
                    return;
                }

#if USE_HTMLTHUMBNAILER_FOR_COVER
                var dom = book.GetPreviewXmlDocumentForFirstPage();
                if (dom == null)
                {
                    callback(Resources.Error70x70);
                    return;
                }
                string folderForCachingThumbnail;

                folderForCachingThumbnail = book.StoragePageFolder;
                _thumbnailProvider.GetThumbnail(folderForCachingThumbnail, book.Storage.Key, dom, thumbnailOptions, callback, errorCallback, async);
#else
                if (!CreateThumbnailOfCoverImage(book, thumbnailOptions, callback))
                {
                    callback(Resources.Error70x70);
                }
#endif
            }
            catch (Exception err)
            {
                callback(Resources.Error70x70);
                errorCallback(err);
                Debug.Fail(err.Message);
            }
        }
All Usage Examples Of Bloom.HtmlThumbNailer::GetThumbnail