コード例 #1
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!
        }
コード例 #2
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 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!
        }