public void Execute(ProcessMonitoredDownloadsCommand message)
        {
            var enableCompletedDownloadHandling = _configService.EnableCompletedDownloadHandling;
            var trackedDownloads = _trackedDownloadService.GetTrackedDownloads();

            foreach (var trackedDownload in trackedDownloads)
            {
                if (trackedDownload.State == TrackedDownloadState.DownloadFailedPending)
                {
                    _failedDownloadService.ProcessFailed(trackedDownload);
                }

                if (enableCompletedDownloadHandling && trackedDownload.State == TrackedDownloadState.ImportPending)
                {
                    _completedDownloadService.Import(trackedDownload);
                }
            }

            if (enableCompletedDownloadHandling && _configService.RemoveCompletedDownloads)
            {
                // Remove tracked downloads that are now complete
                RemoveCompletedDownloads(trackedDownloads);
            }

            _eventAggregator.PublishEvent(new DownloadsProcessedEvent());
        }
Beispiel #2
0
        public void Execute(ProcessMonitoredDownloadsCommand message)
        {
            var enableCompletedDownloadHandling = _configService.EnableCompletedDownloadHandling;
            var removeCompletedDownloads        = _configService.RemoveCompletedDownloads;
            var trackedDownloads = _trackedDownloadService.GetTrackedDownloads()
                                   .Where(t => t.IsTrackable)
                                   .ToList();

            foreach (var trackedDownload in trackedDownloads)
            {
                try
                {
                    if (trackedDownload.State == TrackedDownloadState.DownloadFailedPending)
                    {
                        _failedDownloadService.ProcessFailed(trackedDownload);
                    }
                    else if (enableCompletedDownloadHandling && trackedDownload.State == TrackedDownloadState.ImportPending)
                    {
                        _completedDownloadService.Import(trackedDownload);
                    }
                }
                catch (Exception e)
                {
                    _logger.Debug(e, "Failed to process download: {0}", trackedDownload.DownloadItem.Title);
                }
            }

            // Imported downloads are no longer trackable so process them after processing trackable downloads
            if (removeCompletedDownloads)
            {
                RemoveCompletedDownloads();
            }

            _eventAggregator.PublishEvent(new DownloadsProcessedEvent());
        }