public ServiceEndpointManager(
     IAccessKeySynchronizer synchronizer,
     ServiceOptions options,
     ILoggerFactory loggerFactory) :
     base(
         options,
         loggerFactory?.CreateLogger <ServiceEndpointManager>()
         )
 {
     _options      = options;
     _synchronizer = synchronizer;
 }
        public ServiceEndpointManager(ServiceOptions options, ILoggerFactory loggerFactory) :
            base(options,
                 loggerFactory?.CreateLogger <ServiceEndpointManager>())
        {
            if (Endpoints.Length == 0)
            {
                throw new ArgumentException(ServiceEndpointProvider.ConnectionStringNotFound);
            }

            _ttl     = options.AccessTokenLifetime;
            _options = options;
        }
Пример #3
0
 public ServiceHubDispatcher(IReadOnlyList <string> hubNames,
                             IServiceConnectionManager serviceConnectionManager,
                             IServiceConnectionContainerFactory serviceConnectionContainerFactory,
                             IOptions <ServiceOptions> options,
                             ILoggerFactory loggerFactory)
 {
     _hubNames                          = hubNames;
     _name                              = $"{nameof(ServiceHubDispatcher)}[{string.Join(",", hubNames)}]";
     _loggerFactory                     = loggerFactory;
     _serviceConnectionManager          = serviceConnectionManager ?? throw new ArgumentNullException(nameof(serviceConnectionManager));
     _serviceConnectionContainerFactory = serviceConnectionContainerFactory;
     _options                           = options?.Value;
     _logger                            = _loggerFactory.CreateLogger <ServiceHubDispatcher>();
 }
        public ServiceEndpointProvider(ServiceOptions options)
        {
            var connectionString = options.ConnectionString;

            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException(ConnectionStringNotFound);
            }

            _accessTokenLifetime = options.AccessTokenLifetime;

            // Version is ignored for aspnet signalr case
            (_endpoint, _accessKey, _, _port) = ConnectionStringParser.Parse(connectionString);
        }
 public MultiEndpointServiceConnectionContainerFactory(
     IServiceConnectionFactory serviceConnectionFactory,
     IServiceEndpointManager serviceEndpointManager,
     IEndpointRouter router,
     IOptions <ServiceOptions> options,
     IServerNameProvider nameProvider,
     ILoggerFactory loggerFactory)
 {
     _loggerFactory            = loggerFactory;
     _router                   = router ?? throw new ArgumentNullException(nameof(router));
     _serviceConnectionFactory = serviceConnectionFactory;
     _nameProvider             = nameProvider;
     _options                  = options?.Value;
     _serviceEndpointManager   = serviceEndpointManager ?? throw new ArgumentNullException(nameof(serviceEndpointManager));
 }
        public ServiceEndpointProvider(
            ServiceEndpoint endpoint,
            ServiceOptions options)
        {
            _accessTokenLifetime = options.AccessTokenLifetime;

            // Version is ignored for aspnet signalr case
            _endpoint       = endpoint.Endpoint;
            _clientEndpoint = endpoint.ClientEndpoint ?? endpoint.Endpoint;
            _accessKey      = endpoint.AccessKey;
            _appName        = options.ApplicationName;
            _port           = endpoint.Port;
            _algorithm      = options.AccessTokenAlgorithm;

            Proxy = options.Proxy;
        }
Пример #7
0
        public ConnectionFactory(IReadOnlyList <string> hubNames, HubConfiguration hubConfig)
        {
            _config   = hubConfig;
            _hubNames = hubNames;
            _name     = $"{nameof(ConnectionFactory)}[{string.Join(",", hubNames)}]";
            _userId   = GenerateServerName();

            _loggerFactory            = hubConfig.Resolver.Resolve <ILoggerFactory>() ?? NullLoggerFactory.Instance;
            _protocol                 = hubConfig.Resolver.Resolve <IServiceProtocol>();
            _serviceConnectionManager = hubConfig.Resolver.Resolve <IServiceConnectionManager>();
            _clientConnectionManager  = hubConfig.Resolver.Resolve <IClientConnectionManager>();
            _endpoint                 = hubConfig.Resolver.Resolve <IServiceEndpointProvider>();
            _options = hubConfig.Resolver.Resolve <IOptions <ServiceOptions> >().Value;

            _logger = _loggerFactory.CreateLogger <ConnectionFactory>();
        }
 public ServiceHubDispatcher(IReadOnlyList <string> hubNames, IServiceProtocol protocol,
                             IServiceConnectionManager serviceConnectionManager, IClientConnectionManager clientConnectionManager,
                             IServiceEndpointManager serviceEndpointManager,
                             IEndpointRouter router,
                             IOptions <ServiceOptions> options, ILoggerFactory loggerFactory)
 {
     _hubNames                 = hubNames;
     _name                     = $"{nameof(ServiceHubDispatcher)}[{string.Join(",", hubNames)}]";
     _loggerFactory            = loggerFactory;
     _protocol                 = protocol ?? throw new ArgumentNullException(nameof(protocol));
     _router                   = router ?? throw new ArgumentNullException(nameof(router));
     _serviceConnectionManager = serviceConnectionManager ?? throw new ArgumentNullException(nameof(serviceConnectionManager));
     _clientConnectionManager  = clientConnectionManager ?? throw new ArgumentNullException(nameof(clientConnectionManager));
     _options                  = options?.Value;
     _serviceEndpointManager   = serviceEndpointManager ?? throw new ArgumentNullException(nameof(serviceEndpointManager));
     _logger                   = _loggerFactory.CreateLogger <ServiceHubDispatcher>();
 }
