상속: IDisposable
예제 #1
0
        public HtmlThumbNailer(NavigationIsolator isolator)
        {
            if (_theOnlyOneAllowed != null)
            {
                Debug.Fail("Something tried to make a second HtmlThumbnailer; there should only be one.");
                throw new ApplicationException("Something tried to make a second HtmlThumbnailer; there should only be one.");
            }

            _theOnlyOneAllowed = this;

            _isolator = isolator;

            _syncControl = new Control();
            _syncControl.CreateControl();
        }
예제 #2
0
 public void Dispose()
 {
     _disposed = true;
     _orders.Clear();
     foreach (var browser in _browserCacheForDifferentPaperSizes)
     {
         browser.Value.Invoke((Action)(() =>
         {
             browser.Value.DocumentCompleted -= _browser_OnDocumentCompleted;
             browser.Value.Dispose();
         }));
     }
     _browserCacheForDifferentPaperSizes.Clear();
     _theOnlyOneAllowed = null;
 }
예제 #3
0
        public HtmlThumbNailer(NavigationIsolator isolator)
        {
            if (_theOnlyOneAllowed != null)
            {
                Debug.Fail("Something tried to make a second HtmlThumbnailer; there should only be one.");
                throw new ApplicationException("Something tried to make a second HtmlThumbnailer; there should only be one.");
            }

            _theOnlyOneAllowed = this;

            _isolator = isolator;

            _syncControl = new Control();
            _syncControl.CreateControl();
        }
예제 #4
0
        public void Dispose()
        {
            _disposed = true;
            foreach (var browser in _browserCacheForDifferentPaperSizes)
            {
                if (browser.Value.InvokeRequired)
                {
                    browser.Value.Invoke((Action)(() => {
                        browser.Value.DocumentCompleted -= _browser_OnDocumentCompleted;
                        browser.Value.Dispose();
                    }));
                }
                else
                {
                    browser.Value.DocumentCompleted -= _browser_OnDocumentCompleted;
                    browser.Value.Dispose();
                }
            }
            _browserCacheForDifferentPaperSizes.Clear();
            _theOnlyOneAllowed = null;

            GC.SuppressFinalize(this);
        }
예제 #5
0
 public BookThumbNailer(HtmlThumbNailer thumbNailer)
 {
     _thumbnailProvider = thumbNailer;
 }
예제 #6
0
        public 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;
                }
                Image thumb;
                if (book.Storage.TryGetPremadeThumbnail(thumbnailOptions.FileName, out thumb))
                {
                    callback(thumb);
                    return;
                }

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

                folderForCachingThumbnail = book.Storage.FolderPath;
                _thumbnailProvider.GetThumbnail(folderForCachingThumbnail, book.Storage.Key, dom, thumbnailOptions, callback, errorCallback, async);
            }
            catch (Exception err)
            {
                callback(Resources.Error70x70);
                Debug.Fail(err.Message);
            }
        }
예제 #7
0
 public BookThumbNailer(HtmlThumbNailer thumbNailer)
 {
     _thumbnailProvider = thumbNailer;
 }
