public Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next) { Console.WriteLine($"New client connected. Connection ID: {context.Context.ConnectionId}"); return(next(context)); }
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); }
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(); } }
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); } }
public async Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func <HubLifetimeContext, Exception, Task> next) { try { await next(context, exception); } catch { } }
public async Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next) { try { await next(context); } catch { } }
public Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next) { if (_skipOnConnected) { return(Task.CompletedTask); } return(next(context)); }
public Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func <HubLifetimeContext, Exception, Task> next) { if (_skipOnDisconnected) { return(Task.CompletedTask); } return(next(context, exception)); }
/// <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); } } }
/// <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)); }
public Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next) { _counter.OnConnectedAsyncCount++; return(next(context)); }
public async Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func <HubLifetimeContext, Exception, Task> next) { await _syncPoint[2].WaitToContinue(); await next(context, exception); }
public async Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next) { await _syncPoint[0].WaitToContinue(); await next(context); }
// Optional method public Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next) { return(next(context)); }
public Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func <HubLifetimeContext, Exception, Task> next) { _counter.OnDisconnectedAsyncCount++; return(next(context, exception)); }
public async Task OnConnectedAsync(HubLifetimeContext context, Func <HubLifetimeContext, Task> next) { await Authorize(context.Context.GetHttpContext()); await next(context); }