Пример #1
0
        public async void ServerInserted(IInsertedEntry <Server> server)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                var authService = scope.ServiceProvider.GetService <IAuthorizationService>();

                List <string> connections = new List <string>();

                await Task.WhenAll(_hubConnectionManager.GetConnectedUsers <ServersHub>().Select(async connection =>
                {
                    var authResult = await authService.AuthorizeAsync(connection.Value, server.Entity, "ServerPolicy");
                    if (authResult.Succeeded)
                    {
                        if (!connections.Contains(connection.Key))
                        {
                            connections.Add(connection.Key);
                        }
                    }
                }));

                await NotifyServerInserted(server.Entity, connections.ToArray());
            }
        }