public void Start(ProgressNotification notification, dynamic options)
        {
            var reports = new List <EpisodeParseResult>();

            notification.CurrentMessage = "Fetching RSS";

            Parallel.ForEach(_indexerProvider.GetEnabledIndexers(), indexer =>
            {
                try
                {
                    reports.AddRange(indexer.FetchRss());
                }
                catch (Exception e)
                {
                    Logger.ErrorException("An error has occurred while fetching items from " + indexer.Name, e);
                }
            });

            Logger.Debug("Finished fetching reports from all indexers. Total {0}", reports.Count);

            notification.CurrentMessage = "Processing downloaded RSS";

            foreach (var episodeParseResult in reports)
            {
                try
                {
                    if (_isMonitoredEpisodeSpecification.IsSatisfiedBy(episodeParseResult) &&
                        _allowedDownloadSpecification.IsSatisfiedBy(episodeParseResult) == ReportRejectionType.None &&
                        _upgradeHistorySpecification.IsSatisfiedBy(episodeParseResult))
                    {
                        _downloadProvider.DownloadReport(episodeParseResult);
                    }
                }
                catch (Exception e)
                {
                    Logger.ErrorException("An error has occurred while processing parse result items from " + episodeParseResult, e);
                }
            }

            notification.CurrentMessage = "RSS Sync Completed";

            Logger.Info("RSS Sync completed");
        }
 public void should_be_allowed_if_all_conditions_are_met()
 {
     spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.None);
 }
Beispiel #3
0
        public virtual SearchHistory ProcessReports(Series series, dynamic options, List <EpisodeParseResult> episodeParseResults,
                                                    SearchHistory searchResult, ProgressNotification notification)
        {
            var items = new List <SearchHistoryItem>();

            searchResult.Successes = new List <Int32>();

            foreach (var episodeParseResult in episodeParseResults
                     .OrderByDescending(c => c.Quality)
                     .ThenBy(c => c.EpisodeNumbers.MinOrDefault())
                     .ThenBy(c => c.Age))
            {
                try
                {
                    var item = new SearchHistoryItem
                    {
                        ReportTitle = episodeParseResult.OriginalString,
                        NzbUrl      = episodeParseResult.NzbUrl,
                        Indexer     = episodeParseResult.Indexer,
                        Quality     = episodeParseResult.Quality.Quality,
                        Proper      = episodeParseResult.Quality.Proper,
                        Size        = episodeParseResult.Size,
                        Age         = episodeParseResult.Age,
                        Language    = episodeParseResult.Language
                    };

                    items.Add(item);

                    logger.Trace("Analysing report " + episodeParseResult);
                    episodeParseResult.Series = _seriesProvider.FindSeries(episodeParseResult.CleanTitle);

                    if (episodeParseResult.Series == null || episodeParseResult.Series.SeriesId != series.SeriesId)
                    {
                        item.SearchError = ReportRejectionType.WrongSeries;
                        continue;
                    }

                    episodeParseResult.Episodes = _episodeProvider.GetEpisodesByParseResult(episodeParseResult);

                    if (searchResult.Successes.Intersect(episodeParseResult.Episodes.Select(e => e.EpisodeId)).Any())
                    {
                        item.SearchError = ReportRejectionType.Skipped;
                        continue;
                    }

                    CheckReport(series, options, episodeParseResult, item);
                    if (item.SearchError != ReportRejectionType.None)
                    {
                        continue;
                    }

                    item.SearchError = _allowedDownloadSpecification.IsSatisfiedBy(episodeParseResult);

                    if (item.SearchError == ReportRejectionType.None)
                    {
                        if (DownloadReport(notification, episodeParseResult, item))
                        {
                            searchResult.Successes.AddRange(episodeParseResult.Episodes.Select(e => e.EpisodeId));
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.ErrorException("An error has occurred while processing parse result items from " + episodeParseResult, e);
                }
            }

            searchResult.SearchHistoryItems = items;
            return(searchResult);
        }