Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        public void Setup()
        {
            _booksValidatorFake = A.Fake <IBookValidator>();
            _booksMapperFake    = A.Fake <IBookMapper>();

            _booksParser = new SimpleBookParser(_booksValidatorFake, _booksMapperFake);
        }
Exemplo n.º 4
0
 public BookProcessor(IBookDataProvider bookDataProvider,
                      IBookParser bookParser,
                      IBookStorage bookStorage)
 {
     _bookDataProvider = bookDataProvider;
     _bookParser       = bookParser;
     _bookStorage      = bookStorage;
 }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 static string CheckFor(IBookParser parser)
 {
     if (parser == null)
     {
         return("null");
     }
     else
     {
         return(parser.GetType().ToString());
     }
 }
Exemplo n.º 9
0
 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);
 }