예제 #8
0
        /// <summary>
        /// Will call either 'callback' or 'errorCallback' UNLESS the thumbnail is readonly, in which case it will do neither.
        /// </summary>
        /// <param name="book"></param>
        /// <param name="thumbnailOptions"></param>
        /// <param name="callback"></param>
        /// <param name="errorCallback"></param>
        private void RebuildThumbNail(Book.Book book, HtmlThumbNailer.ThumbnailOptions thumbnailOptions,
			Action<BookInfo, Image> callback, Action<BookInfo, Exception> errorCallback, bool async)
        {
            try
            {
                if(!book.Storage.RemoveBookThumbnail(thumbnailOptions.FileName))
                {
                    // thumbnail is marked readonly, so just use it
                    Image thumb;
                    book.Storage.TryGetPremadeThumbnail(thumbnailOptions.FileName, out thumb);
                    callback(book.BookInfo, thumb);
                    return;
                }

                _thumbnailProvider.RemoveFromCache(book.Storage.Key);

                thumbnailOptions.BorderStyle = (book.Type == Book.Book.BookType.Publication)
                    ? HtmlThumbNailer.ThumbnailOptions.BorderStyles.Solid
                    : HtmlThumbNailer.ThumbnailOptions.BorderStyles.Dashed;
                GetThumbNailOfBookCover(book, thumbnailOptions, image => callback(book.BookInfo, image),
                    error =>
                    {
                        //Enhance; this isn't a very satisfying time to find out, because it's only going to happen if we happen to be rebuilding the thumbnail.
                        //It does help in the case where things are bad, so no thumbnail was created, but by then probably the user has already had some big error.
                        //On the other hand, given that they have this bad book in their collection now, it's good to just remind them that it's broken and not
                        //keep showing green error boxes.
                        book.CheckForErrors();
                        errorCallback(book.BookInfo, error);
                    }, async);
            }
            catch(Exception error)
            {
                NonFatalProblem.Report(ModalIf.Alpha, PassiveIf.All, "Problem creating book thumbnail ", exception: error);
            }
        }
예제 #9
0
 /// <summary>
 /// Will make a new thumbnail (or throw) UNLESS the thumbnail is readonly, in which case it will do nothing.
 /// </summary>
 /// <param name="book"></param>
 /// <param name="thumbnailOptions"></param>
 public void RebuildThumbNailNow(Book.Book book, HtmlThumbNailer.ThumbnailOptions thumbnailOptions)
 {
     RebuildThumbNail(book, thumbnailOptions, (info, image) => { },
         (info, ex) =>
         {
             throw ex;
         }, false);
 }
예제 #10
0
        /// <summary>
        /// Will call either 'callback' or 'errorCallback' UNLESS the thumbnail is readonly, in which case it will do neither.
        /// </summary>
        /// <param name="book"></param>
        /// <param name="thumbnailOptions"></param>
        /// <param name="callback"></param>
        /// <param name="errorCallback"></param>
        public void RebuildThumbNailAsync(Book.Book book, HtmlThumbNailer.ThumbnailOptions thumbnailOptions,
			Action<BookInfo, Image> callback, Action<BookInfo, Exception> errorCallback)
        {
            RebuildThumbNail(book, thumbnailOptions, callback, errorCallback, true);
        }
예제 #11
0
 public void Setup()
 {
     _workFolder = new TemporaryFolder("unittest-" + _thisTestId);
     _workFolderPath = _workFolder.FolderPath;
     Assert.AreEqual(0,Directory.GetDirectories(_workFolderPath).Count(),"Some stuff was left over from a previous test");
     Assert.AreEqual(0, Directory.GetFiles(_workFolderPath).Count(),"Some stuff was left over from a previous test");
     // Todo: Make sure the S3 unit test bucket is empty.
     // Todo: Make sure the parse.com unit test book table is empty
     _parseClient = new BloomParseClientDouble(_thisTestId);
     _htmlThumbNailer = new HtmlThumbNailer(new NavigationIsolator());
     _transfer = new BookTransfer(_parseClient, new BloomS3Client(BloomS3Client.UnitTestBucketName), new BookThumbNailer(_htmlThumbNailer), new BookDownloadStartingEvent());
     _transfer.BookDownLoaded += (sender, args) => _downloadedBooks.Add(args.BookDetails);
 }
예제 #12
0
        public void Dispose()
        {
            _disposed = true;
            foreach (var browser in _browserCacheForDifferentPaperSizes)
            {
                if (browser.Value.InvokeRequired)
                {
                    browser.Value.Invoke((Action)(() => {
                        browser.Value.DocumentCompleted -= _browser_OnDocumentCompleted;
                        browser.Value.Dispose();
                    }));
                }
                else
                {
                    browser.Value.DocumentCompleted -= _browser_OnDocumentCompleted;
                    browser.Value.Dispose();
                }
            }
            _browserCacheForDifferentPaperSizes.Clear();
            _theOnlyOneAllowed = null;

            GC.SuppressFinalize(this);
        }