public ServiceLifetimeManager(
            IServiceConnectionManager <THub> serviceConnectionManager,
            IClientConnectionManager clientConnectionManager,
            IHubProtocolResolver protocolResolver,
            ILogger <ServiceLifetimeManager <THub> > logger,
            AzureSignalRMarkerService marker,
            IOptions <HubOptions> globalHubOptions,
            IOptions <HubOptions <THub> > hubOptions,
            IBlazorDetector blazorDetector)
            : base(
                serviceConnectionManager,
                protocolResolver,
                globalHubOptions,
                hubOptions, logger)
        {
            // after core 3.0 UseAzureSignalR() is not required.
#if NETSTANDARD2_0
            if (!marker.IsConfigured)
            {
                throw new InvalidOperationException(MarkerNotConfiguredError);
            }
#endif
            _clientConnectionManager = clientConnectionManager;

            if (hubOptions.Value.SupportedProtocols != null && hubOptions.Value.SupportedProtocols.Any(x => x.Equals(Constants.Protocol.BlazorPack, StringComparison.OrdinalIgnoreCase)))
            {
                blazorDetector?.TrySetBlazor(typeof(THub).Name, true);
            }
        }
        public ServiceHubDispatcher(
            IServiceProtocol serviceProtocol,
            IHubContext <THub> context,
            IServiceConnectionManager <THub> serviceConnectionManager,
            IClientConnectionManager clientConnectionManager,
            IServiceEndpointManager serviceEndpointManager,
            IOptions <ServiceOptions> options,
            ILoggerFactory loggerFactory,
            IEndpointRouter router,
            IServerNameProvider nameProvider,
            ServerLifetimeManager serverLifetimeManager,
            IClientConnectionFactory clientConnectionFactory,
            IServiceEventHandler serviceEventHandler)
        {
            _serviceProtocol          = serviceProtocol;
            _serviceConnectionManager = serviceConnectionManager;
            _clientConnectionManager  = clientConnectionManager;
            _serviceEndpointManager   = serviceEndpointManager;
            _options = options != null ? options.Value : throw new ArgumentNullException(nameof(options));

            Context = context;

            _router                  = router ?? throw new ArgumentNullException(nameof(router));
            _loggerFactory           = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _logger                  = loggerFactory.CreateLogger <ServiceHubDispatcher <THub> >();
            _clientConnectionFactory = clientConnectionFactory;
            _nameProvider            = nameProvider;
            _hubName                 = typeof(THub).Name;
            _serviceEventHandler     = serviceEventHandler;

            serverLifetimeManager?.Register(ShutdownAsync);
        }
Пример #3
0
        public MockServiceHubDispatcher(
            IServiceProtocol serviceProtocol,
            IHubContext <THub> context,
            IServiceConnectionManager <THub> serviceConnectionManager,
            IClientConnectionManager clientConnectionManager,
            IServiceEndpointManager serviceEndpointManager,
            IOptions <ServiceOptions> options,
            ILoggerFactory loggerFactory,
            IEndpointRouter router,
            IServerNameProvider nameProvider,
            ServerLifetimeManager serverLifetimeManager,
            IClientConnectionFactory clientConnectionFactory) : base(
                serviceProtocol,
                context,
                serviceConnectionManager,
                clientConnectionManager,
                serviceEndpointManager,
                options,
                loggerFactory,
                router,
                nameProvider,
                serverLifetimeManager,
                clientConnectionFactory,
                null)
        {
            MockService = new ConnectionTrackingMockService();

            // just store copies of these locally to keep the base class' accessor modifiers intact
            _loggerFactory           = loggerFactory;
            _clientConnectionManager = clientConnectionManager;
            _serviceProtocol         = serviceProtocol;
            _clientConnectionFactory = clientConnectionFactory;
        }
Пример #4
0
        private static void PrepareConnection(IServiceConnectionManager scm, out SortedList <string, ServiceMessage> output)
        {
            var result = new SortedList <string, ServiceMessage>();

            scm.Initialize(new TestServiceConnectionContainerFactory(result));
            output = result;
        }
Пример #5
0
 public ServiceMessageBus(IDependencyResolver resolver) : base(resolver)
 {
     // TODO: find a more decent way instead of DI, it can be easily overriden
     _serviceConnectionManager = resolver.Resolve <IServiceConnectionManager>() ?? throw new ArgumentNullException(nameof(IServiceConnectionManager));
     _parser     = resolver.Resolve <IMessageParser>() ?? throw new ArgumentNullException(nameof(IMessageParser));
     _ackHandler = resolver.Resolve <IAckHandler>() ?? throw new ArgumentNullException(nameof(IAckHandler));
 }
