/// <summary> /// This method is used to send a single message to the message board. /// </summary> /// <param name="message">The message to send.</param> /// <remarks> /// The message will be send to the <see cref="IMessageBoard"/> which was passed in the constructor. /// </remarks> protected void OnMessage(Message message) { if (Log.IsEnabled(LogEventLevel.Verbose)) { if (message is ExceptionMessage exceptionMessage && exceptionMessage.ExceptionInfo != null) { Log.Verbose(exceptionMessage.ExceptionInfo.SourceException, "{@log}", new AgentLog(agentName, "Publishing", Id, message.ToMessageLog())); } else { Log.Verbose("{@log}", new AgentLog(agentName, "Publishing", Id, message?.ToMessageLog())); } }
/// <summary> /// This method is called by the message boards to execute a certain message. /// </summary> /// <param name="messageData">The message data that is executed.</param> /// <exception cref="ArgumentNullException">When the message data is null.</exception> /// <remarks> /// Only messages which are defined with the <see cref="ConsumesAttribute"/> are passed to this method. /// Only the <see cref="IMessageBoard"/> should call this. It can also be used in unit tests. /// This method executes the <see cref="ExecuteCore"/> method with the provided message. Additionally it logs all received messages and throw an exception method if the <see cref="ExecuteCore"/> method throws an exception. /// </remarks> public void Execute(Message messageData) { if (messageData == null) { throw new ArgumentNullException(nameof(messageData)); } if (Log.IsEnabled(LogEventLevel.Verbose)) { Log.Verbose("{@log}", new AgentLog(agentName, "Executing", Id, messageData.ToMessageLog())); } try { ExecuteCore(messageData); } catch (Exception e) { ExceptionDispatchInfo exceptionInfo = ExceptionDispatchInfo.Capture(e); OnMessage(new ExceptionMessage(exceptionInfo, messageData, this)); } }
/// <summary> /// This method is called by the message boards to intercept a certain message. /// </summary> /// <param name="messageData">The message that is intercepted.</param> /// <exception cref="ArgumentNullException">When the message data is null.</exception> /// <returns>The <see cref="InterceptionAction"/>, which defines whether the original message is published or not.</returns> /// <remarks> /// <para>Only messages which are defined with the <see cref="InterceptsAttribute"/> are passed to this method.</para> /// <para>Only the <see cref="IMessageBoard"/> should call this. It can also be used in unit tests.</para> /// <para>This method executes the <see cref="InterceptCore"/> method with the provided message. Additionally it logs all received messages and throw an exception method if the <see cref="InterceptCore"/> method throws an exception.</para> /// </remarks> public InterceptionAction Intercept(Message messageData) { if (messageData == null) { throw new ArgumentNullException(nameof(messageData)); } if (Log.IsEnabled(LogEventLevel.Verbose)) { Log.Verbose("{@log}", new AgentLog(agentName, "Intercepting", Id, messageData.ToMessageLog())); } try { return(InterceptCore(messageData)); } catch (Exception e) { ExceptionDispatchInfo exceptionInfo = ExceptionDispatchInfo.Capture(e); OnMessage(new ExceptionMessage(exceptionInfo, messageData, this)); } return(InterceptionAction.DoNotPublish); }