示例#1
0
 private static void DisplayNetworkDownloadProblem(Exception e)
 {
     ShellWindow.Invoke((Action)(() =>
                                 Palaso.Reporting.ErrorReport.NotifyUserOfProblem(e,
                                                                                  LocalizationManager.GetString("Download.GenericDownloadProblemNotice",
                                                                                                                "There was a problem downloading your book."))));
 }
示例#2
0
        public string DownloadFromOrderUrl(string orderUrl, string destPath)
        {
            var decoded     = HttpUtilityFromMono.UrlDecode(orderUrl);
            var bucketStart = decoded.IndexOf(_s3Client.BucketName, StringComparison.InvariantCulture);

            if (bucketStart == -1)
            {
#if DEBUG
                if (decoded.StartsWith(("BloomLibraryBooks")))
                {
                    Palaso.Reporting.ErrorReport.NotifyUserOfProblem(
                        "The book is from bloomlibrary.org, but you are running the DEBUG version of Bloom, which can only use dev.bloomlibrary.org.");
                }
                else
                {
                    throw new ApplicationException("Can't match URL of bucket of the book being downloaded, and I don't know why.");
                }
#else
                if (decoded.StartsWith(("BloomLibraryBooks-Sandbox")))
                {
                    Palaso.Reporting.ErrorReport.NotifyUserOfProblem(
                        "The book is from the testing version of the bloomlibrary, but you are running the RELEASE version of Bloom. The RELEASE build cannot use the 'dev.bloomlibrary.org' site. If you need to do that for testing purposes, set the windows Environment variable 'BloomSandbox' to 'true'.", decoded);
                }
                else
                {
                    throw new ApplicationException(string.Format("Can't match URL of bucket of the book being downloaded {0}, and I don't know why.", decoded));
                }
#endif
                return(null);
            }

            var    s3orderKey = decoded.Substring(bucketStart + _s3Client.BucketName.Length + 1);
            string url        = "unknown";
            string title      = "unknown";
            try
            {
                var metadata = BookMetaData.FromString(_s3Client.DownloadFile(s3orderKey));
                url   = metadata.DownloadSource;
                title = metadata.Title;
                if (_progressDialog != null)
                {
                    _progressDialog.Invoke((Action)(() => { _progressDialog.Progress = 1; }));
                }
                // downloading the metadata is considered step 1.
                var destinationPath = DownloadBook(metadata.DownloadSource, destPath);
                LastBookDownloadedPath = destinationPath;

                Analytics.Track("DownloadedBook-Success",
                                new Dictionary <string, string>()
                {
                    { "url", url }, { "title", title }
                });
                return(destinationPath);
            }
            catch (WebException e)
            {
                DisplayNetworkDownloadProblem(e);
                Analytics.Track("DownloadedBook-Failure",
                                new Dictionary <string, string>()
                {
                    { "url", url }, { "title", title }
                });
                Analytics.ReportException(e);
                return("");
            }
            catch (AmazonServiceException e)
            {
                DisplayNetworkDownloadProblem(e);
                Analytics.Track("DownloadedBook-Failure",
                                new Dictionary <string, string>()
                {
                    { "url", url }, { "title", title }
                });
                Analytics.ReportException(e);
                return("");
            }
            catch (Exception e)
            {
                ShellWindow.Invoke((Action)(() =>
                                            Palaso.Reporting.ErrorReport.NotifyUserOfProblem(e,
                                                                                             LocalizationManager.GetString("PublishTab.Upload.DownloadProblem",
                                                                                                                           "There was a problem downloading your book. You may need to restart Bloom or get technical help."))));
                Analytics.Track("DownloadedBook-Failure",
                                new Dictionary <string, string>()
                {
                    { "url", url }, { "title", title }
                });
                Analytics.ReportException(e);
                return("");
            }
        }