public static async Task <bool> ExistsAsync(this IBookParser parser, CancellationToken cancellationToken = default) { if (!string.IsNullOrWhiteSpace(parser.Title) && !string.IsNullOrWhiteSpace(parser.Author) && await Utility.Cache.ExistsAsync($"{parser.Title} - {parser.Author}".Trim().ToLower().GenerateUUID()).ConfigureAwait(false)) { return(true); } var filename = UtilityService.GetNormalizedFilename($"{parser.Title} - {parser.Author}") + ".json"; if (File.Exists(Path.Combine(Utility.GetBookFilePath(filename), filename))) { return(true); } else if (File.Exists(Path.Combine(Utility.DirectoryOfTrashFiles, filename))) { return(true); } var book = !string.IsNullOrWhiteSpace(parser.Title) && !string.IsNullOrWhiteSpace(parser.Author) ? await Book.GetAsync <Book>($"{parser.Title} - {parser.Author}".Trim().ToLower().GenerateUUID(), cancellationToken).ConfigureAwait(false) : await Book.GetAsync(parser.Title, parser.Author, cancellationToken).ConfigureAwait(false); return(book != null); }
public static void NormalizeTOC(this IBookParser parser) { if (parser.Chapters == null || parser.Chapters.Count < 2) { return; } var tocs = new List <string>(); parser.Chapters.ForEach((chapter, index) => { string title = null; if (chapter.IsStartsWith("<h1>")) { var pos = chapter.PositionOf("</h1>"); title = (pos > 0 ? chapter.Substring(4, pos - 4) : "").Trim(); } if (title == null && parser.TOCs != null && parser.TOCs.Count > index) { tocs.Add(!string.IsNullOrWhiteSpace(parser.TOCs[index]) ? parser.TOCs[index] : (index + 1).ToString() + "."); } else { tocs.Add(!string.IsNullOrWhiteSpace(title) ? title : (index + 1).ToString() + "."); } }); parser.TOCs = tocs; }
public void Setup() { _booksValidatorFake = A.Fake <IBookValidator>(); _booksMapperFake = A.Fake <IBookMapper>(); _booksParser = new SimpleBookParser(_booksValidatorFake, _booksMapperFake); }
public BookProcessor(IBookDataProvider bookDataProvider, IBookParser bookParser, IBookStorage bookStorage) { _bookDataProvider = bookDataProvider; _bookParser = bookParser; _bookStorage = bookStorage; }
public int GetNumPages() { if (_bookParser == null) { _bookParser = new RealBookParser(Path); } return(_bookParser.GetNumPages()); }
public int GetNumberOfWords() { if (_bookParser == null) { _bookParser = new RealBookParser(_book); } return(_bookParser.GetNumberOfWords()); }
public void Setup() { _bookDataProviderFake = A.Fake <IBookDataProvider>(options => options.Strict()); _bookParserFake = A.Fake <IBookParser>(options => options.Strict()); _bookStorageFake = A.Fake <IBookStorage>(options => options.Strict()); _bookProcessor = new BookProcessor(_bookDataProviderFake, _bookParserFake, _bookStorageFake); }
static string CheckFor(IBookParser parser) { if (parser == null) { return("null"); } else { return(parser.GetType().ToString()); } }
public Client() { this.parser = new BookProxy(book); //to get number of pages we call proxy instead of real BookParser Console.WriteLine(parser.GetNumberOfPages()); }
private void InitializeBookParser() { _bookParser = new BookParser(_book); }