Пример #6
0
        public ServiceConnectionBase(IServiceProtocol serviceProtocol, ILoggerFactory loggerFactory, string connectionId, IServiceConnectionManager serviceConnectionManager, ServerConnectionType connectionType)
        {
            ServiceProtocol = serviceProtocol;
            ConnectionId    = connectionId;

            _connectionType = connectionType;

            _cachedPingBytes          = serviceProtocol.GetMessageBytes(PingMessage.Instance);
            _handshakeRequest         = new HandshakeRequestMessage(serviceProtocol.Version, (int)connectionType);
            _logger                   = loggerFactory?.CreateLogger <ServiceConnectionBase>() ?? NullLogger <ServiceConnectionBase> .Instance;
            _serviceConnectionManager = serviceConnectionManager;
        }
Пример #7
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>();
 }
Пример #8
0
        private static void PrepareConnection(IServiceConnectionManager scm, out SortedList <string, ServiceMessage> output)
        {
            var result = new SortedList <string, ServiceMessage>();

            scm.Initialize(hub => new TestServiceConnection(hub,
                                                            m =>
            {
                lock (result)
                {
                    result.Add(hub, m.Item1);
                }
            }), 5);
            output = result;
        }
Пример #9
0
        public ServiceLifetimeManager(IServiceConnectionManager <THub> serviceConnectionManager,
                                      IClientConnectionManager clientConnectionManager, IHubProtocolResolver protocolResolver,
                                      ILogger <ServiceLifetimeManager <THub> > logger, AzureSignalRMarkerService marker)
        {
            if (!marker.IsConfigured)
            {
                throw new InvalidOperationException(MarkerNotConfiguredError);
            }

            _serviceConnectionManager = serviceConnectionManager;
            _clientConnectionManager  = clientConnectionManager;
            _allProtocols             = protocolResolver.AllProtocols;
            _logger = logger;
        }
Пример #10
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>();
        }
Пример #11
0
 public ServiceConnection(IServiceProtocol serviceProtocol,
                          IClientConnectionManager clientConnectionManager,
                          IConnectionFactory connectionFactory,
                          ILoggerFactory loggerFactory,
                          ConnectionDelegate connectionDelegate,
                          IClientConnectionFactory clientConnectionFactory,
                          string connectionId,
                          IServiceConnectionManager manager,
                          ServerConnectionType connectionType = ServerConnectionType.Default) :
     base(serviceProtocol, loggerFactory, connectionId, manager, connectionType)
 {
     _clientConnectionManager = clientConnectionManager;
     _connectionFactory       = connectionFactory;
     _connectionDelegate      = connectionDelegate;
     _clientConnectionFactory = clientConnectionFactory;
     _logger = loggerFactory?.CreateLogger <ServiceConnection>() ?? NullLogger <ServiceConnection> .Instance;
 }
Пример #12
0
 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>();
 }
Пример #13
0
        protected override Task StartCoreAsync(string serverUrl, ITestOutputHelper output, Dictionary <string, string> configuration)
        {
            var userIdProvider = new UserIdProvider();

            _loggerFactory = new LoggerFactory().AddXunit(output);

            _webApp = WebApp.Start(new StartOptions(serverUrl), app =>
            {
                var hubConfiguration = Utility.GetActualHubConfig(_loggerFactory);
                hubConfiguration.Resolver.Register(typeof(TestHub), () => new TestHub(HubConnectionManager));
                hubConfiguration.Resolver.Register(typeof(IUserIdProvider), () => userIdProvider);
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                app.MapAzureSignalR("/signalr", GetType().FullName, hubConfiguration, options => options.ConnectionString = TestConfiguration.Instance.ConnectionString);
                _scm = hubConfiguration.Resolver.Resolve <IServiceConnectionManager>();
                GlobalHost.TraceManager.Switch.Level = SourceLevels.Information;
            });
            return(Task.CompletedTask);
        }
        public ServiceLifetimeManager(IServiceConnectionManager <THub> serviceConnectionManager,
                                      IClientConnectionManager clientConnectionManager, IHubProtocolResolver protocolResolver,
                                      ILogger <ServiceLifetimeManager <THub> > logger, AzureSignalRMarkerService marker)
            : base(serviceConnectionManager, protocolResolver)
        {
            // after core 3.0 UseAzureSignalR() is not required.
#if !NETCOREAPP3_0
            if (!marker.IsConfigured)
            {
                throw new InvalidOperationException(MarkerNotConfiguredError);
            }
#endif

            _serviceConnectionManager = serviceConnectionManager;
            _clientConnectionManager  = clientConnectionManager;
            _allProtocols             = protocolResolver.AllProtocols;
            _logger = logger;
        }
