Handles Bloom file/folder operations on Amazon Web Services S3 service.
Inheritance: IDisposable
Exemple #1
0
 public BookTransfer(BloomParseClient bloomParseClient, BloomS3Client bloomS3Client, HtmlThumbNailer htmlThumbnailer, BookDownloadStartingEvent bookDownloadStartingEvent)
 {
     this._parseClient          = bloomParseClient;
     this._s3Client             = bloomS3Client;
     _htmlThumbnailer           = htmlThumbnailer;
     _bookDownloadStartingEvent = bookDownloadStartingEvent;
 }
 public BookTransfer(BloomParseClient bloomParseClient, BloomS3Client bloomS3Client, BookThumbNailer htmlThumbnailer, BookDownloadStartingEvent bookDownloadStartingEvent)
 {
     this._parseClient = bloomParseClient;
     this._s3Client = bloomS3Client;
     _thumbnailer = htmlThumbnailer;
     _bookDownloadStartingEvent = bookDownloadStartingEvent;
 }
        public void SetupFixture()
        {
            // Basic setup
            _workFolder = new TemporaryFolder("unittest2");
            var workFolderPath = _workFolder.FolderPath;
            Assert.AreEqual(0, Directory.GetDirectories(workFolderPath).Count(), "Some stuff was left over from a previous test");

            _client = new BloomS3Client(BloomS3Client.UnitTestBucketName);

            // Now do standard upload/download. We save time by making this whole class do one upload/download sequence
            // on the assumption that things that should be uploaded were if they make it through the download process too.
            // Individual tests just compare what was uploaded with what came back through the download.
            // If we want to upload and download to separate (collection) folders, we need another layer for the actual book

            _storageKeyOfBookFolder = Guid.NewGuid().ToString();

            // First create folder to upload from
            var unittestGuid = Guid.NewGuid();
            var srcFolder = new TemporaryFolder(_workFolder, "unittest-src-" + unittestGuid);
            _srcCollectionPath = srcFolder.FolderPath;

            // Then create standard book
            var book = MakeBookIncludingThumbs(srcFolder);

            // Upload standard book
            UploadBook(book);

            // Create folder to download to
            var destFolder = new TemporaryFolder(_workFolder, "unittest-dest-" + unittestGuid);
            _destCollectionPath = destFolder.FolderPath;

            // Download standard book
            DownloadBook();
        }
        public void Setup()
        {
            _workFolder = new TemporaryFolder("unittest");
            var workFolderPath = _workFolder.FolderPath;
            Assert.AreEqual(0, Directory.GetDirectories(workFolderPath).Count(), "Some stuff was left over from a previous test");
            Assert.AreEqual(0, Directory.GetFiles(workFolderPath).Count(), "Some stuff was left over from a previous test");

            _client = new BloomS3Client(BloomS3Client.UnitTestBucketName);
        }
Exemple #5
0
        static int Main(string[] arguments)
        {
            if (arguments.Length != 1)
            {
                Console.WriteLine("Usage: BloomBookUploader path-to-folder-containing-books");
                return 1;
            }
            if (!Directory.Exists(arguments[0]))
            {
                Console.WriteLine(arguments[0]+" not found");
                return 3;
            }

            var t = new Bloom.WebLibraryIntegration.BloomS3Client(BloomS3Client.SandboxBucketName);
            t.UploadBook(Guid.NewGuid().ToString(), arguments[0]);

            return 0;
        }
        public static string UploadBook(string bucketName, string bookZipPath, IProgress progress)
        {
            try
            {
                using(var s3Client = new BloomS3Client(bucketName))
                {
                    var url = s3Client.UploadSingleFile(bookZipPath, progress);
                    progress.WriteMessage("Upload Success");
                    return url;
                }

            }
            catch (WebException e)
            {
                progress.WriteError("There was a problem uploading your book: "+e.Message);
                throw;
            }
            catch (AmazonS3Exception e)
            {
                if (e.Message.Contains("The difference between the request time and the current time is too large"))
                {
                    progress.WriteError(LocalizationManager.GetString("PublishTab.Upload.TimeProblem",
                        "There was a problem uploading your book. This is probably because your computer is set to use the wrong timezone or your system time is badly wrong. See http://www.di-mgt.com.au/wclock/help/wclo_setsysclock.html for how to fix this."));
                }
                else
                {
                    progress.WriteError("There was a problem uploading your book: " + e.Message);
                }
                throw;
            }
            catch (AmazonServiceException e)
            {
                progress.WriteError("There was a problem uploading your book: " + e.Message);
                throw;
            }
            catch (Exception e)
            {
                progress.WriteError("There was a problem uploading your book.");
                progress.WriteError(e.Message.Replace("{", "{{").Replace("}", "}}"));
                progress.WriteVerbose(e.StackTrace);
                throw;
            }
        }
