Provides a way to note a problem in the log and, depending on channel, notify the user.
Ejemplo n.º 1
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 = GetThumbnailBorderStyle(book);
                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);
            }
        }
Ejemplo n.º 2
0
        private Size SetWidthAndHeight(GeckoWebBrowser browser)
        {
            try
            {
                if (_syncControl.InvokeRequired)
                {
                    return((Size)_syncControl.Invoke(new Func <GeckoWebBrowser, Size>(SetWidthAndHeight), browser));
                }
            }
            catch (Exception e)
            {
                NonFatalProblem.Report(ModalIf.None, PassiveIf.Alpha, "Could not make thumbnail", "Ref bl-524", e);
                return(new Size(0, 0));               // this tells the caller we failed
            }

            Guard.AgainstNull(browser.Document.ActiveElement, "browser.Document.ActiveElement");
            var div = browser.Document.ActiveElement.EvaluateXPath("//div[contains(@class, 'bloom-page')]").GetNodes().FirstOrDefault() as GeckoElement;

            if (div == null)
            {
                var order = (ThumbnailOrder)browser.Tag;
                Logger.WriteEvent("HtmlThumNailer ({1}):  found no div with a class of bloom-Page ({0})", order.ThumbNailFilePath,
                                  Thread.CurrentThread.ManagedThreadId);
                throw new ApplicationException("thumbnails found no div with a class of bloom-Page");
            }
            browser.Height = div.ClientHeight;
            browser.Width  = div.ClientWidth;
            // This is probably not needed...width zero came about in debugging incomplete code where a stylesheet
            // did not take effect..but it seems like a reasonable bit of defensive programming to keep.
            if (browser.Width == 0)
            {
                browser.Width = browser.Height / 2;               // arbitrary way of avoiding crash
            }
            return(new Size(browser.Width, browser.Height));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// If we can successfully download the update version table for the current channel,
        /// we return true and set the TextContentsOfTable property. Otherwise we return false and
        /// an UpdateTableLookupResult with an embedded error as an 'out' param.
        /// This internal method enables testing of captive portal situations
        /// </summary>
        /// <param name="client"></param>
        /// <param name="errorResult"></param>
        /// <returns></returns>
        internal bool CanGetVersionTableFromWeb(IBloomWebClient client, out UpdateTableLookupResult errorResult)
        {
            errorResult = null;
            try
            {
                Logger.WriteEvent("Channel is '" + ApplicationUpdateSupport.ChannelName + "'");
                Logger.WriteEvent("UpdateVersionTable looking for UpdateVersionTable URL: " + GetUrlOfTable());
                TextContentsOfTable = client.DownloadString(GetUrlOfTable());

                //things like captive portals will return an html page rather than the text file what we asked for, if the user isn't
                //logged in.
                if (TextContentsOfTable.ToLower().Contains("<html"))
                {
                    LogTableContents();
                    var msg = "Internet connection did not allow check for update.";
                    NonFatalProblem.Report(ModalIf.Alpha, PassiveIf.All, msg);                     // hopefully this will just 'toast'
                    errorResult = new UpdateTableLookupResult {
                        URL = string.Empty, Error = new WebException(msg)
                    };
                    return(false);
                }
            }
            catch (WebException e)
            {
                Logger.WriteEvent("***Error (WebException) in CanGetVersionTableFromWeb: " + e.Message);
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    if (e.Response is HttpWebResponse resp && resp.StatusCode == HttpStatusCode.NotFound)
                    {
                        Logger.WriteEvent(
                            $"***Error: UpdateVersionTable failed to find a file at {GetUrlOfTable()} (channel='{ApplicationUpdateSupport.ChannelName}'");
                    }
                }
                else if (IsConnectionError(e))
                {
                    Logger.WriteEvent("***Error: UpdateVersionTable could not connect to the server");
                }
                errorResult = new UpdateTableLookupResult()
                {
                    Error = e
                };
                return(false);
            }
            catch (Exception e)
            {
                // We're getting some kind of exception thrown on some alpha users' machines, but we don't know why (BL-9211).
                // It isn't a WebException. I'm adding this catch block at least long enough to diagnose the problem,
                // but it is probably better to be here, anyway, since without it, Bloom crashes silently.
                Logger.WriteError("***Error (Exception) in CanGetVersionTableFromWeb:", e);

                errorResult = new UpdateTableLookupResult()
                {
                    Error = new WebException(e.Message)
                };
                return(false);
            }
            return(true);            // no error yet anyway!
        }
        /// <summary>
        /// If we can successfully download the update version table for the current channel,
        /// we return true and set the TextContentsOfTable property. Otherwise we return false and
        /// an UpdateTableLookupResult with an embedded error as an 'out' param.
        /// This internal method enables testing of captive portal situations
        /// </summary>
        /// <param name="client"></param>
        /// <param name="errorResult"></param>
        /// <returns></returns>
        internal bool CanGetVersionTableFromWeb(IBloomWebClient client, out UpdateTableLookupResult errorResult)
        {
            errorResult = null;
            try
            {
                Logger.WriteEvent("Channel is '" + ApplicationUpdateSupport.ChannelName + "'");
                Logger.WriteEvent("UpdateVersionTable looking for UpdateVersionTable URL: " + GetUrlOfTable());
                TextContentsOfTable = client.DownloadString(GetUrlOfTable());

                //things like captive portals will return an html page rather than the text file what we asked for, if the user isn't
                //logged in.
                if (TextContentsOfTable.ToLower().Contains("<html"))
                {
                    LogTableContents();
                    var msg = "Internet connection did not allow check for update.";
                    NonFatalProblem.Report(ModalIf.Alpha, PassiveIf.All, msg);                     // hopefully this will just 'toast'
                    errorResult = new UpdateTableLookupResult {
                        URL = string.Empty, Error = new WebException(msg)
                    };
                    return(false);
                }
            }
            catch (WebException e)
            {
                Logger.WriteEvent("***Error in LookupURLOfUpdate: " + e.Message);
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    var resp = e.Response as HttpWebResponse;
                    if (resp != null && resp.StatusCode == HttpStatusCode.NotFound)
                    {
                        Logger.WriteEvent(String.Format("***Error: UpdateVersionTable failed to find a file at {0} (channel='{1}'",
                                                        GetUrlOfTable(), ApplicationUpdateSupport.ChannelName));
                    }
                }
                else if (IsConnectionError(e))
                {
                    Logger.WriteEvent("***Error: UpdateVersionTable could not connect to the server");
                }
                errorResult = new UpdateTableLookupResult()
                {
                    Error = e
                };
                return(false);
            }
            return(true);            // no error yet anyway!
        }
Ejemplo n.º 5
0
 public void ReportFatalMessageWithStackTrace(string message, object[] args)
 {
     NonFatalProblem.ReportSentryOnly(Format(message, args));
 }
Ejemplo n.º 6
0
 public void ReportNonFatalExceptionWithMessage(Exception error, string message, params object[] args)
 {
     NonFatalProblem.ReportSentryOnly(error, message);
 }
Ejemplo n.º 7
0
 public void ReportNonFatalException(Exception exception, IRepeatNoticePolicy policy)
 {
     NonFatalProblem.ReportSentryOnly(exception);
 }
Ejemplo n.º 8
0
 public ErrorResult NotifyUserOfProblem(IRepeatNoticePolicy policy, string alternateButton1Label,
                                        ErrorResult resultIfAlternateButtonPressed, string message)
 {
     NonFatalProblem.ReportSentryOnly(message);
     return(ErrorResult.OK);
 }
Ejemplo n.º 9
0
 public void ReportFatalException(Exception e)
 {
     NonFatalProblem.ReportSentryOnly(e);
 }