public IDisposable RegisterCommandHandler <Command, CommandHandler>(string messageChannelIdentifierCode)
            where CommandHandler : ICommandHandler <Command>
        {
            ChannelIdentifier messageChannelIdentifier = _componentChannelIdentifierRepository.GetChannelIdentifierFor(messageChannelIdentifierCode);

            return(_channelProvider.RegisterCommandHandler <Command, CommandHandler>(messageChannelIdentifier, _iocLifetimeScope));
        }
        public async Task <List <LivestreamQueryResult> > GetTopStreams(TopStreamQuery topStreamQuery)
        {
            if (topStreamQuery == null)
            {
                throw new ArgumentNullException(nameof(topStreamQuery));
            }

            var query = new GetStreamsQuery()
            {
                First = topStreamQuery.Take
            };

            if (!string.IsNullOrWhiteSpace(topStreamQuery.GameName))
            {
                var gameId = await GetGameIdByName(topStreamQuery.GameName);

                query.GameIds.Add(gameId);
            }

            var topStreams = await twitchTvHelixClient.GetStreams(query);

            return(topStreams.Select(x =>
            {
                var channelIdentifier = new ChannelIdentifier(this, x.UserId)
                {
                    DisplayName = x.UserName
                };
                var queryResult = new LivestreamQueryResult(channelIdentifier);
                var livestreamModel = new LivestreamModel(x.UserId, channelIdentifier);
                livestreamModel.PopulateWithStreamDetails(x);

                queryResult.LivestreamModel = livestreamModel;
                return queryResult;
            }).ToList());
        }
        public static ServiceBusMessageChannel Create(ChannelIdentifier channelIdentifier, string storageAccountConnectionstring)
        {
            var channel = new ServiceBusMessageChannel(channelIdentifier, storageAccountConnectionstring);

            channel.Initialize();
            return(channel);
        }
Пример #4
0
 public void AddChannelWithoutQuerying(ChannelIdentifier newChannel)
 {
     if (newChannel == null)
     {
         throw new ArgumentNullException(nameof(newChannel));
     }
     moniteredChannels.Add(newChannel);
 }
Пример #5
0
        public LivestreamQueryResult(ChannelIdentifier channelIdentifier)
        {
            if (channelIdentifier == null)
            {
                throw new ArgumentNullException(nameof(channelIdentifier));
            }

            ChannelIdentifier = channelIdentifier;
        }
 public FailedQueryException(ChannelIdentifier channelIdentifier, Exception ex)
     : base($"Error querying {channelIdentifier.ApiClient.ApiName} channel '{channelIdentifier.ChannelId}'. {ex.Message}", ex)
 {
     if (channelIdentifier == null)
     {
         throw new ArgumentNullException(nameof(channelIdentifier));
     }
     ChannelIdentifier = channelIdentifier;
 }
 public LivestreamModel()
 {
     if (!Execute.InDesignMode)
     {
         throw new InvalidOperationException("Design time only constructor");
     }
     Id = "DesignTimeId";
     ChannelIdentifier = new ChannelIdentifier();
     UniqueStreamKey   = new UniqueStreamKey();
 }
        public TopStreamResult()
        {
            if (!Execute.InDesignMode)
            {
                throw new InvalidOperationException("Design time only constructor");
            }

            LivestreamModel   = new LivestreamModel();
            ChannelIdentifier = new ChannelIdentifier();
        }
        /// <summary> A livestream object from an Api/Channel </summary>
        /// <param name="id">A unique id for this livestream for its <see cref="ApiClient"/></param>
        /// <param name="channelIdentifier">The <see cref="ApiClient"/> and unique channel identifier for that api client where this stream came from</param>
        public LivestreamModel(string id, ChannelIdentifier channelIdentifier)
        {
            if (String.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentException("Argument is null or whitespace", nameof(id));
            }

            Id = id;
            ChannelIdentifier = channelIdentifier ?? throw new ArgumentNullException(nameof(channelIdentifier));
            UniqueStreamKey   = new UniqueStreamKey(ApiClient.ApiName, Id);
        }
        public async Task <List <LivestreamQueryResult> > AddChannel(ChannelIdentifier newChannel)
        {
            var queryResults = await QueryChannels(new[] { newChannel }, CancellationToken.None);

            if (queryResults.Any(x => x.IsSuccess))
            {
                moniteredChannels.Add(newChannel);
            }

            return(queryResults);
        }