Exemple #7
0
        static int Main(string[] arguments)
        {
            if (arguments.Length != 1)
            {
                Console.WriteLine("Usage: BloomBookUploader path-to-folder-containing-books");
                return(1);
            }
            if (!Directory.Exists(arguments[0]))
            {
                Console.WriteLine(arguments[0] + " not found");
                return(3);
            }

            var t = new Bloom.WebLibraryIntegration.BloomS3Client(BloomS3Client.SandboxBucketName);

            t.UploadBook(Guid.NewGuid().ToString(), arguments[0], new NullProgress());

            return(0);
        }
 public static string UploadBook(string bucketName, string bookZipPath, IProgress progress)
 {
     try
     {
         using (var s3Client = new BloomS3Client(bucketName))
         {
             var url = s3Client.UploadSingleFile(bookZipPath, progress);
             progress.WriteMessage("Upload Success");
             return(url);
         }
     }
     catch (WebException e)
     {
         progress.WriteError("There was a problem uploading your book: " + e.Message);
         throw;
     }
     catch (AmazonS3Exception e)
     {
         if (e.Message.Contains("The difference between the request time and the current time is too large"))
         {
             progress.WriteError(LocalizationManager.GetString("PublishTab.Upload.TimeProblem",
                                                               "There was a problem uploading your book. This is probably because your computer is set to use the wrong timezone or your system time is badly wrong. See http://www.di-mgt.com.au/wclock/help/wclo_setsysclock.html for how to fix this."));
         }
         else
         {
             progress.WriteError("There was a problem uploading your book: " + e.Message);
         }
         throw;
     }
     catch (AmazonServiceException e)
     {
         progress.WriteError("There was a problem uploading your book: " + e.Message);
         throw;
     }
     catch (Exception e)
     {
         progress.WriteError("There was a problem uploading your book.");
         progress.WriteError(e.Message.Replace("{", "{{").Replace("}", "}}"));
         progress.WriteVerbose(e.StackTrace);
         throw;
     }
 }
Exemple #9
0
        static int Main(string[] arguments)
        {
            if (arguments.Length != 1)
            {
                Console.WriteLine("Usage: BloomBookDownloader keyOnAmazonS3");
                return 1;
            }

            var t = new BloomS3Client(BloomS3Client.SandboxBucketName);

            var destinationPath = Path.Combine(Path.GetTempPath(), "BloomBookDownloader");
            if (!Directory.Exists(destinationPath))
            {
                Directory.CreateDirectory(destinationPath);
            }

            t.DownloadBook(arguments[0], destinationPath);

            return 0;
        }
Exemple #10
0
 public BookTransfer(BloomParseClient bloomParseClient, BloomS3Client bloomS3Client)
 {
     this._parseClient = bloomParseClient;
     this._s3Client = bloomS3Client;
 }
Exemple #11
0
 public BookUpload(BloomParseClient bloomParseClient, BloomS3Client bloomS3Client, BookThumbNailer htmlThumbnailer)
 {
     this.ParseClient = bloomParseClient;
     this._s3Client   = bloomS3Client;
     _thumbnailer     = htmlThumbnailer;
 }
Exemple #12
0
 public BookDownload(BloomParseClient bloomParseClient, BloomS3Client bloomS3Client, BookDownloadStartingEvent bookDownloadStartingEvent)
 {
     this._s3Client             = bloomS3Client;
     _bookDownloadStartingEvent = bookDownloadStartingEvent;
 }
Exemple #13
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;
 }