Example #1
0
        private async Task DownloadContent(string user, CancellationToken cancellationToken, IProgress <double> progress)
        {
            var channels = await _channelManager.GetChannelsInternal(new ChannelQuery
            {
                UserId = user
            }, cancellationToken);

            var numComplete = 0;
            var numItems    = channels.Items.Length;

            foreach (var channel in channels.Items)
            {
                var channelId = channel.Id.ToString("N");

                var features = _channelManager.GetChannelFeatures(channelId);

                const int currentRefreshLevel = 1;
                var       maxRefreshLevel     = features.AutoRefreshLevels ?? 0;
                maxRefreshLevel = Math.Max(maxRefreshLevel, 2);

                if (maxRefreshLevel > 0)
                {
                    var innerProgress = new ActionableProgress <double>();

                    var startingNumberComplete = numComplete;
                    innerProgress.RegisterAction(p =>
                    {
                        double innerPercent = startingNumberComplete;
                        innerPercent       += (p / 100);
                        innerPercent       /= numItems;
                        progress.Report(innerPercent * 100);
                    });

                    try
                    {
                        await GetAllItems(user, channelId, null, currentRefreshLevel, maxRefreshLevel, innerProgress, cancellationToken).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        _logger.ErrorException("Error getting channel content", ex);
                    }
                }

                numComplete++;
                double percent = numComplete;
                percent /= numItems;
                progress.Report(percent * 100);
            }

            progress.Report(100);
        }
Example #2
0
        private async Task DownloadChannelContent(QueryResult <BaseItem> result,
                                                  string path,
                                                  CancellationToken cancellationToken,
                                                  IProgress <double> progress)
        {
            var numComplete = 0;

            var options = _config.GetChannelsConfiguration();

            foreach (var item in result.Items)
            {
                var channelItem = item as IChannelMediaItem;

                if (channelItem != null)
                {
                    var channelFeatures = _manager.GetChannelFeatures(channelItem.ChannelId);

                    if (channelFeatures.SupportsContentDownloading)
                    {
                        if (options.DownloadingChannels.Contains(channelItem.ChannelId))
                        {
                            try
                            {
                                await DownloadChannelItem(channelItem, options, cancellationToken, path);
                            }
                            catch (OperationCanceledException)
                            {
                                break;
                            }
                            catch (ChannelDownloadException)
                            {
                                // Logged at lower levels
                            }
                            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 * 100);
            }

            progress.Report(100);
        }
Example #3
0
        public object Get(GetChannelFeatures request)
        {
            var result = _channelManager.GetChannelFeatures(request.Id);

            return(ToOptimizedResult(result));
        }
Example #4
0
 public ActionResult <ChannelFeatures> GetChannelFeatures([FromRoute, Required] string channelId)
 {
     return(_channelManager.GetChannelFeatures(channelId));
 }