private async Task OnHandlerException_Default(TMessage message, Exception exception) { ASSERT(message != null, $"Missing parameter '{nameof(message)}'"); ASSERT(exception != null, $"Missing parameter '{nameof(exception)}'"); var asyncException = exception as System.Reflection.TargetInvocationException; if (asyncException != null) { // Unwrap those crappy exception ... await OnHandlerException_Default(message, asyncException.InnerException); } else if (string.IsNullOrWhiteSpace(message.TryGetString(MessageKeys.KeySenderID))) { FAIL($"The message handler for '{message.TryGetString(MessageKeys.KeyMessageHandler)}' had no sender defined and threw an exception ({exception.GetType().FullName}): {exception.Message}"); // Discard } else { // Send response var response = Broker.FillAsResponse(source: message, destination: Broker.NewMessage()); Broker.FillException(response, exception); await Broker.ReceiveMessages(new TMessage[] { response }); } }
public async Task ReceiveMessage(TMessage message) { var callback = Callbacks.TryGet(message.TryGetString(MessageKeys.KeyMessageHandler)); if (callback == null) { await OnUnknownMessageReceived.Invoke(message); return; } await callback(message); }
private async Task OnUnknownMessageReceived_Default(TMessage message) { ASSERT(message != null, $"Missing parameter '{nameof(message)}'"); if (string.IsNullOrWhiteSpace(message.TryGetString(MessageKeys.KeySenderID))) { FAIL($"{nameof(MessageHandler)}: Received message with unknown type '{message.TryGetString(MessageKeys.KeyMessageHandler)}'"); // Discard } else { // Send response var response = Broker.FillAsResponse(source: message, destination: Broker.NewMessage()); try{ throw new ArgumentException($"{nameof(MessageHandler)}: Received message with unknown type '{message.TryGetString(MessageKeys.KeyMessageHandler)}'"); } catch (System.Exception ex) { Broker.FillException(response, ex); }; await Broker.ReceiveMessages(new TMessage[] { response }); } }