DownloadFile() public méthode

public DownloadFile ( string bucketName, string storageKeyOfFile ) : string
bucketName string
storageKeyOfFile string
Résultat string
Exemple #1
0
        internal bool CheckAgainstHashFileOnS3(string currentHashes, string bookFolder, IProgress progress)
        {
            string hashInfoOnS3 = null;

            try
            {
                if (!IsBookOnServer(bookFolder))
                {
                    return(false);
                }
                var bkInfo = new BookInfo(bookFolder, true);
                var s3id   = S3BookId(bkInfo.MetaData);
                var key    = s3id + BloomS3Client.kDirectoryDelimeterForS3 + Path.GetFileName(bookFolder) + BloomS3Client.kDirectoryDelimeterForS3 + UploadHashesFilename;
                hashInfoOnS3 = _s3Client.DownloadFile(UseSandbox ? BloomS3Client.SandboxBucketName : BloomS3Client.ProductionBucketName, key);
            }
            catch
            {
                hashInfoOnS3 = "";                      // probably file doesn't exist because it hasn't yet been uploaded
            }

#if DEBUG
            if (currentHashes != hashInfoOnS3)
            {
                progress.WriteMessage("local hash");
                progress.WriteMessage(currentHashes);
                progress.WriteMessage("s3 hash");
                progress.WriteMessage(hashInfoOnS3);
            }
#endif
            return(currentHashes == hashInfoOnS3);
        }
        private void GetUrlAndTitle(string bucket, string s3orderKey, ref string url, ref string title)
        {
            int index = s3orderKey.IndexOf('/');

            if (index > 0)
            {
                index = s3orderKey.IndexOf('/', index + 1);                 // second slash
            }
            if (index > 0)
            {
                url = s3orderKey.Substring(0, index);
            }
            if (url == "unknown" || string.IsNullOrWhiteSpace(title) || title == "unknown")
            {
                // not getting the info we want in the expected way. This old algorithm may work.
                var metadata = BookMetaData.FromString(_s3Client.DownloadFile(s3orderKey, bucket));
                url   = metadata.DownloadSource;
                title = metadata.Title;
            }
        }
Exemple #3
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("");
            }
        }
Exemple #4
0
 private static bool TryLookupUrl(UrlType urlType, out string url)
 {
     url = null;
     // Once the internet has been found missing, don't bother trying it again for the duration of the program.
     if (!_internetAvailable)
         return false;
     try
     {
         using (var s3Client = new BloomS3Client(null))
         {
             s3Client.Timeout = TimeSpan.FromMilliseconds(2500.0);
             s3Client.ReadWriteTimeout = TimeSpan.FromMilliseconds(3000.0);
             s3Client.MaxErrorRetry = 1;
             var jsonContent = s3Client.DownloadFile(BloomS3Client.BloomDesktopFiles, kUrlLookupFileName);
             Urls urls = JsonConvert.DeserializeObject<Urls>(jsonContent);
             url = urls.GetUrlById(urlType.ToJsonPropertyString());
             if (!string.IsNullOrWhiteSpace(url))
                 return true;
             Logger.WriteEvent("Unable to look up URL type " + urlType);
         }
     }
     catch (Exception e)
     {
         _internetAvailable = false;
         Logger.WriteEvent("Exception while attempting look up of URL type " + urlType + ": " + e);
     }
     return false;
 }