예제 #1
0
    private async Task OnUserMembershipChangedAsync(UserMembershipChanged userMembershipChanged, CancellationToken cancellationToken = default)
    {
        if (String.IsNullOrEmpty(userMembershipChanged?.OrganizationId))
        {
            _logger.LogTrace("Ignoring User Membership Changed message: No organization id.");
            return;
        }

        // manage user organization group membership
        var userConnectionIds = await _connectionMapping.GetUserIdConnectionsAsync(userMembershipChanged.UserId);

        _logger.LogTrace("Attempting to update user {User} active groups for {UserConnectionCount} connections", userMembershipChanged.UserId, userConnectionIds.Count);
        foreach (string connectionId in userConnectionIds)
        {
            if (userMembershipChanged.ChangeType == ChangeType.Added)
            {
                await _connectionMapping.GroupAddAsync(userMembershipChanged.OrganizationId, connectionId);
            }
            else if (userMembershipChanged.ChangeType == ChangeType.Removed)
            {
                await _connectionMapping.GroupRemoveAsync(userMembershipChanged.OrganizationId, connectionId);
            }
        }

        await GroupSendAsync(userMembershipChanged.OrganizationId, userMembershipChanged);
    }
        protected override async Task OnConnected(IRequest request, string connectionId)
        {
            if (request.User.GetOrganizationId() != null)
            {
                await _connectionMapping.GroupAddAsync(request.User.GetOrganizationId(), connectionId).AnyContext();
            }

            await _connectionMapping.UserIdAddAsync(request.User.GetUserId(), connectionId).AnyContext();
        }
        protected override async Task OnConnected(IRequest request, string connectionId)
        {
            try {
                foreach (var organizationId in request.User.GetOrganizationIds())
                {
                    await _connectionMapping.GroupAddAsync(organizationId, connectionId);
                }

                await _connectionMapping.UserIdAddAsync(request.User.GetUserId(), connectionId);
            } catch (Exception ex) {
                _logger.Error(ex, "OnReconnected Error: {0}", ex.Message);
                throw;
            }
        }
        private async Task OnConnected(HttpContext context, WebSocket socket, string connectionId)
        {
            _logger.LogTrace("WebSocket connected {ConnectionId} ({State})", connectionId, socket?.State);

            try {
                foreach (string organizationId in context.User.GetOrganizationIds())
                {
                    await _connectionMapping.GroupAddAsync(organizationId, connectionId);
                }

                await _connectionMapping.UserIdAddAsync(context.User.GetUserId(), connectionId);
            } catch (Exception ex) {
                _logger.LogError(ex, "OnConnected Error: {Message}", ex.Message);
                throw;
            }
        }
예제 #5
0
        private async Task OnUserMembershipChangedAsync(UserMembershipChanged userMembershipChanged, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(userMembershipChanged?.OrganizationId))
            {
                return;
            }

            // manage user organization group membership
            foreach (var connectionId in await _connectionMapping.GetConnectionsAsync(userMembershipChanged.UserId))
            {
                if (userMembershipChanged.ChangeType == ChangeType.Added)
                {
                    await _connectionMapping.GroupAddAsync(userMembershipChanged.OrganizationId, connectionId);
                }
                else if (userMembershipChanged.ChangeType == ChangeType.Removed)
                {
                    await _connectionMapping.GroupRemoveAsync(userMembershipChanged.OrganizationId, connectionId);
                }
            }

            await GroupSendAsync(userMembershipChanged.OrganizationId, userMembershipChanged);
        }