Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

33 строки
1.3 KiB

  1. using System;
  2. using System.Threading.Tasks;
  3. using MQTTnet.Client.Receiving;
  4. namespace MQTTnet.Extensions.Rpc
  5. {
  6. public sealed class RpcAwareApplicationMessageReceivedHandler : IMqttApplicationMessageReceivedHandler
  7. {
  8. 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. // First try to check if there is a pending RPC call!
  20. await _handleReceivedApplicationMessageAsync(eventArgs).ConfigureAwait(false);
  21. if (OriginalHandler != null)
  22. {
  23. await OriginalHandler.HandleApplicationMessageReceivedAsync(eventArgs).ConfigureAwait(false);
  24. }
  25. }
  26. }
  27. }