public static void Validate(this ServiceOptions options)
 {
     if (options.MaxPollIntervalInSeconds.HasValue &&
         (options.MaxPollIntervalInSeconds < 1 || options.MaxPollIntervalInSeconds > 300))
     {
         throw new AzureSignalRInvalidServiceOptionsException("MaxPollIntervalInSeconds", "[1,300]");
     }
     if (!string.IsNullOrEmpty(options.ApplicationName) && !AppNameRegex.IsMatch(options.ApplicationName))
     {
         throw new AzureSignalRInvalidServiceOptionsException("ApplicationName", "prefixed with alphabetic characters and only contain alpha-numeric characters or underscore");
     }
 }
        public ServiceEndpointProvider(
            ServiceEndpoint endpoint,
            ServiceOptions serviceOptions)
        {
            _accessTokenLifetime = serviceOptions.AccessTokenLifetime;
            _accessKey           = endpoint.AccessKey;
            _appName             = serviceOptions.ApplicationName;
            _algorithm           = serviceOptions.AccessTokenAlgorithm;

            Proxy = serviceOptions.Proxy;

            _generator = new DefaultServiceEndpointGenerator(endpoint);
        }
        public ServiceEndpointManager(
            IAccessKeySynchronizer synchronizer,
            IOptionsMonitor <ServiceOptions> optionsMonitor,
            ILoggerFactory loggerFactory
            ) :
            base(optionsMonitor.CurrentValue, loggerFactory.CreateLogger <ServiceEndpointManager>())
        {
            _options      = optionsMonitor.CurrentValue;
            _logger       = loggerFactory?.CreateLogger <ServiceEndpointManager>() ?? throw new ArgumentNullException(nameof(loggerFactory));
            _synchronizer = synchronizer;

            optionsMonitor.OnChange(OnChange);
            _scaleTimeout = _options.ServiceScaleTimeout;
        }
Ejemplo n.º 4
0
        public ServiceEndpointManager(IOptionsMonitor <ServiceOptions> optionsMonitor, ILoggerFactory loggerFactory) :
            base(optionsMonitor.CurrentValue, loggerFactory.CreateLogger <ServiceEndpointManager>())
        {
            if (Endpoints.Length == 0)
            {
                throw new ArgumentException(ServiceEndpointProvider.ConnectionStringNotFound);
            }
            _options = optionsMonitor.CurrentValue;
            _logger  = loggerFactory?.CreateLogger <ServiceEndpointManager>() ?? throw new ArgumentNullException(nameof(loggerFactory));

            // TODO: Enable optionsMonitor.OnChange when feature ready.
            // optionsMonitor.OnChange(OnChange);
            _endpointsStore = Endpoints;
        }
Ejemplo n.º 5
0
        public ServiceEndpointManager(
            IServerNameProvider provider,
            IOptionsMonitor <ServiceOptions> optionsMonitor,
            ILoggerFactory loggerFactory
            ) :
            base(optionsMonitor.CurrentValue, loggerFactory.CreateLogger <ServiceEndpointManager>())
        {
            _options       = optionsMonitor.CurrentValue;
            _logger        = loggerFactory?.CreateLogger <ServiceEndpointManager>() ?? throw new ArgumentNullException(nameof(loggerFactory));
            _loggerFactory = loggerFactory;

            optionsMonitor.OnChange(OnChange);
            _scaleTimeout = _options.ServiceScaleTimeout;

            _provider = provider;
        }
Ejemplo n.º 6
0
        private void OnChange(ServiceOptions options)
        {
            Log.DetectConfigurationChanges(_logger);

            // Reset local cache and validate result
            var endpoints = GetValuableEndpoints(GetEndpoints(options));

            if (endpoints.Length == 0)
            {
                Log.EndpointNotFound(_logger);
                return;
            }
            Endpoints = endpoints;

            var updatedEndpoints = GetChangedEndpoints(Endpoints);

            _endpointsStore = Endpoints;
        }
        public ServiceEndpointProvider(
            IServerNameProvider provider,
            ServiceEndpoint endpoint,
            ServiceOptions serviceOptions,
            ILoggerFactory loggerFactory = null
            )
        {
            _accessTokenLifetime = serviceOptions.AccessTokenLifetime;
            _accessKey           = endpoint.AccessKey;
            _appName             = serviceOptions.ApplicationName;
            _algorithm           = serviceOptions.AccessTokenAlgorithm;

            Proxy = serviceOptions.Proxy;

            _generator = new DefaultServiceEndpointGenerator(endpoint);

            _ = UpdateAccessKeyAsync(provider, endpoint, loggerFactory ?? NullLoggerFactory.Instance);
        }