Пример #9
0
        public ServiceEndpointProvider(ServiceEndpoint endpoint, ServiceOptions options)
        {
            var connectionString = endpoint.ConnectionString;

            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException(ConnectionStringNotFound);
            }

            _accessTokenLifetime = options.AccessTokenLifetime;

            // Version is ignored for aspnet signalr case
            _endpoint  = endpoint.Endpoint;
            _accessKey = endpoint.AccessKey;
            _appName   = options.ApplicationName;
            _port      = endpoint.Port;
            Proxy      = options.Proxy;
        }
Пример #10
0
        public ServiceEndpointProvider(ServiceEndpoint endpoint, ServiceOptions options, TimeSpan?ttl = null)
        {
            var connectionString = endpoint.ConnectionString;

            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException(ConnectionStringNotFound);
            }

            _accessTokenLifetime = ttl ?? Constants.DefaultAccessTokenLifetime;

            // Version is ignored for aspnet signalr case
            _endpoint   = endpoint.Endpoint;
            _accessKey  = endpoint.AccessKey;
            _appName    = options.ApplicationName;
            _isolateApp = options.IsolateApplication;
            _port       = endpoint.Port;
        }
        public ServiceEndpointProvider(
            IServerNameProvider provider,
            ServiceEndpoint endpoint,
            ServiceOptions options,
            ILoggerFactory loggerFactory)
        {
            _accessTokenLifetime = options.AccessTokenLifetime;

            // Version is ignored for aspnet signalr case
            _endpoint       = endpoint.Endpoint;
            _clientEndpoint = endpoint.ClientEndpoint ?? endpoint.Endpoint;
            _accessKey      = endpoint.AccessKey;
            _appName        = options.ApplicationName;
            _port           = endpoint.Port;
            _algorithm      = options.AccessTokenAlgorithm;

            _provider = provider;
            Proxy     = options.Proxy;

            if (endpoint.AccessKey is AadAccessKey key)
            {
                _ = key.UpdateAccessKeyAsync(provider, loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)));
            }
        }
Пример #12
0
 public NegotiateMiddleware(OwinMiddleware next, HubConfiguration configuration, string appName, IServiceEndpointManager endpointManager, IEndpointRouter router, ServiceOptions options, IServerNameProvider serverNameProvider, IConnectionRequestIdProvider connectionRequestIdProvider, ILoggerFactory loggerFactory)
     : base(next)
 {
     _configuration               = configuration;
     _provider                    = configuration.Resolver.Resolve <IUserIdProvider>();
     _appName                     = appName ?? throw new ArgumentNullException(nameof(appName));
     _claimsProvider              = options?.ClaimsProvider;
     _endpointManager             = endpointManager ?? throw new ArgumentNullException(nameof(endpointManager));
     _router                      = router ?? throw new ArgumentNullException(nameof(router));
     _connectionRequestIdProvider = connectionRequestIdProvider ?? throw new ArgumentNullException(nameof(connectionRequestIdProvider));
     _logger                      = loggerFactory?.CreateLogger <NegotiateMiddleware>() ?? throw new ArgumentNullException(nameof(loggerFactory));
     _serverName                  = serverNameProvider?.GetName();
     _mode = options.ServerStickyMode;
     _enableDetailedErrors = configuration.EnableDetailedErrors;
     _endpointsCount       = options.Endpoints.Length;
     _maxPollInterval      = options.MaxPollIntervalInSeconds;
 }
Пример #13
0
 public NegotiateMiddleware(OwinMiddleware next, HubConfiguration configuration, string appName, IServiceEndpointManager endpointManager, IEndpointRouter router, ServiceOptions options, IServerNameProvider serverNameProvider, ILoggerFactory loggerFactory)
     : base(next)
 {
     _configuration   = configuration;
     _provider        = configuration.Resolver.Resolve <IUserIdProvider>();
     _appName         = appName ?? throw new ArgumentNullException(nameof(appName));
     _claimsProvider  = options?.ClaimsProvider;
     _endpointManager = endpointManager ?? throw new ArgumentNullException(nameof(endpointManager));
     _router          = router ?? throw new ArgumentNullException(nameof(router));
     _logger          = loggerFactory?.CreateLogger <NegotiateMiddleware>() ?? throw new ArgumentNullException(nameof(loggerFactory));
     _serverName      = serverNameProvider?.GetName();
     _mode            = options.ServerStickyMode;
 }
