コード例 #1
0
        public Task AddLivestream(ChannelIdentifier channelIdentifier, IViewAware viewAware)
        {
            if (channelIdentifier == null)
            {
                throw new ArgumentNullException(nameof(channelIdentifier));
            }
            Livestreams.Add(new LivestreamModel(channelIdentifier.ChannelId, channelIdentifier));

            return(Task.CompletedTask);
        }
コード例 #2
0
        public Task RemoveLivestream(ChannelIdentifier channelIdentifier)
        {
            if (channelIdentifier == null)
            {
                throw new ArgumentNullException(nameof(channelIdentifier));
            }
            var matchingLivestreams = Livestreams.Where(x => Equals(channelIdentifier, x.ChannelIdentifier)).ToList();

            Livestreams.RemoveRange(matchingLivestreams);
            return(Task.CompletedTask);
        }
コード例 #3
0
        public async Task RemoveLivestream(ChannelIdentifier channelIdentifier)
        {
            if (channelIdentifier == null)
            {
                return;
            }

            await channelIdentifier.ApiClient.RemoveChannel(channelIdentifier);

            channelIdentifiers.Remove(channelIdentifier);
            // TODO - if removal of a channel would remove more than 1 livestream, consider warning the user
            var matchingLivestreams = Livestreams.Where(x => Equals(channelIdentifier, x.ChannelIdentifier)).ToList();

            Livestreams.RemoveRange(matchingLivestreams);
            SaveLivestreams();
        }
コード例 #4
0
        public async Task AddLivestream(ChannelIdentifier channelIdentifier, IViewAware viewAware)
        {
            if (channelIdentifier == null)
            {
                throw new ArgumentNullException(nameof(channelIdentifier));
            }
            if (channelIdentifiers.Contains(channelIdentifier))
            {
                return;                                                 // ignore duplicate requests
            }
            var livestreamQueryResults = await channelIdentifier.ApiClient.AddChannel(channelIdentifier);

            livestreamQueryResults.EnsureAllQuerySuccess();

            AddChannels(channelIdentifier);
            Livestreams.AddRange(livestreamQueryResults.Select(x => x.LivestreamModel));
        }
コード例 #5
0
        private async Task PopulateDisplayNames(List <LivestreamFileEntry> fileEntries)
        {
            var groupedLivestreams = fileEntries.Where(x => x.StreamProvider != TwitchApiClient.API_NAME).GroupBy(x => x.StreamProvider);

            foreach (var groupedLivestream in groupedLivestreams)
            {
                var tempChannels = new List <ChannelIdentifier>();
                var apiClient    = apiClientFactory.GetByName(groupedLivestream.Key);
                foreach (var entry in groupedLivestream)
                {
                    var channelId = new ChannelIdentifier(apiClient, entry.ChannelId)
                    {
                        DisplayName = entry.DisplayName,
                        ImportedBy  = entry.ImportedBy
                    };
                    apiClient.AddChannelWithoutQuerying(channelId);
                    tempChannels.Add(channelId);
                }

                var queriedChannels = await apiClient.QueryChannels(CancellationToken.None);

                foreach (var entry in groupedLivestream)
                {
                    var matchingChannel = queriedChannels.FirstOrDefault(x => x.ChannelIdentifier.ChannelId.IsEqualTo(entry.ChannelId));
                    if (matchingChannel != null)
                    {
                        entry.DisplayName = matchingChannel.LivestreamModel.DisplayName;
                    }
                    else
                    {
                        fileEntries.Remove(entry);  // will have to be manually re-imported, most likely the channel has been removed/banned
                    }
                }

                tempChannels.ForEach(x => apiClient.RemoveChannel(x));
            }
        }
コード例 #6
0
 protected bool Equals(ChannelIdentifier other)
 {
     return(ChannelId.IsEqualTo(other.ChannelId) && Equals(ApiClient, other.ApiClient));
 }