示例#1
0
 public Function(ServiceProvider service)
 {
     _service           = service;
     _connectionService = _service.GetService <ConnectionSocketService>();
 }
示例#2
0
        public async Task PostToConnection(ConnectionSocketModel connection, MemoryStream stream, ConnectionSocketService connectionService, AmazonApiGatewayManagementApiClient apiClient, ILambdaContext context)
        {
            var connectionId = connection.connection_id;

            context.Logger.LogLine($"Get Connection ID from DB: {connectionId}");

            var postConnectionRequest = new PostToConnectionRequest
            {
                ConnectionId = connectionId,
                Data         = stream
            };

            try
            {
                context.Logger.LogLine($"Post to connection: {connectionId}");
                stream.Position = 0;
                await apiClient.PostToConnectionAsync(postConnectionRequest);
            }
            catch (AmazonServiceException e)
            {
                if (e.StatusCode == HttpStatusCode.Gone)
                {
                    connectionService.GetConnection(connectionId);
                    context.Logger.LogLine($"Deleting gone connection: {connectionId}");
                }
                else
                {
                    context.Logger.LogLine($"Error posting message to {connectionId}: {e.Message}");
                    context.Logger.LogLine(e.StackTrace);
                }
            }
        }