Example #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);
        }
Example #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);
        }
        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();

            Livestreams.AddRange(newStreams);
            Livestreams.RemoveRange(removedStreams);
        }
        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();
        }
        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));
        }
        private void AddChannels(params ChannelIdentifier[] newChannels)
        {
            bool channelAdded = false;

            foreach (var newChannel in newChannels)
            {
                if (channelIdentifiers.Add(newChannel))
                {
                    channelAdded = true;
                }
            }

            if (channelAdded)
            {
                SaveLivestreams();
                SelectedLivestream = Livestreams.FirstOrDefault();
            }
        }
Example #7
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);
            }
        }
Example #9
0
        internal void Dispose(bool destructor)
        {
            Logout();

            if (!destructor)
            {
                foreach (var stream in Livestreams.Values)
                {
                    stream.Disconnect();
                }

                foreach (var session in VoiceSessions.Values)
                {
                    session.Disconnect();
                }

                VoiceSessions.Clear();
                Livestreams.Clear();
                WebSocket.Dispose();

                Reset();
            }
        }
        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();
        }