Esempio n. 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);
    }
Esempio n. 2
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.GetUserIdConnectionsAsync(userMembershipChanged.UserId))
            {
                if (userMembershipChanged.ChangeType == ChangeType.Added)
                {
                    await _connectionMapping.GroupAddAsync(userMembershipChanged.OrganizationId, connectionId).AnyContext();
                }
                else if (userMembershipChanged.ChangeType == ChangeType.Removed)
                {
                    await _connectionMapping.GroupRemoveAsync(userMembershipChanged.OrganizationId, connectionId);
                }
            }

            await GroupSendAsync(userMembershipChanged.OrganizationId, userMembershipChanged);
        }
        private async Task OnEntityChangedAsync(ExtendedEntityChanged entityChanged, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (entityChanged == null)
            {
                return;
            }

            if (entityChanged.Type == UserTypeName)
            {
                foreach (var connectionId in await _connectionMapping.GetUserIdConnectionsAsync(entityChanged.Id))
                {
                    await Context.Connection.TypedSendAsync(connectionId, entityChanged);
                }

                return;
            }

            if (!String.IsNullOrEmpty(entityChanged.OrganizationId))
            {
                await GroupSendAsync(entityChanged.OrganizationId, entityChanged);
            }
        }