private static void AddModule <TEvent>(
            EventPipelineConfigurator <TEvent> eventPipelineConfigurator,
            PublicationMethod publicationMethod,
            string hubName,
            string hubMethodName,
            Func <TEvent, string[]> receiverIdsProviderAction
            )
            where TEvent : class
        {
            if (hubMethodName == null)
            {
                hubMethodName = typeof(TEvent).Name;
            }

            ((IInfrastructure <IPipeline>)eventPipelineConfigurator).Instance
            .AddModule <AzureSignalRPipelineModule, AzureSignalRPipelineModuleConfig>(
                new AzureSignalRPipelineModuleConfig
            {
                PublicationMethod         = publicationMethod,
                HubMethodName             = hubMethodName,
                HubName                   = hubName,
                ReceiverIdsProviderAction = receiverIdsProviderAction == null
                            ? (Func <object, string[]>)null
                            : e => receiverIdsProviderAction((TEvent)e)
            }
                );
        }
        public async Task SendEventAsync(PublicationMethod publicationMethod,
                                         string hubName,
                                         string hubMethodName,
                                         string[] receiverIds,
                                         object e
                                         )
        {
            foreach (var receiverId in receiverIds ?? _nullReceiver)
            {
                var url = _urlProvider.GetUrl(
                    _connectionString.Endpoint,
                    publicationMethod,
                    hubName,
                    receiverId
                    );

                var request = _httpRequestFactory.CreateHttpRequest(
                    _connectionString,
                    hubMethodName,
                    e,
                    url
                    );

                using (var response = await _signalRHttpClient.SendAsync(request).ConfigureAwait(false))
                {
                    try
                    {
                        response.EnsureSuccessStatusCode();
                    }
                    catch (HttpRequestException ex)
                    {
                        throw new AzureSignalRPublishingFailedException(ex);
                    }

                    if (response.StatusCode != HttpStatusCode.Accepted)
                    {
                        throw new AzureSignalRPublishingFailedException(response.StatusCode);
                    }
                }
            }
        }
예제 #3
0
        public string GetUrl(string endpoint, PublicationMethod publicationMethod, string hubName, string receiverId)
        {
            string url;

            switch (publicationMethod)
            {
            case PublicationMethod.User:
                url = GetSendToUserUrl(endpoint, hubName, receiverId);
                break;

            case PublicationMethod.Group:
                url = GetSendToGroupUrl(endpoint, hubName, receiverId);
                break;

            case PublicationMethod.Broadcast:
                url = GetBroadcastUrl(endpoint, hubName);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(publicationMethod));
            }

            return(url);
        }