Exemple #1
0
        private async Task ExploringStep(CancellationToken cancellationToken)
        {
            await RandomDelay(cancellationToken);

            var randomBook = await _booksRepository.GetRandomNotFilledBookAsync();

            await RandomDelay(cancellationToken);

            var bookExists = _seeker.ReadBookInfo(randomBook);

            if (!bookExists)
            {
                BookInfo.MarkAsNotFound(randomBook);
            }
            else
            {
                if (randomBook?.BookType == null)
                {
                    throw new InvalidOperationException(
                              "something went wrong, book properties was not read");
                }

                if (randomBook.ClosureDate.Length <= 4)
                {
                    var properties = _seeker.ReadProperties();
                    randomBook.AddNewProperties(properties);
                }
            }

            await _booksRepository.UpdateBookAsync(randomBook);

            await _booksRepository.AddPropertyFromBookAsync(randomBook);

            await RandomDelay(cancellationToken);

            _seeker.BackToCriteria();
        }
Exemple #2
0
        public async Task Explore(CancellationToken cancellationToken)
        {
            var downloadedBooks = 0;

            while (!cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var randomBook = await _booksRepository.GetRandomNotFilledBookAsync();

                _dataGenerator.WriteDataToBook(randomBook);

                await _booksRepository.UpdateBookAsync(randomBook);

                await _booksRepository.AddPropertyFromBookAsync(randomBook);

                downloadedBooks++;
                _logger.Debug("Downloaded books: {DownloadedBooks}", downloadedBooks);

                await RandomDelay(cancellationToken);
            }

            cancellationToken.ThrowIfCancellationRequested();
        }