Exemplo n.º 1
0
        private async Task DownloadAllChannelContent(string userId,
                                                     CancellationToken cancellationToken,
                                                     IProgress <double> progress)
        {
            var result = await _manager.GetAllMedia(new AllChannelMediaQuery
            {
                UserId = userId
            }, cancellationToken).ConfigureAwait(false);

            progress.Report(5);

            var innerProgress = new ActionableProgress <double>();

            innerProgress.RegisterAction(p => progress.Report(5 + (.95 * p)));

            var path = _manager.ChannelDownloadPath;

            await DownloadChannelContent(result, path, cancellationToken, innerProgress).ConfigureAwait(false);
        }
        private async Task DownloadChannelContent(CancellationToken cancellationToken, IProgress <double> progress)
        {
            if (_config.Configuration.ChannelOptions.DownloadingChannels.Length == 0)
            {
                return;
            }

            var result = await _manager.GetAllMedia(new AllChannelMediaQuery
            {
                ChannelIds = _config.Configuration.ChannelOptions.DownloadingChannels
            }, cancellationToken).ConfigureAwait(false);

            var path = _manager.ChannelDownloadPath;

            var numComplete = 0;

            foreach (var item in result.Items)
            {
                try
                {
                    await DownloadChannelItem(item, cancellationToken, path);
                }
                catch (OperationCanceledException)
                {
                    break;
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error downloading channel content for {0}", ex, item.Name);
                }

                numComplete++;
                double percent = numComplete;
                percent /= result.Items.Length;
                progress.Report(percent * 95 + 5);
            }
        }