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.

MqttFactoryExtensions.cs 1.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233
  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. }