public Task OnConnectedAsync(HubLifetimeContext context,
                                     Func <HubLifetimeContext, Task> next)
        {
            Console.WriteLine($"New client connected. Connection ID: {context.Context.ConnectionId}");

            return(next(context));
        }
예제 #2
0
        public async Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func <HubLifetimeContext, Exception, Task> next)
        {
            _service.StartedMethod.TrySetResult(null);
            await next(context, exception);

            _service.EndMethod.TrySetResult(null);
        }
예제 #3
0
        public override async Task OnConnectedAsync(HubConnectionContext connection)
        {
            IServiceScope scope = null;

            try
            {
                scope = _serviceScopeFactory.CreateScope();

                var hubActivator = scope.ServiceProvider.GetRequiredService <IHubActivator <THub> >();
                var hub          = hubActivator.Create();
                try
                {
                    InitializeHub(hub, connection);

                    if (_onConnectedMiddleware != null)
                    {
                        var context = new HubLifetimeContext(connection.HubCallerContext, scope.ServiceProvider, hub);
                        await _onConnectedMiddleware(context);
                    }
                    else
                    {
                        await hub.OnConnectedAsync();
                    }
                }
                finally
                {
                    hubActivator.Release(hub);
                }
            }
            finally
            {
                await scope.DisposeAsync();
            }
        }
예제 #4
0
 public virtual async Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func<HubLifetimeContext, Exception, Task> next)
 {
     var currentPrincipalAccessor = context.ServiceProvider.GetRequiredService<ICurrentPrincipalAccessor>();
     using (currentPrincipalAccessor.Change(context.Context.User))
     {
         await next(context, exception);
     }
 }
예제 #5
0
 public async Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func <HubLifetimeContext, Exception, Task> next)
 {
     try
     {
         await next(context, exception);
     }
     catch { }
 }
예제 #6
0
 public async Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next)
 {
     try
     {
         await next(context);
     }
     catch { }
 }
예제 #7
0
        public Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next)
        {
            if (_skipOnConnected)
            {
                return(Task.CompletedTask);
            }

            return(next(context));
        }
예제 #8
0
        public Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func <HubLifetimeContext, Exception, Task> next)
        {
            if (_skipOnDisconnected)
            {
                return(Task.CompletedTask);
            }

            return(next(context, exception));
        }
예제 #9
0
        /// <summary>
        /// Updates IdentityContext with current tenant id on connection establishment.
        /// </summary>
        /// <param name="lifetimeContext"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public Task OnConnectedAsync(
            HubLifetimeContext lifetimeContext,
            Func <HubLifetimeContext, Task> next)
        {
            var identityContext = lifetimeContext.ServiceProvider
                                  .GetRequiredService <IIdentityContext>();
            var httpContext = lifetimeContext.Context.GetHttpContext();

            SetTenantFor(identityContext, httpContext !);

            return(next(lifetimeContext));
        }
        public Task OnDisconnectedAsync(HubLifetimeContext context,
                                        Exception?exc,
                                        Func <HubLifetimeContext, Exception?, Task> next)
        {
            Console.WriteLine($"Client with connection ID {context.Context.ConnectionId} has disconnected.");
            if (exc != null)
            {
                Console.WriteLine($"Disconnection exception: {exc}");
            }

            return(next(context, exc));
        }
        public async Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func <HubLifetimeContext, Exception, Task> next)
        {
            var(filter, owned) = GetFilter(context.ServiceProvider);

            try
            {
                await filter.OnDisconnectedAsync(context, exception, next);
            }
            finally
            {
                if (owned)
                {
                    await DisposeFilter(filter);
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Updates user information with data from HttpContext.User object.
        /// </summary>
        /// <param name="lifetimeContext"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public Task OnConnectedAsync(
            HubLifetimeContext lifetimeContext,
            Func <HubLifetimeContext, Task> next)
        {
            var identityContext = lifetimeContext.ServiceProvider
                                  .GetRequiredService <IIdentityContext>();
            var httpContext = lifetimeContext.Context.GetHttpContext();

            if (!identityContext.HasAssociatedUser && httpContext is not null)
            {
                var principal = httpContext.User;
                if (!principal.IsAnyIdentityAuthenticated())
                {
                    return(next(lifetimeContext));
                }

                var userId = principal.Claims
                             .First(c => c.Type == ClaimTypes.NameIdentifier).Value;
                identityContext.SetUserId(userId);
            }

            return(next(lifetimeContext));
        }
예제 #13
0
 public Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next)
 {
     _counter.OnConnectedAsyncCount++;
     return(next(context));
 }
예제 #14
0
        public async Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func <HubLifetimeContext, Exception, Task> next)
        {
            await _syncPoint[2].WaitToContinue();

            await next(context, exception);
        }
예제 #15
0
        public async Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next)
        {
            await _syncPoint[0].WaitToContinue();

            await next(context);
        }
예제 #16
0
 // Optional method
 public Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next)
 {
     return(next(context));
 }
예제 #17
0
 public Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func <HubLifetimeContext, Exception, Task> next)
 {
     _counter.OnDisconnectedAsyncCount++;
     return(next(context, exception));
 }
예제 #18
0
 public async Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next)
 {
     await Authorize(context.Context.GetHttpContext());
     await next(context);
 }