Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

32 lignes
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. }