Ejemplo n.º 1
0
        public Task OnDisconnectedAsync(IConnectionContext connection)
        {
            _connections.Remove(connection);

            var tasks = new List <Task>();

            var connectionChannel = _channels.Connection(connection.ConnectionId);

            RedisLog.Unsubscribe(_logger, connectionChannel);
            tasks.Add(_bus.UnsubscribeAsync(connectionChannel));

            var feature    = connection.Features.Get <IRedisFeature>();
            var groupNames = feature.Groups;

            if (groupNames != null)
            {
                // Copy the groups to an array here because they get removed from this collection
                // in RemoveFromGroupAsync
                foreach (var group in groupNames.ToArray())
                {
                    // Use RemoveGroupAsyncCore because the connection is local and we don't want to
                    // accidentally go to other servers with our remove request.
                    tasks.Add(RemoveGroupAsyncCore(connection, group));
                }
            }

            if (!string.IsNullOrEmpty(connection.UserIdentifier))
            {
                tasks.Add(RemoveUserAsync(connection));
            }

            return(Task.WhenAll(tasks));
        }
Ejemplo n.º 2
0
        private Task RemoveUserAsync(IConnectionContext connection)
        {
            var userChannel = _channels.User(connection.UserIdentifier);

            return(_users.RemoveSubscriptionAsync(userChannel, connection, channelName =>
            {
                RedisLog.Unsubscribe(_logger, channelName);
                return _bus.UnsubscribeAsync(channelName);
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This takes <see cref="HubConnectionContext"/> because we want to remove the connection from the
        /// _connections list in OnDisconnectedAsync and still be able to remove groups with this method.
        /// </summary>
        private async Task RemoveGroupAsyncCore(IConnectionContext connection, string groupName)
        {
            var groupChannel = _channels.Group(groupName);

            await _groups.RemoveSubscriptionAsync(groupChannel, connection, channelName =>
            {
                RedisLog.Unsubscribe(_logger, channelName);
                return(_bus.UnsubscribeAsync(channelName));
            });

            var feature    = connection.Features.Get <IRedisFeature>();
            var groupNames = feature.Groups;

            if (groupNames != null)
            {
                lock (groupNames)
                {
                    groupNames.Remove(groupName);
                }
            }
        }