You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

46 lines
1.4 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.Server;
  8. namespace MQTTnet
  9. {
  10. public class MqttFactory : IMqttClientFactory, IMqttServerFactory
  11. {
  12. public IMqttClient CreateMqttClient()
  13. {
  14. return CreateMqttClient(new MqttNetLogger());
  15. }
  16. public IMqttClient CreateMqttClient(IMqttNetLogger logger)
  17. {
  18. if (logger == null) throw new ArgumentNullException(nameof(logger));
  19. return new MqttClient(new MqttClientAdapterFactory(), logger);
  20. }
  21. public IMqttServer CreateMqttServer()
  22. {
  23. var logger = new MqttNetLogger();
  24. return CreateMqttServer(logger);
  25. }
  26. public IMqttServer CreateMqttServer(IMqttNetLogger logger)
  27. {
  28. if (logger == null) throw new ArgumentNullException(nameof(logger));
  29. return CreateMqttServer(new List<IMqttServerAdapter> { new MqttTcpServerAdapter(logger.CreateChildLogger()) }, logger);
  30. }
  31. public IMqttServer CreateMqttServer(IEnumerable<IMqttServerAdapter> adapters, IMqttNetLogger logger)
  32. {
  33. if (adapters == null) throw new ArgumentNullException(nameof(adapters));
  34. if (logger == null) throw new ArgumentNullException(nameof(logger));
  35. return new MqttServer(adapters, logger.CreateChildLogger());
  36. }
  37. }
  38. }