Example #1
0
        public async Task <IEnumerable <BookFile> > GetBookFiles()
        {
            foreach (var reader in _readers)
            {
                _fileList.AddExtension(reader.Extension);
                _lookup.Add(string.Format(".{0}", reader.Extension), reader);
            }

            IEnumerable <string> list = await _fileList.GetFileList();

            _messages.Write("Found {0} files", list.Count());

            //var books = new List<BookFile>();
            //foreach (var path in list)
            //{
            //    BookFile book = await ReadBookFile(path);
            //    if (book != null)
            //        books.Add(book);
            //}

            var allBookTasks = list.Select(async path => await ReadBookFile(path));

            var allBooks = await Task.WhenAll(allBookTasks);

            var books = allBooks.Where(book => book != null).ToArray();

            return(books);
        }
Example #2
0
        async Task SaveBook(BookFilesInfo book)
        {
            BookInfo info = book.Book;

            if (!string.IsNullOrEmpty(info.Isbn))
            {
                info.Isbn = Isbn.Normalise(info.Isbn);
            }

            await _originalDataSource.SaveBook(info);

            _messages.Write("Added:    {0} - {1} [{2}]", book.Book.Title, book.Book.Author, book.Book.Isbn);

            foreach (var file in book.Files)
            {
                await SaveBookFile(file);
            }
        }
Example #3
0
        public async Task <IEnumerable <MatchInfo> > Match(IEnumerable <MatchInfo> incoming)
        {
            var matches = new List <MatchInfo>();

            IEnumerable <MatchInfo> toMatch = incoming
                                              .Where(b => b.IsSelected)
                                              .Where(b => b.Status == MatchStatus.NotAttempted);

            foreach (var match in toMatch)
            {
                FindResultInfo result = await _bookFinder.Find(match.Book);

                match.SetMatch(result.Book, result.Status, result.NewTypes);

                matches.Add(match);

                _messages.Write("Match done: {0}: {1}", match.Book.Title, match.Status);
            }

            return(matches);
        }