public void InitBook(string title) { if (books == null) { LoadLibrary(); } if (!books.Contains(title)) { // throw error } BookFormat bookType = BookInfoMapper.DeserializeInfo(title).format; switch (bookType) { case BookFormat.TXT: InitTxtBasedBook(title); break; default: Debug.Log("Invalid book format"); return; } }
public static IDrmProcessor Get(BookFormat format, PrivateKeyScheme scheme) { if (scheme == PrivateKeyScheme.None) return PassThrough.Value; switch (format) { case BookFormat.EPub: switch (scheme) { case PrivateKeyScheme.Adept: return AdeptEPub.Value; case PrivateKeyScheme.Kobo: case PrivateKeyScheme.KoboNone: return KoboEPub.Value; default: throw new NotSupportedException("Unsupported combination of book format and DRM scheme."); } case BookFormat.EReader: switch (scheme) { default: throw new NotSupportedException("Unsupported combination of book format and DRM scheme."); } default: throw new NotSupportedException("Unsupported book format."); } }
// Perform some initial work then delegate the remaining tasks to specific methods based on book format public void Import(string path) { BookFormat bookFormat = DetermineFormat(path); string title = GetTitleFromPath(path); CurrentBookTitle = title; if (DoesLibraryContain(title)) { return; // todo - reimport or skip? } switch (bookFormat) { case BookFormat.TXT: ImportDotText(path); break; case BookFormat.PDF: Config config = Config.Instance; if (config.PdfImportAsImages) { ImportPdf(path); } else { ImportPdfInteractive(path); } break; default: throw new InvalidBookFormatException("Unable to determine book format for path " + path); } UpdateLib(title); }
public async Task <IActionResult> Edit(int id, [Bind("BookFormatID,FormatDescription")] BookFormat bookFormat) { if (id != bookFormat.BookFormatID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(bookFormat); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookFormatExists(bookFormat.BookFormatID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(bookFormat)); }
public static IDrmProcessor Get(BookFormat format, PrivateKeyScheme scheme) { if (scheme == PrivateKeyScheme.None) { return(PassThrough.Value); } switch (format) { case BookFormat.EPub: switch (scheme) { case PrivateKeyScheme.Adept: return(AdeptEPub.Value); case PrivateKeyScheme.Kobo: case PrivateKeyScheme.KoboNone: return(KoboEPub.Value); default: throw new NotSupportedException("Unsupported combination of book format and DRM scheme."); } case BookFormat.EReader: switch (scheme) { default: throw new NotSupportedException("Unsupported combination of book format and DRM scheme."); } default: throw new NotSupportedException("Unsupported book format."); } }
public BookInfo(string title, BookFormat format, string origin) { this.title = title; this.format = format; this.origin = origin; this.thumbnailPath = ""; }
private static void Main(string[] args) { var inPath = args.Length > 0 ? args : new[] { @".\*" }; Console.WriteLine("Removing DRM..."); var inFiles = GetInFiles(inPath); foreach (var file in inFiles) { string bookName = Path.GetFileNameWithoutExtension(file); Console.Write(bookName.Substring(0, Math.Min(40, bookName.Length))); BookFormat format = FormatGuesser.Guess(file); Logger.PrintResult(format); var scheme = SchemeGuesser.Guess(file, format); Logger.PrintResult(scheme); if (format == BookFormat.Unknown) { Logger.PrintResult(ProcessResult.Skipped); Console.WriteLine(); continue; } ProcessResult processResult; string error = null; string outFileName = bookName; try { var processor = DrmProcessorFactory.Get(format, scheme); var data = File.ReadAllBytes(file); var result = processor.Strip(data, file); var outDir = Path.Combine(Path.GetDirectoryName(file), "out"); if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } outFileName = processor.GetFileName(file).ReplaceInvalidChars(); var outFilePath = Path.Combine(outDir, outFileName); File.WriteAllBytes(outFilePath, result); processResult = ProcessResult.Success; } catch (Exception e) { error = e.Message; processResult = ProcessResult.Fail; } Logger.PrintResult(processResult); Logger.PrintResult(outFileName); if (processResult == ProcessResult.Fail) { Console.WriteLine("\tError: " + error); } } Console.WriteLine("Done."); }
public static void SerializeInfo(string outputPath, BookFormat bookType, string location, string title) { BookInfo bookInfo = new BookInfo(title, bookType, location); var serializer = new SerializerBuilder().Build(); var yaml = serializer.Serialize(bookInfo); File.WriteAllText(outputPath, yaml); }
public void AddFormat(BookFormat format) { this.AvailableFormats = this.AvailableFormats ?? new System.Collections.Generic.List <BookFormat>(); if (!this.AvailableFormats.Contains(format)) { this.AvailableFormats.Add(format); } }
public void Formating_ReturnsFormatedString(string format, string expectedResult) { Book testBook = new Book("978-0-7356-6745-7", "Jeffrey Richter", "CLR via C#", "Microsoft Press", 2012, 826, 29.99m); BookFormat bookFormat = new BookFormat(); string result = bookFormat.Format(format, testBook, null); Assert.AreEqual(expectedResult, result); }
public static PrivateKeyScheme Guess(string filePath, BookFormat format) { switch (format) { case BookFormat.EPub: return Epub.GuessScheme(filePath); default: return PrivateKeyScheme.Unknown; } }
private async Task ProcessBookAsync(Document document, long chatId, BookFormat desiredFormat) { string fileName = document.FileName; Message loadingMessage = await SendLoadingMessageAsync(); using var tempFiles = new TempFiles(); try { Book originalBook = await DownloadOriginalBookAsync(document); tempFiles.Add(originalBook.FilePath); Book convertedBook = await ConvertBookAsync(desiredFormat, originalBook); tempFiles.Add(convertedBook.FilePath); await DeleteLoadingMessageAsync(loadingMessage); if (convertedBook.Equals(originalBook)) { await this.bot.SendTextMessageAsync(chatId, $"Your book *{originalBook.Title}* is already good!", ParseMode.Markdown); } else { await using Stream output = convertedBook.Content(); await this.bot.SendDocumentAsync(chatId, new InputOnlineFile(output, $"{convertedBook.Title}{convertedBook.Format}"), $"Here you go! Your *{convertedBook.Title}* is ready. Enjoy.", ParseMode.Markdown); } } catch (Exception exception) { Log.Error(exception, $"Exception happened when converting {document.FileId}"); await DeleteLoadingMessageAsync(loadingMessage); await this.bot.SendTextMessageAsync(chatId, $"Sorry, something went wrong with *{fileName}*. Try sending the book again.", ParseMode.Markdown); } Task <Message> SendLoadingMessageAsync() { return(this.bot.SendTextMessageAsync(chatId, $"Wait a bit. My dwarfs are working on *{fileName}*", ParseMode.Markdown)); } Task DeleteLoadingMessageAsync(Message message) { return(message != null ? this.bot.DeleteMessageAsync(chatId, message.MessageId) : Task.CompletedTask); } }
public static PrivateKeyScheme Guess(string filePath, BookFormat format) { switch (format) { case BookFormat.EPub: return(Epub.GuessScheme(filePath)); default: return(PrivateKeyScheme.Unknown); } }
public async Task <IActionResult> Create([Bind("BookFormatID,FormatDescription")] BookFormat bookFormat) { if (ModelState.IsValid) { _context.Add(bookFormat); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bookFormat)); }
public async Task <ActionResult> CreateBookFormatAsync([FromBody] BookFormat bookFormat) { if (string.IsNullOrEmpty(bookFormat.Type)) { return(BadRequest("Book format type should not be empty")); } _catalogContext.BookFormats.Add(bookFormat); await _catalogContext.SaveChangesAsync(); return(CreatedAtAction(nameof(BookFormatByIdAsync), new { id = bookFormat.Id }, bookFormat)); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { BookFormat obj = (BookFormat)value; if (obj == BookFormat.EBook) { return(""); } else { return("Gray"); } }
public ActionResult Delete(string Id) { BookFormat bookFormatToDelete = context.Find(Id); if (bookFormatToDelete == null) { return(HttpNotFound()); } else { return(View(bookFormatToDelete)); } }
public ActionResult Edit(string Id) { BookFormat bookFormat = context.Find(Id); if (bookFormat == null) { return(HttpNotFound()); } else { return(View(bookFormat)); } }
private async Task <Book> DownloadOriginalBookAsync(Document document) { string fileName = document.FileName; string originalBookPath = Path.Combine(this.fileStorage, $"{Guid.NewGuid().ToString()}{Path.GetExtension(fileName)}"); await using Stream input = System.IO.File.OpenWrite(originalBookPath); File documentFile = await this.bot.GetFileAsync(document.FileId); await this.bot.DownloadFileAsync(documentFile.FilePath, input); return(new Book(Path.GetFileNameWithoutExtension(fileName), BookFormat.FromExtension(Path.GetExtension(fileName)), originalBookPath)); }
public ActionResult Create(BookFormat bookFormat) { if (!ModelState.IsValid) { return(View(bookFormat)); } else { context.Insert(bookFormat); context.Commit(); return(RedirectToAction("Index")); } }
public ActionResult ConfirmDelete(string Id) { BookFormat bookFormatToDelete = context.Find(Id); if (bookFormatToDelete == null) { return(HttpNotFound()); } else { context.Delete(Id); context.Commit(); return(RedirectToAction("Index")); } }
internal static void PrintResult(BookFormat format) { string result = format.ToString(); ConsoleColor? color; switch (format) { case BookFormat.EPub: case BookFormat.EReader: color = ConsoleColor.Green; break; default: color = ConsoleColor.Red; break; } PrintResult(result, 40, color); }
private static async Task <Book> ConvertBookAsync(BookFormat desiredFormat, Book originalBook) { IBookConverter?converter = CreateConverter(); if (converter == null) { throw new NotSupportedException($"No converter for {desiredFormat}"); } using MeasuredOperation operation = new MeasuredOperation($"Converting {originalBook.Title} to {desiredFormat.Name}"); return(await converter.ConvertAsync(originalBook)); IBookConverter?CreateConverter() { SupportedFormats.TryGetValue(desiredFormat, out IBookConverter? bookConverter); return(bookConverter); } }
public BookItems(string barcode, bool isReferenceOnly, DateTime borrowed, DateTime dueDate, double price, BookFormat format, BookStatus status, DateTime dateOfPurchase, DateTime publicationDate, Rack placedAt, string ISBN, string title, string subject, string publisher, Language language, int noOfPages, List <string> authors) : base(ISBN, title, subject, publisher, language, noOfPages, authors) { _barcode = barcode; _isReferenceOnly = isReferenceOnly; _borrowed = borrowed; _dueDate = dueDate; _price = price; _format = format; _status = status; _dateOfPurchase = dateOfPurchase; _publicationDate = publicationDate; _placedAt = placedAt; }
internal static void PrintResult(BookFormat format) { string result = format.ToString(); ConsoleColor?color; switch (format) { case BookFormat.EPub: case BookFormat.EReader: color = ConsoleColor.Green; break; default: color = ConsoleColor.Red; break; } PrintResult(result, 40, color); }
/// <summary> /// Converts book using Calibre /// </summary> /// <param name="source">Source book</param> /// <param name="targetFormat">Target format file extension (e.g. .mobi)</param> /// <param name="arguments">Additional Calibre command line arguments</param> /// <returns>Converted book</returns> public static async Task <Book> ConvertAsync(Book source, BookFormat targetFormat, string arguments) { string?fileName = Path.GetFileNameWithoutExtension(source.FilePath); if (source.Format.Equals(targetFormat)) { return(source); } string? directoryName = Path.GetDirectoryName(source.FilePath); string outputPath = Path.Combine(directoryName ?? string.Empty, $"{fileName}{targetFormat}"); ProcessResults result = await ProcessEx.RunAsync("ebook-convert", $"{source.FilePath} {outputPath} {arguments}"); Log.Information("{@Output}", result.StandardOutput); if (result.StandardError.Any()) { Log.Error("{@Output}", result.StandardError); } return(new Book(source.Title, targetFormat, outputPath)); }
public async Task HandleCallbackAsync(CallbackQuery callback) { Message documentMessage = callback.Message.ReplyToMessage; if (documentMessage == null || !documentMessage.IsDocument()) { Log.Information("Unexpected original message {@Message}", documentMessage); return; } BookFormat?desiredFormat = BookFormat.TryParse(callback.Data); if (desiredFormat == null) { Log.Error("Can't parse callback {@Callback}", callback); return; } long chatId = documentMessage.Chat.Id; await this.bot.DeleteMessageAsync(chatId, callback.Message.MessageId); await ProcessBookAsync(documentMessage.Document, chatId, desiredFormat); }
IntPtr BookEngineInterface.BEIDocViewCreate(string fname) { BookFormat newFormat = getFormatFromName(fname); if ((newFormat != format) || (handle == IntPtr.Zero)) { if (handle != IntPtr.Zero) { switch (format) { // TODO case BookFormat.coolreader: // cri.BEIReleaseHandle (handle); break; case BookFormat.poppler: // pop.BEIReleaseHandle (handle); break; } } switch (newFormat) { case BookFormat.coolreader: // Create a book with a default font size. handle = cri.BEIDocViewCreate(fname); Debug.Log("CRI Handle " + handle); break; case BookFormat.poppler: // Create a book with a default font size. handle = pop.BEIDocViewCreate(fname); Debug.Log("Poppler Handle " + handle); break; } format = newFormat; } return(handle); }
public ActionResult Edit(BookFormat bookFormat, string Id) { BookFormat bookFormatToEdit = context.Find(Id); if (bookFormat == null) { return(HttpNotFound()); } else { if (!ModelState.IsValid) { return(View(bookFormat)); } bookFormatToEdit.Format = bookFormat.Format; context.Commit(); return(RedirectToAction("Index")); } }
public ActionResult Create() { BookFormat bookFormat = new BookFormat(); return(View(bookFormat)); }
public record Book(string ISBN, string Title, string Author, BookFormat Format, int Pages, bool IsPublished = true);
public static void Initialize(BookContext context) { context.Database.EnsureCreated(); if (context.Authors.Any()) { return; // DB has been seeded } var authors = new Author[] { new Author { AuthorFirstName = "Kira", AuthorLastName = "Cass" }, new Author { AuthorFirstName = "R.J", AuthorLastName = "Palacio" } }; foreach (Author s in authors) { context.Authors.Add(s); } context.SaveChanges(); var publisher = new Publisher[] { new Publisher { PublisherName = Publisher.editorial.RocaEditorial }, new Publisher { PublisherName = Publisher.editorial.Oceano } }; foreach (Publisher s in publisher) { context.publishers.Add(s); } context.SaveChanges(); var format = new BookFormat[] { new BookFormat { FormatDescription = Format.EBUP }, new BookFormat { FormatDescription = Format.PDF } }; foreach (BookFormat s in format) { context.BookFormats.Add(s); } context.SaveChanges(); var category = new Category[] { new Category { CategoryDescription = Categories.Drama }, new Category { CategoryDescription = Categories.Romance } }; foreach (Category s in category) { context.Categories.Add(s); } context.SaveChanges(); var BookTitles = new BookTitle[] { new BookTitle { ISBN_Number = 1234, Title = "La seleccion", PublisherID = publisher.Single(i => i.PublisherName == Publisher.editorial.RocaEditorial).PublisherID, Published = DateTime.Parse("2007-09-01"), BookFormatID = format.Single(i => i.FormatDescription == Format.EBUP).BookFormatID, Pages = 234, Price = 459, Comments = "" }, new BookTitle { ISBN_Number = 4321, Title = "La leccion de august", PublisherID = publisher.Single(i => i.PublisherName == Publisher.editorial.Oceano).PublisherID, Published = DateTime.Parse("2006-11-11"), BookFormatID = format.Single(i => i.FormatDescription == Format.PDF).BookFormatID, Pages = 347, Price = 255, Comments = "" } }; /* foreach (BookTitle s in BookTitles) * { * context.BookTitles.Add(s); * } * context.SaveChanges();*/ foreach (BookTitle e in BookTitles) { var bookindatabase = context.BookTitles.Where( s => s.Publisher.PublisherID == e.PublisherID && s.BookFormat.BookFormatID == e.BookFormatID).SingleOrDefault(); if (bookindatabase == null) { context.BookTitles.Add(e); } } context.SaveChanges(); var AuthorBookTitle = new Book_Author[] { new Book_Author { AuthorID = authors.Single(i => i.AuthorLastName == "Cass").AuthorID, ISBN_Number = BookTitles.Single(i => i.Title == "La seleccion").ISBN_Number }, new Book_Author { AuthorID = authors.Single(i => i.AuthorLastName == "Palacio").AuthorID, ISBN_Number = BookTitles.Single(i => i.Title == "La leccion de august").ISBN_Number } }; foreach (Book_Author s in AuthorBookTitle) { context.Book_Authors.Add(s); } context.SaveChanges(); var BooksCategory = new BookCategory[] { new BookCategory { CategoryID = category.Single(i => i.CategoryDescription == Categories.Drama).CategoryID, ISBN_Number = BookTitles.Single(i => i.Title == "La seleccion").ISBN_Number }, new BookCategory { CategoryID = category.Single(i => i.CategoryDescription == Categories.Romance).CategoryID, ISBN_Number = BookTitles.Single(i => i.Title == "La leccion de august").ISBN_Number } }; foreach (BookCategory s in BooksCategory) { context.BookCategories.Add(s); } context.SaveChanges(); }