Пример #11
0
        private HekaDAQStream StreamWithIdentifier(ChannelIdentifier channelIdentifier)
        {
            HekaDAQStream result =
                Streams.OfType <HekaDAQStream>().First(s => s.ChannelNumber == channelIdentifier.ChannelNumber && s.ChannelType == (StreamType)channelIdentifier.ChannelType);

            if (result == null)
            {
                throw new DAQException("Unable to find stream with identifier " + channelIdentifier);
            }

            return(result);
        }
Пример #12
0
        public async Task <List <LivestreamQueryResult> > GetUserFollows(string userName)
        {
            var userFollows = await hitboxClient.GetUserFollows(userName);

            return(userFollows.Select(x =>
            {
                var channelIdentifier = new ChannelIdentifier(this, x.UserName);
                return new LivestreamQueryResult(channelIdentifier)
                {
                    LivestreamModel = new LivestreamModel(x.UserName, channelIdentifier)
                };
            }).ToList());
        }
 public TopStreamResult(LivestreamModel livestreamModel, ChannelIdentifier channelIdentifier)
 {
     if (livestreamModel == null)
     {
         throw new ArgumentNullException(nameof(livestreamModel));
     }
     if (channelIdentifier == null)
     {
         throw new ArgumentNullException(nameof(channelIdentifier));
     }
     LivestreamModel   = livestreamModel;
     ChannelIdentifier = channelIdentifier;
 }
Пример #14
0
        public void ToDelimitedString_WithAllProperties_ReturnsCorrectlySequencedFields()
        {
            IType hl7Type = new ChannelIdentifier
            {
                ChannelNumber = 1,
                ChannelName   = "2"
            };

            string expected = "1^2";
            string actual   = hl7Type.ToDelimitedString();

            Assert.Equal(expected, actual);
        }
Пример #15
0
 internal InMemoryMessageChannel GetChannel(ChannelIdentifier identifier)
 {
     if (!_channels.ContainsKey(identifier))
     {
         lock (_channelCreationLockObject)
         {
             if (!_channels.ContainsKey(identifier))
             {
                 _channels[identifier] = new InMemoryMessageChannel(identifier);
             }
         }
     }
     return(_channels[identifier]);
 }
Пример #16
0
        public Task RemoveChannel(ChannelIdentifier channelIdentifier)
        {
            // we keep our offline query results cached so we don't need to re-query them again this application run
            // as such, we must cleanup any previous query result that has the channel identifier being removed
            var queryResult = offlineQueryResultsCache.FirstOrDefault(x => Equals(channelIdentifier, x.ChannelIdentifier));

            if (queryResult != null)
            {
                offlineQueryResultsCache.Remove(queryResult);
            }

            moniteredChannels.Remove(channelIdentifier);
            return(Task.CompletedTask);
        }
Пример #17
0
        public void FromDelimitedString_WithAllProperties_ReturnsCorrectlyInitializedFields()
        {
            IType expected = new ChannelIdentifier
            {
                ChannelNumber = 1,
                ChannelName   = "2"
            };

            IType actual = new ChannelIdentifier();

            actual.FromDelimitedString("1^2");

            expected.Should().BeEquivalentTo(actual);
        }
 public ServiceBusMessageChannel GetChannel(ChannelIdentifier identifier)
 {
     if (!_channels.ContainsKey(identifier))
     {
         lock (_channelCreationLockObject)
         {
             if (!_channels.ContainsKey(identifier))
             {
                 _channels[identifier] = ServiceBusMessageChannel.Create(identifier, _storageAccountConnectionstring);
             }
         }
     }
     return(_channels[identifier]);
 }
