public void BookWithPeriodInTitle_DoesNotGetTruncatedPdfName() { #if __MonoCS__ Assert.That(BookUpload.UploadPdfPath("/somewhere/Look at the sky. What do you see"), Is.EqualTo("/somewhere/Look at the sky. What do you see/Look at the sky. What do you see.pdf")); #else Assert.That(BookUpload.UploadPdfPath(@"c:\somewhere\Look at the sky. What do you see"), Is.EqualTo(@"c:\somewhere\Look at the sky. What do you see\Look at the sky. What do you see.pdf")); #endif }
internal string UploadOneBook(BookInstance book, LogBox progressBox, PublishView publishView, bool excludeMusic, out string parseId) { using (var tempFolder = new TemporaryFolder(Path.Combine("BloomUpload", Path.GetFileName(book.FolderPath)))) { BookUpload.PrepareBookForUpload(ref book, _publishModel.BookServer, tempFolder.FolderPath, progressBox); var bookParams = new BookUploadParameters { ExcludeMusic = excludeMusic, PreserveThumbnails = false, }; return(_uploader.FullUpload(book, progressBox, publishView, bookParams, out parseId)); } }
public BloomLibraryPublishModel(BookUpload uploader, BookInstance book, PublishModel model) { Book = book; _uploader = uploader; _publishModel = model; _licenseMetadata = Book.GetLicenseMetadata(); // This is usually redundant, but might not be on old books where the license was set before the new // editing code was written. Book.SetMetadata(_licenseMetadata); _license = _licenseMetadata.License; EnsureBookAndUploaderId(); }
public void Setup() { _thisTestId = Guid.NewGuid().ToString().Replace('-', '_'); _workFolder = new TemporaryFolder("unittest-" + _thisTestId); _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"); // Todo: Make sure the S3 unit test bucket is empty. // Todo: Make sure the parse.com unit test book table is empty _parseClient = new BloomParseClientTestDouble(_thisTestId); _htmlThumbNailer = new HtmlThumbNailer(NavigationIsolator.GetOrCreateTheOneNavigationIsolator()); _uploader = new BookUpload(_parseClient, new BloomS3Client(BloomS3Client.UnitTestBucketName), new BookThumbNailer(_htmlThumbNailer)); _downloader = new BookDownload(_parseClient, new BloomS3Client(BloomS3Client.UnitTestBucketName), new BookDownloadStartingEvent()); _downloader.BookDownLoaded += (sender, args) => _downloadedBooks.Add(args.BookDetails); }
public void DuplicateIdTest() { // SUT (use workFolder as the root directory) BookUpload.BulkRepairInstanceIds(_workFolderPath); // Verification var book1 = _foldersToDispose[3]; var book2 = _foldersToDispose[4]; var book3 = _foldersToDispose[5]; var book4 = _foldersToDispose[6]; var book5 = _foldersToDispose[7]; Assert.That(GetInstanceIdFromMetadataFile(book1), Is.Not.EqualTo(_guid1), "book1 should have changed guid1"); Assert.That(GetInstanceIdFromMetadataFile(book2), Is.Not.EqualTo(_guid1), "book2 should have changed guid1"); Assert.That(GetInstanceIdFromMetadataFile(book1), Is.Not.EqualTo(GetInstanceIdFromMetadataFile(book2)), "book1 should have different guid than book2"); Assert.That(GetInstanceIdFromMetadataFile(book3), Is.EqualTo(_guid1), "book3 should have guid1"); Assert.That(GetInstanceIdFromMetadataFile(book4), Is.EqualTo(_guid2), "book4 should have guid2"); Assert.That(GetInstanceIdFromMetadataFile(book4), Is.Not.EqualTo(GetInstanceIdFromMetadataFile(book5)), "book4 should have different guid than book5"); }
protected void BookUploadBtn_Click(object sender, EventArgs e) { string filename = ""; if (BookUpload.FileName != null) { filename = BookUpload.FileName; BookUpload.SaveAs(Server.MapPath("~/LMS/Books/" + filename)); } int crsid = int.Parse(Request.QueryString["course"]); string booktitle = bookTitle.Text; Reference_Books_tbl rbs = new Reference_Books_tbl { CourseID = crsid, Reference_Book = booktitle, Description = bookdescription.Text, Book_path = filename }; DBFunctions db = new DBFunctions(); db.addbooks(rbs); Response.Redirect("UploadAssignments.aspx?course=" + Request.QueryString["course"] + "&tab=books"); }
public void DuplicateIdTest() { var book2 = _foldersToDispose[4]; // Although book3 is set up to be older than book1 and book2, // we are simulating a situation where book2 is in a TC and its ID // cannot be changed. Func <string, bool> okToChangeId = (string folderName) => folderName != book2.FolderPath; // SUT (use workFolder as the root directory) BookUpload.BulkRepairInstanceIds(_workFolderPath, okToChangeId); // Verification var book1 = _foldersToDispose[3]; var book3 = _foldersToDispose[5]; var book4 = _foldersToDispose[6]; var book5 = _foldersToDispose[7]; Assert.That(GetInstanceIdFromMetadataFile(book1), Is.Not.EqualTo(_guid1), "book1 should have changed guid1"); Assert.That(GetInstanceIdFromMetadataFile(book2), Is.EqualTo(_guid1), "book2 should not have changed guid1"); Assert.That(GetInstanceIdFromMetadataFile(book3), Is.Not.EqualTo(_guid1), "book3 should have changed guid1"); Assert.That(GetInstanceIdFromMetadataFile(book1), Is.Not.EqualTo(GetInstanceIdFromMetadataFile(book3)), "the two changed IDs for guid1 should be different from each other"); Assert.That(GetInstanceIdFromMetadataFile(book4), Is.EqualTo(_guid2), "book4 should have guid2"); Assert.That(GetInstanceIdFromMetadataFile(book4), Is.Not.EqualTo(GetInstanceIdFromMetadataFile(book5)), "book4 should have different guid than book5"); }
public static int Handle(UploadParameters options) { try { Console.OutputEncoding = Encoding.UTF8; } catch (Exception) { // swallow. The above throws a handle error when run in Visual Studio } IsUploading = true; // -u user, and <path> are all required, so they must contain strings. // -d destination has a default value, so it also must contain a string. options.Path = options.Path.TrimEnd(new[] { '/', '\\', System.IO.Path.PathSeparator }); // remove any trailing slashes // validate the value for the upload destination. options.Dest = options.Dest.ToLowerInvariant(); switch (options.Dest) { case UploadDestination.DryRun: case UploadDestination.Development: case UploadDestination.Production: break; default: Console.WriteLine($"Error: if present, upload destination (-d) must be one of {UploadDestination.DryRun}, {UploadDestination.Development}, or {UploadDestination.Production}"); return(1); } BookUpload.Destination = options.Dest; // must be set before calling SetupErrorHandling() (or BloomParseClient constructor) // This task will be all the program does. We need to do enough setup so that // the upload code can work, then tear it down. Program.SetUpErrorHandling(); try { using (var applicationContainer = new ApplicationContainer()) { Program.SetUpLocalization(applicationContainer); LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false); var singleBookUploader = new BookUpload(new BloomParseClient(), ProjectContext.CreateBloomS3Client(), applicationContainer.BookThumbNailer); var uploader = new BulkUploader(singleBookUploader); // Since Bloom is not a normal console app, when run from a command line, the new command prompt // appears at once. The extra newlines here are attempting to separate this from our output. switch (options.Dest) { case UploadDestination.DryRun: Console.WriteLine($"\nThe following actions would happen if you set destination to '{(BookUpload.UseSandboxByDefault ? UploadDestination.Development : UploadDestination.Production)}'."); break; case UploadDestination.Development: Console.WriteLine("\nThe upload will go to dev.bloomlibrary.org."); break; case UploadDestination.Production: Console.WriteLine("\nThe upload will go to bloomlibrary.org."); break; } Console.WriteLine("\nStarting upload..."); uploader.BulkUpload(applicationContainer, options); Console.WriteLine(("\nBulk upload complete.\n")); } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); return(1); } }