public DatedFeedAsyncEnumerator(IDatedFeed datedFeed, FeedDate feedDate, bool cachePages = false)
     : base(datedFeed, cachePages)
 {
     CurrentEarliest = feedDate.Date;
     CurrentLatest   = feedDate.Date;
     DatedFeed       = datedFeed;
 }
        public override async Task <PageReadResult> MoveNextAsync(CancellationToken cancellationToken)
        {
            PageReadResult?result          = null;
            Uri?           pageUri         = null;
            FeedDate       feedDate        = default;
            bool           criticalFailure = false;

            try
            {
                await _semaphore.WaitAsync(cancellationToken);

                feedDate = new FeedDate(CurrentEarliest, DateDirection.Before);
                pageUri  = DatedFeed.GetUriForDate(feedDate);
                if (pageUri == LastFetchedUri)
                {
                    criticalFailure = true;
                    throw new FeedReaderException($"URL '{pageUri}' was previously read, aborting to avoid possible infinite loop.");
                }
                result = await DatedFeed.GetSongsAsync(pageUri, cancellationToken).ConfigureAwait(false);

                LastFetchedUri = pageUri;
            }
            catch (OperationCanceledException ex)
            {
                result = PageReadResult.CancelledResult(pageUri, ex);
            }
            catch (Exception ex)
            {
                if (criticalFailure)
                {
                    throw;
                }
                result = new PageReadResult(pageUri, null, null, null, 0, ex, PageErrorType.Unknown);
            }
            finally
            {
                ProcessResult(result, feedDate.Direction);
                _semaphore.Release();
            }

            return(result);
        }
Ejemplo n.º 3
0
 public bool Equals(FeedDate other)
 {
     return(Date == other.Date && Direction == other.Direction);
 }