Exemple #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);
        }
Exemple #2
0
        /// <summary> Design time only constructor </summary>
        public MonitorStreamsModel()
        {
            if (!Execute.InDesignMode)
            {
                throw new InvalidOperationException("Constructor only accessible from design time");
            }

            var rnd = new Random();

            for (int i = 0; i < 100; i++)
            {
                Livestreams.Add(new LivestreamModel("Livestream " + i, null)
                {
                    Live        = i < 14,
                    DisplayName = $"Channel Name {i + 1}",
                    Description = $"Channel Description {i + 1}",
                    Game        = i < 50 ? "Game A" : "Game B",
                    StartTime   = i < 14 ? DateTimeOffset.Now.AddSeconds(-(rnd.Next(10000))) : DateTimeOffset.MinValue,
                    Viewers     = i < 14 ? rnd.Next(50000) : 0
                });
            }
        }
        private void PopulateLivestreams(List <LivestreamModel> livestreamModels)
        {
            foreach (var livestream in livestreamModels)
            {
                var livestreamModel = Livestreams.FirstOrDefault(x => Equals(livestream, x));
                livestreamModel?.PopulateSelf(livestream);
            }

            var newStreams     = livestreamModels.Except(Livestreams).ToList();
            var removedStreams = Livestreams.Except(livestreamModels).ToList();

            // add/remove streams one at a time so we trigger regular add/remove collection change event
            // using addrange/removerange will instead trigger a reset event and will not state what new items were added/removed
            foreach (var livestreamModel in newStreams)
            {
                Livestreams.Add(livestreamModel);
            }
            foreach (var livestreamModel in removedStreams)
            {
                Livestreams.Remove(livestreamModel);
            }
        }
        public async Task ImportFollows(string username, IApiClient apiClient)
        {
            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }
            if (apiClient == null)
            {
                throw new ArgumentNullException(nameof(apiClient));
            }
            if (!apiClient.HasUserFollowQuerySupport)
            {
                throw new InvalidOperationException($"{apiClient.ApiName} does not have support for getting followed streams.");
            }

            var followedChannelsQueryResults = await apiClient.GetUserFollows(username);

            followedChannelsQueryResults.EnsureAllQuerySuccess();

            // Ignore duplicate channels
            var newChannels = followedChannelsQueryResults.Where(x => !channelIdentifiers.Contains(x.ChannelIdentifier)).ToList();

            if (newChannels.Count == 0)
            {
                return;
            }

            foreach (var newChannel in newChannels)
            {
                newChannel.ChannelIdentifier.ImportedBy = username;
                Livestreams.Add(newChannel.LivestreamModel);
                newChannel.ChannelIdentifier.ApiClient.AddChannelWithoutQuerying(newChannel.ChannelIdentifier);
            }

            AddChannels(newChannels.Select(x => x.ChannelIdentifier).ToArray());
            await RefreshLivestreams();
        }