Beispiel #1
0
        void MakeThumbnail(Book.Book book, int height, Control invokeTarget)
        {
            bool   done  = false;
            string error = null;

            HtmlThumbNailer.ThumbnailOptions options = new HtmlThumbNailer.ThumbnailOptions()
            {
                CenterImageUsingTransparentPadding = false,
                //since this is destined for HTML, it's much easier to handle if there is no pre-padding

                Height   = height,
                Width    = -1,
                FileName = "thumbnail-" + height + ".png"
            };

            book.RebuildThumbNailAsync(options, (info, image) => done = true,
                                       (info, ex) =>
            {
                done = true;
                throw ex;
            });
            var giveUpTime = DateTime.Now.AddSeconds(15);

            while (!done && DateTime.Now < giveUpTime)
            {
                Thread.Sleep(100);
                Application.DoEvents();
                // In the context of bulk upload, when a model dialog is the only window, apparently Application.Idle is never invoked.
                // So we need a trick to allow the thumbnailer to actually make some progress, since it usually works while idle.
                this._htmlThumbnailer.Advance(invokeTarget);
            }
            if (!done)
            {
                throw new ApplicationException(string.Format("Gave up waiting for the {0} to be created. This usually means Bloom is busy making thumbnails for other things. Wait a bit, and try again.", options.FileName));
            }
        }
 public void UpdateThumbnailAsync(Book.Book book, HtmlThumbNailer.ThumbnailOptions thumbnailOptions, Action <Book.BookInfo, Image> callback, Action <Book.BookInfo, Exception> errorCallback)
 {
     book.RebuildThumbNailAsync(thumbnailOptions, callback, errorCallback);
 }