/// <summary>
        /// Initializes a new instance of the <see cref="HubConnectionHandler{THub}"/> class.
        /// </summary>
        /// <param name="lifetimeManager">The hub lifetime manager.</param>
        /// <param name="protocolResolver">The protocol resolver used to resolve the protocols between client and server.</param>
        /// <param name="globalHubOptions">The global options used to initialize hubs.</param>
        /// <param name="hubOptions">Hub specific options used to initialize hubs. These options override the global options.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="userIdProvider">The user ID provider used to get the user ID from a hub connection.</param>
        /// <param name="serviceScopeFactory">The service scope factory.</param>
        /// <remarks>This class is typically created via dependency injection.</remarks>
        public HubConnectionHandler(HubLifetimeManager <THub> lifetimeManager,
                                    IHubProtocolResolver protocolResolver,
                                    IOptions <HubOptions> globalHubOptions,
                                    IOptions <HubOptions <THub> > hubOptions,
                                    ILoggerFactory loggerFactory,
                                    IUserIdProvider userIdProvider,
                                    IServiceScopeFactory serviceScopeFactory
                                    )
        {
            _protocolResolver = protocolResolver;
            _lifetimeManager  = lifetimeManager;
            _loggerFactory    = loggerFactory;
            _hubOptions       = hubOptions.Value;
            _globalHubOptions = globalHubOptions.Value;
            _logger           = loggerFactory.CreateLogger <HubConnectionHandler <THub> >();
            _userIdProvider   = userIdProvider;

            _enableDetailedErrors = _hubOptions.EnableDetailedErrors ?? _globalHubOptions.EnableDetailedErrors ?? false;
            _maximumMessageSize   = _hubOptions.MaximumReceiveMessageSize ?? _globalHubOptions.MaximumReceiveMessageSize;

            _dispatcher = new DefaultHubDispatcher <THub>(
                serviceScopeFactory,
                new HubContext <THub>(lifetimeManager),
                hubOptions,
                globalHubOptions,
                new Logger <DefaultHubDispatcher <THub> >(loggerFactory));
        }
Esempio n. 2
0
 public HubEndPoint(HubLifetimeManager <THub> lifetimeManager,
                    IHubContext <THub> hubContext,
                    InvocationAdapterRegistry registry,
                    ILogger <HubEndPoint <THub> > logger,
                    IServiceScopeFactory serviceScopeFactory) : base(lifetimeManager, hubContext, registry, logger, serviceScopeFactory)
 {
 }
Esempio n. 3
0
        public HubContext(HubLifetimeManager <THub> lifetimeManager)
        {
            _lifetimeManager = lifetimeManager;
            All = TypedClientBuilder <T> .Build(new AllClientProxy <THub>(_lifetimeManager));

            Groups = new GroupManager <THub>(lifetimeManager);
        }
Esempio n. 4
0
 private static async Task InvokeConnectionAsync(HubLifetimeManager <ClientHub> clientHubManager,
                                                 HubMethodInvocationMessage message)
 {
     if (message.TryGetConnectionId(out var connectionId))
     {
         await clientHubManager.InvokeConnectionAsync(connectionId, message.Target, message.Arguments);
     }
 }
Esempio n. 5
0
 private static async Task RemoveGroupAsync(HubLifetimeManager <ClientHub> clientHubManager,
                                            HubMethodInvocationMessage message)
 {
     if (message.TryGetGroupName(out var groupName) &&
         message.TryGetConnectionId(out var connectionId))
     {
         await clientHubManager.RemoveGroupAsync(connectionId, groupName);
     }
 }
Esempio n. 6
0
 private static async Task InvokeGroupAsync(HubLifetimeManager <ClientHub> clientHubManager,
                                            HubMethodInvocationMessage message)
 {
     if (message.TryGetGroupName(out var groupName))
     {
         await clientHubManager.InvokeGroupAsync(groupName, message.Target,
                                                 message.Arguments);
     }
 }
Esempio n. 7
0
 private static async Task InvokeAllExceptAsync(HubLifetimeManager <ClientHub> clientHubManager,
                                                HubMethodInvocationMessage message)
 {
     if (message.TryGetExcludedIds(out var excludedIds))
     {
         await clientHubManager.InvokeAllExceptAsync(message.Target, message.Arguments,
                                                     excludedIds);
     }
 }
