private void UploadBooks() { var uploadOptions = new UploadOptions { Verbose = _options.Verbose, VeryVerbose = _options.VeryVerbose, SingleBookshelfLevel = true, BloomExe = _options.BloomExe, BookShelfContainer = TrimBookShelfContainerToBaseFolder(), UploadUser = _options.UploadUser, UploadPassword = _options.UploadPassword }; if (_options.DryRun || _options.DoNotUpload) { var command = new StringBuilder(); command.Append("RoseGarden upload -s"); if (uploadOptions.VeryVerbose) { command.Append(" -V"); } else if (uploadOptions.Verbose) { command.Append(" -v"); } command.AppendFormat(" -b \"{0}\"", uploadOptions.BloomExe); command.AppendFormat(" \"{0}\"", uploadOptions.BookShelfContainer); Console.WriteLine(command); return; } Console.WriteLine("INFO: trying to upload the books."); var upload = new UploadToBloomLibrary(uploadOptions); if (upload.RunUpload() == 0) { Console.WriteLine("INFO: uploading the books appears to have succeeded."); } else { Console.WriteLine("WARNING: uploading the books appears to have failed."); } }
public int RunFix() { if (!VerifyOptions()) { return(1); } var client = new ParseClient(_options.UploadUser, _options.UploadPassword); string importedFilter = "{\"importedBookSourceUrl\": {\"$regex\": \".\"}}"; IEnumerable <Book> bookList = client.GetBooks(importedFilter, new[] { "uploader" }); var bookCount = 0; var fixedCount = 0; foreach (var book in bookList) { ++bookCount; if (_options.VeryVerbose) { Console.WriteLine("DEBUG: For \"{0}\", tags = [{1}]", book.Title, String.Join(", ", book.Tags).TrimEnd(',', ' ')); } if (book.Tags == null || book.Tags.Count == 0) { continue; } bool updateTags = false; if (book.Tags.Contains("system:Incoming")) { updateTags = true; book.Tags.Remove("system:Incoming"); } var newTags = new List <string>(); foreach (var tag in book.Tags) { if (tag.StartsWith("level:Level ", StringComparison.InvariantCulture)) { var newTag = UploadToBloomLibrary.GetTagForLrmiReadingLevel(tag.Substring(6)); newTags.Add(newTag); updateTags = true; } else if (tag.StartsWith("level:ደረጃ ", StringComparison.InvariantCulture)) { var newTag = UploadToBloomLibrary.GetTagForLrmiReadingLevel(tag.Substring(6)); newTags.Add(newTag); updateTags = true; } else if (tag == "level:Read aloud" || tag == "level:ጮክ ብለህ አንብብ") { var newTag = UploadToBloomLibrary.GetTagForLrmiReadingLevel(tag.Substring(6)); newTags.Add(newTag); updateTags = true; } else if (tag == "level:Decodable" || tag == "level:መፍታት የሚችል") { var newTag = UploadToBloomLibrary.GetTagForLrmiReadingLevel(tag.Substring(6)); newTags.Add(newTag); updateTags = true; } else { newTags.Add(tag); } } if (updateTags) { ++fixedCount; var updateJson = new StringBuilder("{ \"updateSource\":\"[email protected]\", \"tags\":["); var sep = ""; foreach (var tag in newTags) { updateJson.AppendFormat("{0}\"{1}\"", sep, tag); sep = ","; } updateJson.Append("] }"); if (_options.VeryVerbose) { Console.WriteLine("DEBUG: For \"{0}\", fix tags json = {1}", book.Title, updateJson); } var response = client.UpdateObject("books", book.ObjectId, updateJson.ToString()); if (response.StatusCode != System.Net.HttpStatusCode.OK) { Console.WriteLine("WARNING: updating the book table for \"{0}\" failed: {1}", book.Title, response.Content); } } } if (_options.Verbose) { Console.WriteLine("INFO: fixed tags in {0} of {1} books.", fixedCount, bookCount); } return(0); }