Пример #15
0
        protected override Task StartCoreAsync(string serverUrl, ITestOutputHelper output, Dictionary <string, string> configuration)
        {
            _host = new WebHostBuilder()
                    .ConfigureServices(services =>
            {
                services.AddSingleton <TestHubConnectionManager>(HubConnectionManager);
            })
                    .ConfigureLogging(logging => logging.AddXunit(output))
                    .ConfigureAppConfiguration(builder => builder.AddInMemoryCollection(configuration))
                    .UseStartup <TestStartup>()
                    .UseUrls(serverUrl)
                    .UseKestrel()
                    .Build();

            _scm = _host.Services.GetRequiredService <IServiceConnectionManager <TestHub> >();

            return(_host.StartAsync());
        }
Пример #16
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();
        }
Пример #17
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;
        }
        private HubLifetimeManager <TestHub> MockLifetimeManager(IServiceConnectionManager <TestHub> serviceConnectionManager, IClientConnectionManager clientConnectionManager = null, IBlazorDetector blazorDetector = null)
        {
            clientConnectionManager ??= new ClientConnectionManager();

            var protocolResolver = new DefaultHubProtocolResolver(new IHubProtocol[]
            {
                new JsonHubProtocol(),
                new MessagePackHubProtocol(),
                new CustomHubProtocol(),
            },
                                                                  NullLogger <DefaultHubProtocolResolver> .Instance
                                                                  );
            IOptions <HubOptions> globalHubOptions = Options.Create(new HubOptions()
            {
                SupportedProtocols = new List <string>()
                {
                    MockProtocol
                }
            });
            IOptions <HubOptions <TestHub> > localHubOptions = Options.Create(new HubOptions <TestHub>()
            {
                SupportedProtocols = new List <string>()
                {
                    MockProtocol
                }
            });

            return(new ServiceLifetimeManager <TestHub>(
                       serviceConnectionManager,
                       clientConnectionManager,
                       protocolResolver,
                       Logger,
                       Marker,
                       globalHubOptions,
                       localHubOptions,
                       blazorDetector
                       ));
        }
        public ServiceLifetimeManager(
            IServiceConnectionManager <THub> serviceConnectionManager,
            IClientConnectionManager clientConnectionManager,
            IHubProtocolResolver protocolResolver,
            ILogger <ServiceLifetimeManager <THub> > logger,
            AzureSignalRMarkerService marker,
            IOptions <HubOptions> globalHubOptions,
            IOptions <HubOptions <THub> > hubOptions)
            : base(
                serviceConnectionManager,
                protocolResolver,
                globalHubOptions,
                hubOptions, logger)
        {
            // after core 3.0 UseAzureSignalR() is not required.
#if NETSTANDARD2_0
            if (!marker.IsConfigured)
            {
                throw new InvalidOperationException(MarkerNotConfiguredError);
            }
#endif
            _clientConnectionManager = clientConnectionManager;
        }
 public WebSocketsHubLifetimeManager(IServiceConnectionManager <THub> serviceConnectionManager, IHubProtocolResolver protocolResolver,
                                     IOptions <HubOptions> globalHubOptions, IOptions <HubOptions <THub> > hubOptions, ILoggerFactory loggerFactory, IOptions <ServiceManagerOptions> serviceManagerOptions) :
     base(serviceConnectionManager, protocolResolver, globalHubOptions, hubOptions, loggerFactory?.CreateLogger(nameof(WebSocketsHubLifetimeManager <Hub>)))
 {
     _serviceManagerOptions = serviceManagerOptions ?? throw new ArgumentNullException(nameof(serviceManagerOptions));
 }
