internal WebPubSubService GetService(WebPubSubAttribute attribute)
        {
            var connectionString = Utilities.FirstOrDefault(attribute.ConnectionStringSetting, _options.ConnectionString);
            var hubName          = Utilities.FirstOrDefault(attribute.Hub, _options.Hub);

            return(new WebPubSubService(connectionString, hubName));
        }
        private WebPubSubConnection GetClientConnection(WebPubSubConnectionAttribute attribute)
        {
            var hub     = Utilities.FirstOrDefault(attribute.Hub, _options.Hub);
            var service = new WebPubSubService(attribute.ConnectionStringSetting, hub);

            return(service.GetClientConnection(attribute.UserId));
        }
        private void ValidateConnectionString(string attributeConnectionString, string attributeConnectionStringName)
        {
            var connectionString = Utilities.FirstOrDefault(attributeConnectionString, _options.ConnectionString);

            if (string.IsNullOrEmpty(connectionString))
            {
                throw new InvalidOperationException($"The Service connection string must be set either via an '{Constants.WebPubSubConnectionStringName}' app setting, via an '{Constants.WebPubSubConnectionStringName}' environment variable, or directly in code via {nameof(WebPubSubFunctionsOptions)}.{nameof(WebPubSubFunctionsOptions.ConnectionString)} or {attributeConnectionStringName}.");
            }
        }
Exemple #4
0
        public Task <IListener> CreateListenerAsync(ListenerFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Get listener key from attributes.
            var hub = Utilities.FirstOrDefault(_attribute.Hub, _options.Hub);

            if (string.IsNullOrEmpty(hub))
            {
                throw new ArgumentException("Hub name should be configured in either attribute or appsettings.");
            }
            var attributeName = $"{hub}.{_attribute.EventType}.{_attribute.EventName}";
            var listernerKey  = attributeName;

            return(Task.FromResult <IListener>(new WebPubSubListener(context.Executor, listernerKey, _dispatcher)));
        }