You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 line
1.3 KiB

  1. using System;
  2. using System.Threading.Tasks;
  3. using MQTTnet.Client.Receiving;
  4. namespace MQTTnet.Extensions.Rpc
  5. {
  6. public class RpcAwareApplicationMessageReceivedHandler : IMqttApplicationMessageReceivedHandler
  7. {
  8. private readonly Func<MqttApplicationMessageReceivedEventArgs, Task> _handleReceivedApplicationMessageAsync;
  9. public RpcAwareApplicationMessageReceivedHandler(
  10. IMqttApplicationMessageReceivedHandler originalHandler,
  11. Func<MqttApplicationMessageReceivedEventArgs, Task> handleReceivedApplicationMessageAsync)
  12. {
  13. OriginalHandler = originalHandler;
  14. _handleReceivedApplicationMessageAsync = handleReceivedApplicationMessageAsync ?? throw new ArgumentNullException(nameof(handleReceivedApplicationMessageAsync));
  15. }
  16. public IMqttApplicationMessageReceivedHandler OriginalHandler { get; }
  17. public async Task HandleApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs eventArgs)
  18. {
  19. if (OriginalHandler != null)
  20. {
  21. await OriginalHandler.HandleApplicationMessageReceivedAsync(eventArgs).ConfigureAwait(false);
  22. }
  23. await _handleReceivedApplicationMessageAsync(eventArgs).ConfigureAwait(false);
  24. }
  25. }
  26. }