Ejemplo n.º 8
0
        public ServiceEndpointProvider(ServiceEndpoint endpoint, ServiceOptions serviceOptions)
        {
            var connectionString = endpoint.ConnectionString;

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

            _accessTokenLifetime = serviceOptions.AccessTokenLifetime;
            _accessKey           = endpoint.AccessKey;
            _appName             = serviceOptions.ApplicationName;
            Proxy = serviceOptions.Proxy;

            var port    = endpoint.Port;
            var version = endpoint.Version;

            _generator = new DefaultServiceEndpointGenerator(endpoint.Endpoint, _accessKey, version, port);
        }
Ejemplo n.º 9
0
        public ServiceHubDispatcher(IServiceProtocol serviceProtocol,
                                    IServiceConnectionManager <THub> serviceConnectionManager,
                                    IClientConnectionManager clientConnectionManager,
                                    IServiceEndpointProvider serviceEndpointProvider,
                                    IOptions <ServiceOptions> options,
                                    ILoggerFactory loggerFactory,
                                    IClientConnectionFactory clientConnectionFactory)
        {
            _serviceProtocol          = serviceProtocol;
            _serviceConnectionManager = serviceConnectionManager;
            _clientConnectionManager  = clientConnectionManager;
            _serviceEndpointProvider  = serviceEndpointProvider;
            _options = options != null ? options.Value : throw new ArgumentNullException(nameof(options));

            _loggerFactory           = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _logger                  = loggerFactory.CreateLogger <ServiceHubDispatcher <THub> >();
            _clientConnectionFactory = clientConnectionFactory;
            _userId                  = GenerateServerName();
        }
Ejemplo n.º 10
0
        public ServiceEndpointProvider(
            IServerNameProvider provider,
            ServiceEndpoint endpoint,
            ServiceOptions serviceOptions,
            ILoggerFactory loggerFactory)
        {
            _accessTokenLifetime = serviceOptions.AccessTokenLifetime;
            _accessKey           = endpoint.AccessKey;
            _appName             = serviceOptions.ApplicationName;
            _algorithm           = serviceOptions.AccessTokenAlgorithm;

            Proxy = serviceOptions.Proxy;

            _generator = new DefaultServiceEndpointGenerator(endpoint);

            if (endpoint.AccessKey is AadAccessKey key)
            {
                _ = key.UpdateAccessKeyAsync(provider, loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)));
            }
        }
Ejemplo n.º 11
0
        public ServiceHubDispatcher(IServiceProtocol serviceProtocol,
                                    IServiceConnectionManager <THub> serviceConnectionManager,
                                    IClientConnectionManager clientConnectionManager,
                                    IServiceEndpointManager serviceEndpointManager,
                                    IOptions <ServiceOptions> options,
                                    ILoggerFactory loggerFactory,
                                    IEndpointRouter router,
                                    IClientConnectionFactory clientConnectionFactory)
        {
            _serviceProtocol          = serviceProtocol;
            _serviceConnectionManager = serviceConnectionManager;
            _clientConnectionManager  = clientConnectionManager;
            _serviceEndpointManager   = serviceEndpointManager;
            _options = options != null ? options.Value : throw new ArgumentNullException(nameof(options));

            _router                  = router ?? throw new ArgumentNullException(nameof(router));
            _loggerFactory           = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _logger                  = loggerFactory.CreateLogger <ServiceHubDispatcher <THub> >();
            _clientConnectionFactory = clientConnectionFactory;
            _hubName                 = typeof(THub).Name;
        }
Ejemplo n.º 12
0
        private void OnChange(ServiceOptions options)
        {
            Log.DetectConfigurationChanges(_logger);

            ReloadServiceEndpointsAsync(options.Endpoints);
        }
        private void OnChange(ServiceOptions options)
        {
            Log.DetectConfigurationChanges(_logger);

            ReloadServiceEndpointsAsync(ServiceEndpointUtility.Merge(options.ConnectionString, options.Endpoints));
        }