Пример #21
0
 public ServiceLifetimeManagerBase(IServiceConnectionManager <THub> serviceConnectionManager, IHubProtocolResolver protocolResolver, IOptions <HubOptions> globalHubOptions, IOptions <HubOptions <THub> > hubOptions, ILogger logger)
 {
     Logger = logger ?? throw new ArgumentNullException(nameof(logger));
     ServiceConnectionContainer = serviceConnectionManager;
     _messageSerializer         = new DefaultHubMessageSerializer(protocolResolver, globalHubOptions.Value.SupportedProtocols, hubOptions.Value.SupportedProtocols);
 }
Пример #22
0
 public IServiceConnection Create(IConnectionFactory connectionFactory, IServiceConnectionManager manager, ServerConnectionType type)
 {
     return(new ServiceConnection(_serviceProtocol, _clientConnectionManager, connectionFactory,
                                  _loggerFactory, _connectionDelegate, _clientConnectionFactory,
                                  Guid.NewGuid().ToString(), manager, type));
 }
Пример #23
0
 public WebSocketsHubLifetimeManager(IServiceConnectionManager <THub> serviceConnectionManager, IHubProtocolResolver protocolResolver) : base(serviceConnectionManager, protocolResolver)
 {
 }
Пример #24
0
        private static IDependencyResolver GetDefaultResolver(IReadOnlyList <string> hubs, out IServiceConnectionManager scm)
        {
            var resolver = new DefaultDependencyResolver();

            resolver.Register(typeof(IServiceProtocol), () => new ServiceProtocol());
            var ccm = new TestClientConnectionManager();

            resolver.Register(typeof(IClientConnectionManager), () => ccm);
            var connectionManager = new ServiceConnectionManager(AppName, hubs);

            resolver.Register(typeof(IServiceConnectionManager), () => connectionManager);
            resolver.Register(typeof(IMessageParser), () => new SignalRMessageParser(hubs, resolver, NullLogger <SignalRMessageParser> .Instance));
            scm = connectionManager;
            return(resolver);
        }
Пример #25
0
 public ServiceLifetimeManagerBase(IServiceConnectionManager <THub> serviceConnectionManager, IHubProtocolResolver protocolResolver, IOptions <HubOptions> globalHubOptions, IOptions <HubOptions <THub> > hubOptions)
 {
     ServiceConnectionContainer = serviceConnectionManager;
     _messageSerializer         = new DefaultHubMessageSerializer(protocolResolver, globalHubOptions.Value.SupportedProtocols, hubOptions.Value.SupportedProtocols);
 }
 public ServiceConnectionProxy(ConnectionDelegate callback             = null, PipeOptions clientPipeOptions = null,
                               TestConnectionFactory connectionFactory = null, IServiceConnectionManager serviceConnectionManager = null)
 {
     ConnectionFactory       = connectionFactory ?? new TestConnectionFactory();
     ClientConnectionManager = new ClientConnectionManager();
     _clientPipeOptions      = clientPipeOptions;
     ServiceConnection       = new ServiceConnection(
         SharedServiceProtocol,
         this,
         ConnectionFactory,
         NullLoggerFactory.Instance,
         callback ?? OnConnectionAsync,
         this,
         Guid.NewGuid().ToString("N"),
         serviceConnectionManager);
     ServiceConnectionContainer = new StrongServiceConnectionContainer(null, connectionFactory, new List <IServiceConnection>()
     {
         ServiceConnection
     }, new ServiceEndpoint("", ""));
 }
Пример #27
0
 public WebSocketsHubLifetimeManager(IServiceConnectionManager <THub> serviceConnectionManager, IHubProtocolResolver protocolResolver,
                                     IOptions <HubOptions> globalHubOptions, IOptions <HubOptions <THub> > hubOptions, ILoggerFactory loggerFactory) :
     base(serviceConnectionManager, protocolResolver, globalHubOptions, hubOptions, loggerFactory?.CreateLogger(nameof(WebSocketsHubLifetimeManager <Hub>)))
 {
 }
Пример #28
0
 public ServiceLifetimeManagerBase(IServiceConnectionManager <THub> serviceConnectionManager, IHubProtocolResolver protocolResolver)
 {
     ServiceConnectionContainer = serviceConnectionManager;
     _allProtocols = protocolResolver.AllProtocols;
 }
Пример #29
0
 public WebSocketsHubLifetimeManager(IServiceConnectionManager <THub> serviceConnectionManager, IHubProtocolResolver protocolResolver,
                                     IOptions <HubOptions> globalHubOptions, IOptions <HubOptions <THub> > hubOptions) : base(serviceConnectionManager, protocolResolver, globalHubOptions, hubOptions)
 {
 }