Exemplo n.º 1
0
        public async Task SendCoreAsync(string connectionId, string method, object[] args, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Sending data to connectionId: {connectionId} data: {method}");
            try
            {
                PostToConnectionResponse sendResult;
                using (var ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes((string)method)))
                {
                    sendResult = await _apiGatewayManagementApi.PostToConnectionAsync(new PostToConnectionRequest()
                    {
                        ConnectionId = connectionId,
                        Data         = ms
                    });
                }
                if (sendResult.HttpStatusCode == HttpStatusCode.OK)
                {
                    return;
                }
                else if (sendResult.HttpStatusCode == HttpStatusCode.Gone)
                {
                    Task.Run(() => _connectionStore.RemoveConnectionAsync(connectionId));
                }
                else
                {
                    _logger.LogError($"Error1 sending message to connectionId: {connectionId}, httpStatus: {sendResult.HttpStatusCode}");
                }
            }
            catch (GoneException e)
            {
                _logger.LogWarning($"ConnectionId: {connectionId} received a GoneException, {e.Message.ToString()} ,{e.InnerException?.Message?.ToString()}");
                await _connectionStore.RemoveConnectionAsync(connectionId);
            }
            catch (Amazon.ApiGatewayManagementApi.Model.ForbiddenException e)
            {
                _logger.LogError($"Error2 sending message to connectionId: {connectionId}, {e.Message.ToString()} ,{e.InnerException?.Message?.ToString()}");
            }
            catch (Amazon.ApiGatewayManagementApi.Model.PayloadTooLargeException e)
            {
                _logger.LogError($"Error3 sending message to connectionId: {connectionId}, {e.Message.ToString()} ,{e.InnerException?.Message?.ToString()}");
            }
            catch (AggregateException e)
            {
                _logger.LogError($"Error4 sending message to connectionId: {connectionId}, {e.Message.ToString()} ,{e.InnerException?.Message?.ToString()}");
            }
            catch (ObjectDisposedException e)
            {
                _logger.LogWarning($"Removing connectionId: {connectionId} from store.");
                await _connectionStore.RemoveConnectionAsync(connectionId);
            }
            catch (Exception e)
            {
                _logger.LogError($"Error5 sending message to connectionId: {connectionId}, {e.Message.ToString()} ,{e.InnerException?.Message?.ToString()}");
                _logger.LogWarning($"Removing connectionId: {connectionId} from store.");
                await _connectionStore.RemoveConnectionAsync(connectionId);
            }



            return;
        }
Exemplo n.º 2
0
        public async void CanRemoveConnectionAsync()
        {
            await _connectionStore.StoreConnectionAsync(connectionIdA, userIdA);

            await _connectionStore.RemoveConnectionAsync(connectionIdA);

            Assert.True(!(await _connectionStore.GetAllClients()).Select(x => x.ConnectionId).Contains(connectionIdA));
        }
Exemplo n.º 3
0
        public override async Task OnDisconnectedAsync(System.Exception exception)
        {
            _logger.LogWarning($"Disconnection connectionId: {Context.ConnectionId}");

            await _connectionStore.RemoveConnectionAsync(Context.ConnectionId);

            return;
        }