Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

MqttFactory.cs 1.8 KiB

il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
il y a 7 ans
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());
  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. }