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.

MqttFactory.cs 2.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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().CreateChildLogger(string.Empty));
  25. }
  26. public IManagedMqttClient CreateManagedMqttClient(IMqttNetLogger logger)
  27. {
  28. if (logger == null) throw new ArgumentNullException(nameof(logger));
  29. return new ManagedMqttClient(CreateMqttClient(), logger.CreateChildLogger(string.Empty));
  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.CreateChildLogger(string.Empty)) }, 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.CreateChildLogger(string.Empty));
  46. }
  47. }
  48. }