Esempio n. 8
0
        public HubServer(HubLifetimeManager <THub> lifetimeManager,
                         IHubInvoker <THub> hubInvoker,
                         ILoggerFactory loggerFactory)
        {
            _lifetimeManager = lifetimeManager;
            _hubInvoker      = hubInvoker;

            _loggerFactory = loggerFactory;
            _logger        = loggerFactory.CreateLogger <HubServer <THub> >();
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HubConnectionHandler{THub}"/> class.
        /// </summary>
        /// <param name="lifetimeManager">The hub lifetime manager.</param>
        /// <param name="protocolResolver">The protocol resolver used to resolve the protocols between client and server.</param>
        /// <param name="globalHubOptions">The global options used to initialize hubs.</param>
        /// <param name="hubOptions">Hub specific options used to initialize hubs. These options override the global options.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="userIdProvider">The user ID provider used to get the user ID from a hub connection.</param>
        /// <param name="serviceScopeFactory">The service scope factory.</param>
        /// <remarks>This class is typically created via dependency injection.</remarks>
        public HubConnectionHandler(HubLifetimeManager <THub> lifetimeManager,
                                    IHubProtocolResolver protocolResolver,
                                    IOptions <HubOptions> globalHubOptions,
                                    IOptions <HubOptions <THub> > hubOptions,
                                    ILoggerFactory loggerFactory,
                                    IUserIdProvider userIdProvider,
                                    IServiceScopeFactory serviceScopeFactory
                                    )
        {
            _protocolResolver = protocolResolver;
            _lifetimeManager  = lifetimeManager;
            _loggerFactory    = loggerFactory;
            _hubOptions       = hubOptions.Value;
            _globalHubOptions = globalHubOptions.Value;
            _logger           = loggerFactory.CreateLogger <HubConnectionHandler <THub> >();
            _userIdProvider   = userIdProvider;

            _enableDetailedErrors = false;

            List <IHubFilter> hubFilters = null;

            if (_hubOptions.UserHasSetValues)
            {
                _maximumMessageSize   = _hubOptions.MaximumReceiveMessageSize;
                _enableDetailedErrors = _hubOptions.EnableDetailedErrors ?? _enableDetailedErrors;

                if (_hubOptions.HubFilters != null)
                {
                    hubFilters = new List <IHubFilter>();
                    hubFilters.AddRange(_hubOptions.HubFilters);
                }
            }
            else
            {
                _maximumMessageSize   = _globalHubOptions.MaximumReceiveMessageSize;
                _enableDetailedErrors = _globalHubOptions.EnableDetailedErrors ?? _enableDetailedErrors;

                if (_globalHubOptions.HubFilters != null)
                {
                    hubFilters = new List <IHubFilter>();
                    hubFilters.AddRange(_globalHubOptions.HubFilters);
                }
            }

            _dispatcher = new DefaultHubDispatcher <THub>(
                serviceScopeFactory,
                new HubContext <THub>(lifetimeManager),
                _enableDetailedErrors,
                new Logger <DefaultHubDispatcher <THub> >(loggerFactory),
                hubFilters);
        }
Esempio n. 10
0
 public HubEndPoint(HubLifetimeManager <THub> lifetimeManager,
                    IHubProtocolResolver protocolResolver,
                    IOptions <HubOptions> hubOptions,
                    ILoggerFactory loggerFactory,
                    IUserIdProvider userIdProvider,
                    IHubInvoker <THub> hubInvoker)
 {
     _protocolResolver = protocolResolver;
     _lifetimeManager  = lifetimeManager;
     _loggerFactory    = loggerFactory;
     _hubOptions       = hubOptions.Value;
     _logger           = loggerFactory.CreateLogger <HubEndPoint <THub> >();
     _userIdProvider   = userIdProvider;
     _hubInvoker       = hubInvoker;
 }
Esempio n. 11
0
        public HubEndPoint(HubLifetimeManager <THub> lifetimeManager,
                           IHubProtocolResolver protocolResolver,
                           IHubContext <THub> hubContext,
                           IOptions <HubOptions> hubOptions,
                           ILogger <HubEndPoint <THub> > logger,
                           IServiceScopeFactory serviceScopeFactory)
        {
            _protocolResolver    = protocolResolver;
            _lifetimeManager     = lifetimeManager;
            _hubContext          = hubContext;
            _hubOptions          = hubOptions;
            _logger              = logger;
            _serviceScopeFactory = serviceScopeFactory;

            DiscoverHubMethods();
        }
Esempio n. 12
0
 public HubEndPoint(HubLifetimeManager <THub> lifetimeManager,
                    IHubProtocolResolver protocolResolver,
                    IOptions <HubOptions> globalHubOptions,
                    IOptions <HubOptions <THub> > hubOptions,
                    ILoggerFactory loggerFactory,
                    IUserIdProvider userIdProvider,
                    HubDispatcher <THub> dispatcher)
 {
     _protocolResolver = protocolResolver;
     _lifetimeManager  = lifetimeManager;
     _loggerFactory    = loggerFactory;
     _hubOptions       = hubOptions.Value;
     _globalHubOptions = globalHubOptions.Value;
     _logger           = loggerFactory.CreateLogger <HubEndPoint <THub> >();
     _userIdProvider   = userIdProvider;
     _dispatcher       = dispatcher;
 }
Esempio n. 13
0
        public HubConnectionHandler(HubLifetimeManager <THub> lifetimeManager,
                                    IHubProtocolResolver protocolResolver,
                                    IOptions <HubOptions> globalHubOptions,
                                    IOptions <HubOptions <THub> > hubOptions,
                                    ILoggerFactory loggerFactory,
                                    IUserIdProvider userIdProvider,
                                    HubDispatcher <THub> dispatcher)
        {
            _protocolResolver = protocolResolver;
            _lifetimeManager  = lifetimeManager;
            _loggerFactory    = loggerFactory;
            _hubOptions       = hubOptions.Value;
            _globalHubOptions = globalHubOptions.Value;
            _logger           = loggerFactory.CreateLogger <HubConnectionHandler <THub> >();
            _userIdProvider   = userIdProvider;
            _dispatcher       = dispatcher;

            _enableDetailedErrors = _hubOptions.EnableDetailedErrors ?? _globalHubOptions.EnableDetailedErrors ?? false;
        }
Esempio n. 14
0
        public ServiceConnection(IConnection connection,
                                 IHubProtocol protocol,
                                 HubLifetimeManager <THub> lifetimeManager,
                                 IHubInvoker <THub> hubInvoker,
                                 ILoggerFactory loggerFactory)
        {
            _connection      = connection ?? throw new ArgumentNullException(nameof(connection));
            _protocol        = protocol ?? throw new ArgumentNullException(nameof(protocol));
            _loggerFactory   = loggerFactory ?? NullLoggerFactory.Instance;
            _logger          = _loggerFactory.CreateLogger <ServiceConnection <THub> >();
            _hubInvoker      = hubInvoker;
            _lifetimeManager = lifetimeManager;
            _output          = Channel.CreateUnbounded <HubMessage>();

            // Create the timer for timeout, but disabled by default (we enable it when started).
            _timeoutTimer = new Timer(state => ((ServiceConnection <THub>)state).TimeoutElapsed(), this, Timeout.Infinite, Timeout.Infinite);

            connection.OnReceived((data, state) => ((ServiceConnection <THub>)state).OnDataReceivedAsync(data), this);
        }
Esempio n. 15
0
        public HubEndPoint(HubLifetimeManager <THub> lifetimeManager,
                           IHubProtocolResolver protocolResolver,
                           IHubContext <THub> hubContext,
                           IOptions <HubOptions> hubOptions,
                           ILoggerFactory loggerFactory,
                           IServiceScopeFactory serviceScopeFactory,
                           IUserIdProvider userIdProvider)
        {
            _protocolResolver    = protocolResolver;
            _lifetimeManager     = lifetimeManager;
            _hubContext          = hubContext;
            _loggerFactory       = loggerFactory;
            _hubOptions          = hubOptions.Value;
            _logger              = loggerFactory.CreateLogger <HubEndPoint <THub> >();
            _serviceScopeFactory = serviceScopeFactory;
            _userIdProvider      = userIdProvider;

            DiscoverHubMethods();
        }
Esempio n. 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HubConnectionHandler{THub}"/> class.
        /// </summary>
        /// <param name="lifetimeManager">The hub lifetime manager.</param>
        /// <param name="protocolResolver">The protocol resolver used to resolve the protocols between client and server.</param>
        /// <param name="globalHubOptions">The global options used to initialize hubs.</param>
        /// <param name="hubOptions">Hub specific options used to initialize hubs. These options override the global options.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="userIdProvider">The user ID provider used to get the user ID from a hub connection.</param>
        /// <param name="dispatcher">The hub dispatcher used to dispatch incoming messages to hubs.</param>
        /// <remarks>This class is typically created via dependency injection.</remarks>
        public HubConnectionHandler(HubLifetimeManager <THub> lifetimeManager,
                                    IHubProtocolResolver protocolResolver,
                                    IOptions <HubOptions> globalHubOptions,
                                    IOptions <HubOptions <THub> > hubOptions,
                                    ILoggerFactory loggerFactory,
                                    IUserIdProvider userIdProvider,
#pragma warning disable PUB0001 // Pubternal type in public API
                                    HubDispatcher <THub> dispatcher
#pragma warning restore PUB0001
                                    )
        {
            _protocolResolver = protocolResolver;
            _lifetimeManager  = lifetimeManager;
            _loggerFactory    = loggerFactory;
            _hubOptions       = hubOptions.Value;
            _globalHubOptions = globalHubOptions.Value;
            _logger           = loggerFactory.CreateLogger <HubConnectionHandler <THub> >();
            _userIdProvider   = userIdProvider;
            _dispatcher       = dispatcher;

            _enableDetailedErrors = _hubOptions.EnableDetailedErrors ?? _globalHubOptions.EnableDetailedErrors ?? false;
        }
Esempio n. 17
0
 public AllClientProxy(HubLifetimeManager <THub> lifetimeManager)
 {
     _lifetimeManager = lifetimeManager;
 }
Esempio n. 18
0
 public GroupExceptProxy(HubLifetimeManager <THub> lifetimeManager, string groupName, IReadOnlyList <string> excludedIds)
 {
     _lifetimeManager = lifetimeManager;
     _groupName       = groupName;
     _excludedIds     = excludedIds;
 }
Esempio n. 19
0
 public MultipleGroupProxy(HubLifetimeManager <THub> lifetimeManager, IReadOnlyList <string> groupNames)
 {
     _lifetimeManager = lifetimeManager;
     _groupNames      = groupNames;
 }
Esempio n. 20
0
 public GroupProxy(HubLifetimeManager <THub> lifetimeManager, string groupName)
 {
     _lifetimeManager = lifetimeManager;
     _groupName       = groupName;
 }
Esempio n. 21
0
 public MultipleUserProxy(HubLifetimeManager <THub> lifetimeManager, IReadOnlyList <string> userIds)
 {
     _lifetimeManager = lifetimeManager;
     _userIds         = userIds;
 }
Esempio n. 22
0
 public GroupManager(HubLifetimeManager <THub> lifetimeManager)
 {
     _lifetimeManager = lifetimeManager;
 }
Esempio n. 23
0
 public MultipleClientProxy(HubLifetimeManager <THub> lifetimeManager, IReadOnlyList <string> connectionIds)
 {
     _lifetimeManager = lifetimeManager;
     _connectionIds   = connectionIds;
 }
Esempio n. 24
0
 public SingleClientProxy(HubLifetimeManager <THub> lifetimeManager, string connectionId)
 {
     _lifetimeManager = lifetimeManager;
     _connectionId    = connectionId;
 }
Esempio n. 25
0
 public UserProxy(HubLifetimeManager <THub> lifetimeManager, string userId)
 {
     _lifetimeManager = lifetimeManager;
     _userId          = userId;
 }
Esempio n. 26
0
 public AllClientsExceptProxy(HubLifetimeManager <THub> lifetimeManager, IReadOnlyList <string> excludedIds)
 {
     _lifetimeManager = lifetimeManager;
     _excludedIds     = excludedIds;
 }
Esempio n. 27
0
 public HubContext(HubLifetimeManager <THub> lifetimeManager)
 {
     _lifetimeManager = lifetimeManager;
     _clients         = new HubClients <THub, T>(_lifetimeManager);
     Groups           = new GroupManager <THub>(lifetimeManager);
 }
Esempio n. 28
0
 public HubClients(HubLifetimeManager <THub> lifetimeManager)
 {
     _lifetimeManager = lifetimeManager;
     All = TypedClientBuilder <T> .Build(new AllClientProxy <THub>(_lifetimeManager));
 }
Esempio n. 29
0
 private static async Task InvokeAllAsync(HubLifetimeManager <ClientHub> clientHubManager,
                                          HubMethodInvocationMessage message)
 {
     await clientHubManager.InvokeAllAsync(message.Target, message.Arguments);
 }
Esempio n. 30
0
 public HubClients(HubLifetimeManager <THub> lifetimeManager)
 {
     _lifetimeManager = lifetimeManager;
     All = new AllClientProxy <THub>(_lifetimeManager);
 }