No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

59 líneas
1.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using MQTTnet.Adapter;
  4. using MQTTnet.Client;
  5. using MQTTnet.Diagnostics;
  6. using MQTTnet.Implementations;
  7. using MQTTnet.ManagedClient;
  8. using MQTTnet.Server;
  9. namespace MQTTnet
  10. {
  11. public class MqttFactory : IMqttClientFactory, IMqttServerFactory
  12. {
  13. public IMqttClient CreateMqttClient()
  14. {
  15. return CreateMqttClient(new MqttNetLogger());
  16. }
  17. public IMqttClient CreateMqttClient(IMqttNetLogger logger)
  18. {
  19. if (logger == null) throw new ArgumentNullException(nameof(logger));
  20. return new MqttClient(new MqttClientAdapterFactory(), logger);
  21. }
  22. public IManagedMqttClient CreateManagedMqttClient()
  23. {
  24. return new ManagedMqttClient(CreateMqttClient(), new MqttNetLogger());
  25. }
  26. public IManagedMqttClient CreateManagedMqttClient(IMqttNetLogger logger)
  27. {
  28. if (logger == null) throw new ArgumentNullException(nameof(logger));
  29. return new ManagedMqttClient(CreateMqttClient(), logger);
  30. }
  31. public IMqttServer CreateMqttServer()
  32. {
  33. var logger = new MqttNetLogger();
  34. return CreateMqttServer(logger);
  35. }
  36. public IMqttServer CreateMqttServer(IMqttNetLogger logger)
  37. {
  38. if (logger == null) throw new ArgumentNullException(nameof(logger));
  39. return CreateMqttServer(new List<IMqttServerAdapter> { new MqttTcpServerAdapter(logger) }, logger);
  40. }
  41. public IMqttServer CreateMqttServer(IEnumerable<IMqttServerAdapter> adapters, IMqttNetLogger logger)
  42. {
  43. if (adapters == null) throw new ArgumentNullException(nameof(adapters));
  44. if (logger == null) throw new ArgumentNullException(nameof(logger));
  45. return new MqttServer(adapters, logger);
  46. }
  47. }
  48. }