public void LookupURLOfUpdateInternal_NotBehindCaptivePortal_Works()
        {
            var t = new UpdateVersionTable();

            t.URLOfTable     = "http://bloomlibrary.org/channels/UpgradeTableAlpha.txt";
            t.RunningVersion = Version.Parse("2.0.2000");
            //the full result would normally be something like
            //"https://s3.amazonaws.com/bloomlibrary.org/deltasAlpha"
            //check that feeding this a normal WebClient doesn't find an error.
            var client = new BloomWebClient();
            TableLookupResult dummy;

            Assert.IsTrue(t.CanGetVersionTableFromWeb(client, out dummy));
        }
Example #2
0
        /// <summary>
        /// Note! This will propagate network exceptions, so client can catch them and warn or not warn the user.
        /// </summary>
        /// <returns></returns>
        public UpdateTableLookupResult LookupURLOfUpdate(bool forceReload = false)
        {
            if (string.IsNullOrEmpty(TextContentsOfTable) || forceReload)
            {
                Logger.WriteEvent("Enter LookupURLOfUpdate()");
                var client = new BloomWebClient();
                {
                    UpdateTableLookupResult errorResult;
                    if (!CanGetVersionTableFromWeb(client, out errorResult))
                    {
                        return(errorResult);
                    }
                }
            }
            if (RunningVersion == default(Version))
            {
                RunningVersion = Assembly.GetExecutingAssembly().GetName().Version;
            }

            var parsingErrorMsg = String.Empty;

            try
            {
                //NB Programmers: don't change this to some OS-specific line ending, this is  file read by both OS's. '\n' is common to files edited on linux and windows.
                foreach (var line in TextContentsOfTable.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (line.TrimStart().StartsWith("#"))
                    {
                        continue;                         //comment
                    }
                    var parts = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length != 3)
                    {
                        Logger.WriteEvent("***Error: UpdateVersionTable could not parse line {0} of this updateTableContent:", line);
                        LogTableContents();
                        throw new ApplicationException(line);
                    }
                    var lower = Version.Parse(parts[0]);
                    var upper = Version.Parse(parts[1]);
                    if (lower <= RunningVersion && upper >= RunningVersion)
                    {
                        return new UpdateTableLookupResult {
                                   URL = parts[2].Trim()
                        }
                    }
                    ;
                }
                parsingErrorMsg = string.Format("{0} contains no record for this version of Bloom", GetUrlOfTable());
            }
            catch (ApplicationException e)
            {
                // BL-2654 Failure when reading upgrade table should not give a crash
                // In this case, a line of the UpdateVersionTable was not parseable
                // Put a message in the log and don't upgrade (and return a message that will get into a 'toast')
                parsingErrorMsg = "Could not parse a line of the UpdateVersionTable" + e.Message;
                Logger.WriteEvent(parsingErrorMsg);
            }
            catch (ArgumentException e)
            {
                // BL-2654 Failure when reading upgrade table should not give a crash
                // In this case, a version number in the UpdateVersionTable was not parseable
                // Put a message in the log and don't upgrade (and return a message that will get into a 'toast')
                parsingErrorMsg = "Could not parse a version number in the UpdateVersionTable" + e.Message;
                Logger.WriteEvent(parsingErrorMsg);
            }
            return(new UpdateTableLookupResult {
                URL = String.Empty, Error = new WebException(parsingErrorMsg)
            });
        }