Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

33 linhas
1.0 KiB

  1. using System;
  2. using MQTTnet.Core.Adapter;
  3. using MQTTnet.Core.Channel;
  4. using MQTTnet.Core.Client;
  5. using MQTTnet.Core.Serializer;
  6. using MQTTnet.Implementations;
  7. namespace MQTTnet
  8. {
  9. public class MqttClientFactory : IMqttClientFactory
  10. {
  11. public IMqttClient CreateMqttClient(MqttClientOptions options)
  12. {
  13. if (options == null) throw new ArgumentNullException(nameof(options));
  14. return new MqttClient(options, new MqttChannelCommunicationAdapter(GetMqttCommunicationChannel(options), new MqttPacketSerializer()));
  15. }
  16. private static IMqttCommunicationChannel GetMqttCommunicationChannel(MqttClientOptions options)
  17. {
  18. switch (options.ConnectionType)
  19. {
  20. case MqttConnectionType.Tcp:
  21. return new MqttTcpChannel();
  22. case MqttConnectionType.Ws:
  23. return new MqttWebSocketChannel();
  24. default:
  25. throw new NotSupportedException();
  26. }
  27. }
  28. }
  29. }