Пример #14
0
 public ServiceHubDispatcher(HubConfiguration configuration, string appName, ServiceOptions options) : base(configuration)
 {
     _appName        = appName ?? throw new ArgumentException(nameof(appName));
     _claimsProvider = options?.ClaimsProvider;
 }
Пример #15
0
        internal static ServiceHubDispatcher PrepareAndGetDispatcher(IAppBuilder builder, HubConfiguration configuration, ServiceOptions options, string applicationName, ILoggerFactory loggerFactory)
        {
            // Ensure we have the conversions for MS.Owin so that
            // the app builder respects the OwinMiddleware base class
            SignatureConversions.AddConversions(builder);

            // ServiceEndpointManager needs the logger
            var hubs = GetAvailableHubNames(configuration);

            // Get the one from DI or new a default one
            var router = configuration.Resolver.Resolve <IEndpointRouter>() ?? new DefaultEndpointRouter();

            var serverNameProvider = configuration.Resolver.Resolve <IServerNameProvider>();

            if (serverNameProvider == null)
            {
                serverNameProvider = new DefaultServerNameProvider();
                configuration.Resolver.Register(typeof(IServerNameProvider), () => serverNameProvider);
            }

            var endpoint = new ServiceEndpointManager(serverNameProvider, options, loggerFactory);

            configuration.Resolver.Register(typeof(IServiceEndpointManager), () => endpoint);

            var requestIdProvider = configuration.Resolver.Resolve <IConnectionRequestIdProvider>();

            if (requestIdProvider == null)
            {
                requestIdProvider = new DefaultConnectionRequestIdProvider();
                configuration.Resolver.Register(typeof(IConnectionRequestIdProvider), () => requestIdProvider);
            }

            builder.Use <NegotiateMiddleware>(configuration, applicationName, endpoint, router, options, serverNameProvider, requestIdProvider, loggerFactory);

            builder.RunSignalR(configuration);

            // Fetch the trace manager from DI and add logger provider
            var traceManager = configuration.Resolver.Resolve <ITraceManager>();

            if (traceManager != null)
            {
                loggerFactory.AddProvider(new TraceManagerLoggerProvider(traceManager));
            }

            configuration.Resolver.Register(typeof(ILoggerFactory), () => loggerFactory);

            // TODO: Using IOptions looks wierd, thinking of a way removing it
            // share the same object all through
            var serviceOptions = Options.Create(options);

            // For safety, ALWAYS register abstract classes or interfaces
            // Some third-party DI frameworks such as Ninject, implicit self-binding concrete types:
            // https://github.com/ninject/ninject/wiki/dependency-injection-with-ninject#skipping-the-type-binding-bit--implicit-self-binding-of-concrete-types
            configuration.Resolver.Register(typeof(IOptions <ServiceOptions>), () => serviceOptions);

            var serviceProtocol = new ServiceProtocol();

            configuration.Resolver.Register(typeof(IServiceProtocol), () => serviceProtocol);

            // allow override from tests
            var scm = configuration.Resolver.Resolve <IServiceConnectionManager>();

            if (scm == null)
            {
                scm = new ServiceConnectionManager(applicationName, hubs);
                configuration.Resolver.Register(typeof(IServiceConnectionManager), () => scm);
            }

            var ccm = configuration.Resolver.Resolve <IClientConnectionManager>();

            if (ccm == null)
            {
                ccm = new ClientConnectionManager(configuration, loggerFactory);
                configuration.Resolver.Register(typeof(IClientConnectionManager), () => ccm);
            }

            var atm = new AzureTransportManager(configuration.Resolver);

            configuration.Resolver.Register(typeof(ITransportManager), () => atm);

            var parser = new SignalRMessageParser(hubs, configuration.Resolver, loggerFactory.CreateLogger <SignalRMessageParser>());

            configuration.Resolver.Register(typeof(IMessageParser), () => parser);

            var smb = new ServiceMessageBus(configuration.Resolver, loggerFactory.CreateLogger <ServiceMessageBus>());

            configuration.Resolver.Register(typeof(IMessageBus), () => smb);

            var scf = configuration.Resolver.Resolve <IServiceConnectionFactory>();

            if (scf == null)
            {
                var connectionFactory = new ConnectionFactory(serverNameProvider, loggerFactory);
                scf = new ServiceConnectionFactory(serviceProtocol, ccm, connectionFactory, loggerFactory, serverNameProvider);
                configuration.Resolver.Register(typeof(IServiceConnectionFactory), () => scf);
            }

            var sccf = new ServiceConnectionContainerFactory(scf, endpoint, router, options, loggerFactory);

            if (hubs?.Count > 0)
            {
                return(new ServiceHubDispatcher(hubs, scm, sccf, serviceOptions, loggerFactory));
            }
            else
            {
                loggerFactory.CreateLogger <DispatcherHelper>().Log(LogLevel.Warning, "No hubs found.");
                return(null);
            }
        }
 public ServiceEndpointManager(ServiceOptions options, ILoggerFactory loggerFactory) :
     base(options,
          loggerFactory?.CreateLogger <ServiceEndpointManager>())
 {
     _options = options;
 }