示例#1
0
        /// <summary>
        /// Review: this is fragile and expensive. We're doing real internet traffic and creating real objects on S3 and parse.com
        /// which (to a very small extent) costs us real money. This will be slow. Also, under S3 eventual consistency rules,
        /// there is no guarantee that the data we just created will actually be retrievable immediately.
        /// </summary>
        /// <param name="bookName"></param>
        /// <param name="id"></param>
        /// <param name="uploader"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public Tuple <string, string> UploadAndDownLoadNewBook(string bookName, string id, string uploader, string data, bool isTemplate = false)
        {
            //  Create a book folder with meta.json that includes an uploader and id and some other files.
            var originalBookFolder = MakeBook(bookName, id, uploader, data, true);

            if (isTemplate)
            {
                var metadata = BookMetaData.FromFolder(originalBookFolder);
                metadata.IsSuitableForMakingShells = true;
                metadata.WriteToFolder(originalBookFolder);
            }
            // The files that actually get uploaded omit some of the ones in the folder.
            // The only omitted one that messes up current unit tests is meta.bak
            var filesToUpload = Directory.GetFiles(originalBookFolder).Where(p => !p.EndsWith(".bak") && !p.Contains(BookStorage.PrefixForCorruptHtmFiles));
            int fileCount     = filesToUpload.Count();

            Login();
            //HashSet<string> notifications = new HashSet<string>();

            var progress = new SIL.Progress.StringBuilderProgress();
            var s3Id     = _transfer.UploadBook(originalBookFolder, progress);

            var uploadMessages = progress.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            var expectedFileCount = fileCount + 2;             // should get one per file, plus one for metadata, plus one for book order

#if DEBUG
            ++expectedFileCount;                // and if in debug mode, then plus one for S3 ID
#endif
            Assert.That(uploadMessages.Length, Is.EqualTo(expectedFileCount));
            Assert.That(progress.Text, Does.Contain(
                            LocalizationManager.GetString("PublishTab.Upload.UploadingBookMetadata", "Uploading book metadata",
                                                          "In this step, Bloom is uploading things like title, languages, & topic tags to the bloomlibrary.org database.")));
            Assert.That(progress.Text, Does.Contain(Path.GetFileName(filesToUpload.First())));

            _transfer.WaitUntilS3DataIsOnServer(BloomS3Client.UnitTestBucketName, originalBookFolder);
            var dest = _workFolderPath.CombineForPath("output");
            Directory.CreateDirectory(dest);
            _downloadedBooks.Clear();
            var url           = BookTransfer.BloomS3UrlPrefix + BloomS3Client.UnitTestBucketName + "/" + s3Id;
            var newBookFolder = _transfer.HandleDownloadWithoutProgress(url, dest);

            Assert.That(Directory.GetFiles(newBookFolder).Length, Is.EqualTo(fileCount + 1));             // book order is added during upload

            Assert.That(_downloadedBooks.Count, Is.EqualTo(1));
            Assert.That(_downloadedBooks[0].FolderPath, Is.EqualTo(newBookFolder));
            // Todo: verify that metadata was transferred to Parse.com
            return(new Tuple <string, string>(originalBookFolder, newBookFolder));
        }
        /// <summary>
        /// Review: this is fragile and expensive. We're doing real internet traffic and creating real objects on S3 and parse.com
        /// which (to a very small extent) costs us real money. This will be slow. Also, under S3 eventual consistency rules,
        /// there is no guarantee that the data we just created will actually be retrievable immediately.
        /// </summary>
        /// <param name="bookName"></param>
        /// <param name="id"></param>
        /// <param name="uploader"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public Tuple <string, string> UploadAndDownLoadNewBook(string bookName, string id, string uploader, string data)
        {
            //  Create a book folder with meta.json that includes an uploader and id and some other files.
            var originalBookFolder = MakeBook(bookName, id, uploader, data);
            int fileCount          = Directory.GetFiles(originalBookFolder).Length;

            Login();
            //HashSet<string> notifications = new HashSet<string>();

            var progress = new Palaso.Progress.StringBuilderProgress();
            var s3Id     = _transfer.UploadBook(originalBookFolder, progress);

            var uploadMessages = progress.Text.Split(new string[] { "Uploading" }, StringSplitOptions.RemoveEmptyEntries);

            Assert.That(uploadMessages.Length, Is.EqualTo(fileCount + 2));             // should get one per file, plus one for metadata, plus one for book order
            Assert.That(progress.Text.Contains("Uploading book metadata"));
            Assert.That(progress.Text.Contains("Uploading " + Path.GetFileName(Directory.GetFiles(originalBookFolder).First())));

            _transfer.WaitUntilS3DataIsOnServer(originalBookFolder);
            var dest = _workFolderPath.CombineForPath("output");

            Directory.CreateDirectory(dest);
            _downloadedBooks.Clear();
            var newBookFolder = _transfer.DownloadBook(s3Id, dest);

            Assert.That(Directory.GetFiles(newBookFolder).Length, Is.EqualTo(fileCount + 1));             // book order is added during upload

            Assert.That(_downloadedBooks.Count, Is.EqualTo(1));
            Assert.That(_downloadedBooks[0].FolderPath, Is.EqualTo(newBookFolder));
            // Todo: verify that metadata was transferred to Parse.com
            return(new Tuple <string, string>(originalBookFolder, newBookFolder));
        }