Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

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