Exemple #1
0
 private Task HandleInitAsync(OperationMessage message)
 {
     _logger.LogInformation("Handle init");
     return(TransportWriter.SendAsync(new OperationMessage
     {
         Type = MessageType.GQL_CONNECTION_ACK
     }));
 }
 public MessageHandlingContext(IServerOperations server, OperationMessage message)
 {
     _server       = server;
     Reader        = server.TransportReader;
     Writer        = server.TransportWriter;
     Subscriptions = server.Subscriptions;
     Message       = message;
 }
Exemple #3
0
        private Task HandleStartAsync(OperationMessage message)
        {
            _logger.LogInformation("Handle start: {id}", message.Id);
            var payload = message.Payload.ToObject <OperationMessagePayload>();

            if (payload == null)
            {
                throw new InvalidOperationException($"Could not get OperationMessagePayload from message.Payload");
            }

            return(Subscriptions.SubscribeOrExecuteAsync(
                       message.Id,
                       payload,
                       TransportWriter));
        }
Exemple #4
0
        private async Task HandleMessageAsync(OperationMessage message)
        {
            _logger.LogDebug("Handling message: {id} of type: {type}", message.Id, message.Type);
            using (var context = await BuildMessageHandlingContext(message))
            {
                await OnBeforeHandleAsync(context);

                if (context.Terminated)
                {
                    return;
                }

                await OnHandleAsync(context);
                await OnAfterHandleAsync(context);
            }
        }
Exemple #5
0
 private Task HandleUnknownAsync(OperationMessage message)
 {
     _logger.LogError($"Unexpected message type: {message.Type}");
     return(TransportWriter.SendAsync(new OperationMessage
     {
         Type = MessageType.GQL_CONNECTION_ERROR,
         Id = message.Id,
         Payload = JObject.FromObject(new
         {
             message.Id,
             Errors = new ExecutionErrors
             {
                 new ExecutionError($"Unexpected message type {message.Type}")
             }
         })
     }));
 }
Exemple #6
0
        private async Task HandleMessageAsync(OperationMessage message)
        {
            _logger.LogDebug("Handling message: {id} of type: {type}", message.Id, message.Type);
            await OnBeforeHandleAsync(message);

            //todo(pekka): should this be changed into message listener?
            switch (message.Type)
            {
            case MessageType.GQL_CONNECTION_INIT:
                await HandleInitAsync(message);

                break;

            case MessageType.GQL_START:
                await HandleStartAsync(message);

                break;

            case MessageType.GQL_STOP:
                await HandleStopAsync(message);

                break;

            case MessageType.GQL_CONNECTION_TERMINATE:
                await HandleTerminateAsync(message);

                break;

            default:
                await HandleUnknownAsync(message);

                break;
            }

            await OnAfterHandleAsync(message);
        }
Exemple #7
0
 private Task <MessageHandlingContext> BuildMessageHandlingContext(OperationMessage message)
 {
     return(Task.FromResult(new MessageHandlingContext(this, message)));
 }
Exemple #8
0
 public Task OnAfterHandleAsync(IReaderPipeline reader, IWriterPipeline writer, OperationMessage message)
 {
     return(Task.CompletedTask);
 }
Exemple #9
0
 public Task OnBeforeHandleAsync(IReaderPipeline reader, IWriterPipeline writer, OperationMessage message)
 {
     _logger.LogDebug("Received message: {message}", message);
     return(Task.CompletedTask);
 }
Exemple #10
0
 private Task HandleStopAsync(OperationMessage message)
 {
     _logger.LogInformation("Handle stop: {id}", message.Id);
     return(Subscriptions.UnsubscribeAsync(message.Id));
 }
Exemple #11
0
 private async Task HandleTerminateAsync(OperationMessage message)
 {
     _logger.LogInformation("Handle terminate");
     await Terminate();
 }