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.
 
 
 
 

33 lignes
1.2 KiB

  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using MQTTnet.Client;
  6. using MQTTnet.Diagnostics;
  7. namespace MQTTnet.Extensions.ManagedClient
  8. {
  9. public static class MqttFactoryExtensions
  10. {
  11. public static ManagedMqttClient CreateManagedMqttClient(this MqttFactory factory, MqttClient mqttClient = null)
  12. {
  13. if (factory == null) throw new ArgumentNullException(nameof(factory));
  14. if (mqttClient == null)
  15. {
  16. return new ManagedMqttClient(factory.CreateMqttClient(), factory.DefaultLogger);
  17. }
  18. return new ManagedMqttClient(mqttClient, factory.DefaultLogger);
  19. }
  20. public static ManagedMqttClient CreateManagedMqttClient(this MqttFactory factory, IMqttNetLogger logger)
  21. {
  22. if (factory == null) throw new ArgumentNullException(nameof(factory));
  23. if (logger == null) throw new ArgumentNullException(nameof(logger));
  24. return new ManagedMqttClient(factory.CreateMqttClient(logger), logger);
  25. }
  26. }
  27. }