Exemplo n.º 1
0
        public override async Task OnConnectedAsync(HubConnectionContext connection)
        {
            if (!isInitialized)
            {
                await ConnectToClusterAsync();
            }

            var connectionId = connection.ConnectionId;
            await _clusterClient.GetHubLifetimeManagerGrain(_id, _hubTypeId).OnConnectedAsync(connectionId);

            var userId = _userIdProvider.GetUserId(connection);

            if (!string.IsNullOrEmpty(userId))
            {
                await _userPartitioner.GetPartitionGrain(_clusterClient, userId, _hubTypeId).AddToUserAsync(connectionId, userId);
            }
            connectionsById.TryAdd(connectionId, connection);
        }
        public async Task OnDisconnectedAsync()
        {
            var groupTasks = State.GroupNames.Select(name => _groupPartitioner.GetPartitionGrain(GrainFactory, name, _hubTypeId).RemoveFromGroupAsync(_connectionId, name));
            await Task.WhenAll(groupTasks);

            if (!string.IsNullOrEmpty(State.UserId))
            {
                await _userPartitioner.GetPartitionGrain(GrainFactory, State.UserId, _hubTypeId).RemoveFromUserAsync(_connectionId, State.UserId);
            }

            State.Aborted = true;
            await WriteStateAsync();

            DeactivateOnIdle();
        }
 public override Task AddToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default)
 {
     return(_groupPartitioner.GetPartitionGrain(_clusterClient, groupName, _hubTypeId).AddToGroupAsync(connectionId, groupName));
 }