Beispiel #1
0
        private void OnUserMembershipChanged(UserMembershipChanged userMembershipChanged)
        {
            if (userMembershipChanged == null)
            {
                return;
            }

            if (String.IsNullOrEmpty(userMembershipChanged.OrganizationId))
            {
                return;
            }

            // manage user organization group membership
            foreach (var connectionId in _userIdConnections.GetConnections(userMembershipChanged.UserId))
            {
                if (userMembershipChanged.ChangeType == ChangeType.Added)
                {
                    Groups.Add(connectionId, userMembershipChanged.OrganizationId).Wait();
                }
                else if (userMembershipChanged.ChangeType == ChangeType.Removed)
                {
                    Groups.Remove(connectionId, userMembershipChanged.OrganizationId).Wait();
                }
            }

            Clients.Group(userMembershipChanged.OrganizationId).userMembershipChanged(userMembershipChanged);
        }
        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 _userIdConnections.GetConnections(userMembershipChanged.UserId))
            {
                if (userMembershipChanged.ChangeType == ChangeType.Added)
                {
                    await Context.Groups.Add(connectionId, userMembershipChanged.OrganizationId);
                }
                else if (userMembershipChanged.ChangeType == ChangeType.Removed)
                {
                    await Context.Groups.Remove(connectionId, userMembershipChanged.OrganizationId);
                }
            }

            await Context.Groups.TypedSend(userMembershipChanged.OrganizationId, userMembershipChanged);
        }
        protected override async Task OnReconnected(IRequest request, string connectionId)
        {
            try {
                foreach (var organizationId in request.User.GetOrganizationIds())
                {
                    await Groups.Add(connectionId, organizationId);
                }

                if (!_userIdConnections.GetConnections(request.User.GetUserId()).Contains(connectionId))
                {
                    _userIdConnections.Add(request.User.GetUserId(), connectionId);
                }
            } catch (Exception ex) {
                Logger.Error().Exception(ex).Message($"OnReconnected Error: {ex.Message}").Tag("SignalR").Write();
                throw;
            }
        }
        protected override async Task OnReconnected(IRequest request, string connectionId)
        {
            try {
                foreach (var organizationId in request.User.GetOrganizationIds())
                {
                    await Groups.Add(connectionId, organizationId);
                }

                if (!_userIdConnections.GetConnections(request.User.GetUserId()).Contains(connectionId))
                {
                    _userIdConnections.Add(request.User.GetUserId(), connectionId);
                }
            } catch (Exception ex) {
                _logger.Error(ex, "OnReconnected Error: {0}", ex.Message);
                throw;
            }
        }