private async Task Invoke(Message message, string messageContent, IConnectionContext context) { ReturnMessage returnMessage = null; try { var response = await this.InvokeHandler(message, messageContent, context); if (response != null && response != Response.VoidResponse) { returnMessage = new DataReturnMessage() { op = "op.return", id = message.id, targetOp = message.op, data = response.GetData() }; } else if (response == Response.VoidResponse) { returnMessage = new VoidReturnMesage() { op = "op.return", targetOp = message.op, id = message.id }; } } catch (ReturnException ex) { returnMessage = new ErrorReturnMessage() { op = "op.return", id = message.id, targetOp = message.op, error = ex.ErrorCode, message = ex.Message }; } catch (Exception ex) { returnMessage = new ErrorReturnMessage() { op = "op.return", id = message.id, targetOp = message.op, error = 500, message = "inner system error" }; } await context.WriteAsync(CreateSerializedIMessage(returnMessage), CancellationToken.None); }
private async Task SubscribeToConnection(IConnectionContext connection) { var connectionChannel = _channels.Connection(connection.ConnectionId); RedisLog.Subscribing(_logger, connectionChannel); var channel = await _bus.SubscribeAsync(connectionChannel); channel.OnMessage(channelMessage => { var invocation = _protocol.ReadInvocation((byte[])channelMessage.Message); return(connection.WriteAsync(invocation.Message, CancellationToken.None)); }); }
public static async Task WriteAsync(this IConnectionContext context, IPushMessage pushMessage, CancellationToken cancellationToken) { var message = pushMessage.GetMessage(); await context.WriteAsync(message, cancellationToken); }
public static async Task SendToCaller(this IConnectionContext context, Message message) { var pushMessage = context.CreatePushMessage(message); await context.WriteAsync(pushMessage, CancellationToken.None); }