Пример #19
0
        public async Task <List <LivestreamQueryResult> > AddChannel(ChannelIdentifier newChannel)
        {
            var queryResult = await QueryChannel(newChannel, CancellationToken.None);

            if (queryResult.IsSuccess)
            {
                followedChannels.Add(newChannel);
            }

            return(new List <LivestreamQueryResult>()
            {
                queryResult
            });
        }
Пример #20
0
        public async Task <List <LivestreamQueryResult> > AddChannel(ChannelIdentifier newChannel)
        {
            if (newChannel == null)
            {
                throw new ArgumentNullException(nameof(newChannel));
            }

            var queryResults = await QueryChannels(new[] { newChannel }, CancellationToken.None);

            if (queryResults.Any(x => x.IsSuccess))
            {
                moniteredChannels.Add(newChannel);
            }

            return(queryResults);
        }
Пример #21
0
        public async Task <List <LivestreamQueryResult> > AddChannel(ChannelIdentifier newChannel)
        {
            if (newChannel == null)
            {
                throw new ArgumentNullException(nameof(newChannel));
            }

            // shorter implementation of QueryChannels
            var queryResults  = new List <LivestreamQueryResult>();
            var onlineStreams = await twitchTvClient.GetStreamsDetails(new[] { newChannel.ChannelId });

            var onlineStream = onlineStreams.FirstOrDefault();

            if (onlineStream != null)
            {
                var livestream = new LivestreamModel(onlineStream.Channel?.Name, newChannel);
                livestream.PopulateWithChannel(onlineStream.Channel);
                livestream.PopulateWithStreamDetails(onlineStream);
                queryResults.Add(new LivestreamQueryResult(newChannel)
                {
                    LivestreamModel = livestream
                });
            }

            // we always need to check for offline channels when attempting to add a channel for the first time
            // this is the only way to detect non-existant/banned channels
            var offlineStreams = await GetOfflineStreamQueryResults(new[] { newChannel }, CancellationToken.None);

            if (onlineStream == null || offlineStreams.Any(x => !x.IsSuccess))
            {
                queryResults.AddRange(offlineStreams);
            }
            else
            {
                offlineStreams.Clear();
            }

            if (queryResults.All(x => x.IsSuccess))
            {
                moniteredChannels.Add(newChannel);
                offlineQueryResultsCache.AddRange(offlineStreams.Where(x => x.IsSuccess));
            }
            return(queryResults);
        }
Пример #22
0
        private async Task <LivestreamQueryResult> QueryChannel(ChannelIdentifier channelIdentifier, CancellationToken cancellationToken)
        {
            var queryResult = new LivestreamQueryResult(channelIdentifier);

            try
            {
                var channel = await beamProClient.GetStreamDetails(channelIdentifier.ChannelId, cancellationToken);

                channelNameIdMap[channel.token] = channel.id; // record the mapping of the channels token/name to its underlying id
                var livestreamModel = ConvertToLivestreamModel(channel);
                queryResult.LivestreamModel = livestreamModel;
            }
            catch (Exception ex)
            {
                queryResult.FailedQueryException = new FailedQueryException(channelIdentifier, ex);
            }

            return(queryResult);
        }
Пример #23
0
        public async Task <List <LivestreamQueryResult> > GetTopStreams(TopStreamQuery topStreamQuery)
        {
            var pagedQuery = new BeamProPagedQuery()
            {
                Skip = topStreamQuery.Skip,
                Take = topStreamQuery.Take
            };
            var topStreams = await beamProClient.GetTopStreams(pagedQuery);

            return(topStreams.ConvertAll(input =>
            {
                var channelIdentifier = new ChannelIdentifier(this, input.token);
                channelNameIdMap[input.token] = input.id;
                return new LivestreamQueryResult(channelIdentifier)
                {
                    LivestreamModel = ConvertToLivestreamModel(input)
                };
            }));
        }
