Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

37 righe
1.2 KiB

  1. using System;
  2. using MQTTnet.Adapter;
  3. using MQTTnet.Client;
  4. using MQTTnet.Diagnostics;
  5. using MQTTnet.Serializer;
  6. namespace MQTTnet.Implementations
  7. {
  8. public class MqttClientAdapterFactory : IMqttClientAdapterFactory
  9. {
  10. public IMqttChannelAdapter CreateClientAdapter(IMqttClientOptions options, IMqttNetChildLogger logger)
  11. {
  12. if (options == null) throw new ArgumentNullException(nameof(options));
  13. var serializer = new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion };
  14. switch (options.ChannelOptions)
  15. {
  16. case MqttClientTcpOptions tcpOptions:
  17. {
  18. return new MqttChannelAdapter(new MqttTcpChannel(tcpOptions), serializer, logger);
  19. }
  20. case MqttClientWebSocketOptions webSocketOptions:
  21. {
  22. return new MqttChannelAdapter(new MqttWebSocketChannel(webSocketOptions), serializer, logger);
  23. }
  24. default:
  25. {
  26. throw new NotSupportedException();
  27. }
  28. }
  29. }
  30. }
  31. }