Пример #24
0
        public async Task <List <LivestreamQueryResult> > GetTopStreams(TopStreamQuery topStreamQuery)
        {
            if (topStreamQuery == null)
            {
                throw new ArgumentNullException(nameof(topStreamQuery));
            }
            var topStreams = await twitchTvClient.GetTopStreams(topStreamQuery);

            return(topStreams.Select(x =>
            {
                var channelIdentifier = new ChannelIdentifier(this, x.Channel.Name);
                var queryResult = new LivestreamQueryResult(channelIdentifier);
                var livestreamModel = new LivestreamModel(x.Channel?.Name, channelIdentifier);
                livestreamModel.PopulateWithStreamDetails(x);
                livestreamModel.PopulateWithChannel(x.Channel);

                queryResult.LivestreamModel = livestreamModel;
                return queryResult;
            }).ToList());
        }
Пример #25
0
        public async Task JoinGameAsync(GameInfoDto game)
        {
            ChannelIdentifier channelIdentifier = _hashService.GenerateChannelIdentifier(game.Hash);

            var channel = new Channel()
            {
                Id     = channelIdentifier.Id,
                Expiry = DateTimeOffset.UtcNow.AddMinutes(45).ToUnixTimeSeconds(),
                Name   = channelIdentifier.Name
            };

            await _channelPersistence.PersistChannelAsync(channel);

            await _channelPersistence.PersistUserInChannelAsync(channel.Id, game.User);

            var joinedGameEvent = new OnJoinedGameEvent()
            {
                ChannelName = channel.Name,
                VoiceUserId = game.User.Discord.UserId
            };

            await _messageBus.PublishAsync(joinedGameEvent);
        }
Пример #26
0
 /// <summary>
 /// Creates a new <see cref="SendMessageException"/>.
 /// </summary>
 /// <param name="channelIdentifier">The identifier of the channel through which the message failed to send.</param>
 /// <param name="innerException">The exception that is the cause of the current exception.</param>
 internal SendMessageException(ChannelIdentifier channelIdentifier, Exception innerException) : base("Error sending message.", innerException)
 {
     ChannelIdentifier = channelIdentifier;
 }
Пример #27
0
 public Task RemoveChannel(ChannelIdentifier channelIdentifier)
 {
     moniteredChannels.Remove(channelIdentifier);
     return(Task.CompletedTask);
 }
Пример #28
0
 public void AddChannelWithoutQuerying(ChannelIdentifier newChannel)
 {
     followedChannels.Add(newChannel);
 }
Пример #29
0
        private HekaDAQStream StreamWithIdentifier(ChannelIdentifier channelIdentifier)
        {
            HekaDAQStream result =
                Streams.OfType<HekaDAQStream>().First(s => s.ChannelNumber == channelIdentifier.ChannelNumber && s.ChannelType == (StreamType)channelIdentifier.ChannelType);

            if (result == null)
            {
                throw new DAQException("Unable to find stream with identifier " + channelIdentifier);
            }

            return result;
        }
Пример #30
0
 /// <summary>
 /// Creates a new <see cref="DisconnectedChannelException"/>.
 /// </summary>
 /// <param name="channelIdentifier">The identifier of the channel that is disconnected.</param>
 internal DisconnectedChannelException(ChannelIdentifier channelIdentifier) : base($"The channel {channelIdentifier} is not connected.")
 {
     ChannelIdentifier = channelIdentifier;
 }
 internal StringMessageReceivedEventArgs(ChannelIdentifier channelIdentifier, string message)
 {
     ChannelIdentifier = channelIdentifier;
     Message           = message;
 }