using System; using System.Collections.Generic; using MQTTnet.Adapter; using MQTTnet.Client; using MQTTnet.Diagnostics; using MQTTnet.Implementations; using MQTTnet.ManagedClient; using MQTTnet.Server; namespace MQTTnet { public class MqttFactory : IMqttClientFactory, IMqttServerFactory { public IMqttClient CreateMqttClient() { return CreateMqttClient(new MqttNetLogger()); } public IMqttClient CreateMqttClient(IMqttNetLogger logger) { if (logger == null) throw new ArgumentNullException(nameof(logger)); return new MqttClient(new MqttClientAdapterFactory(), logger); } public IManagedMqttClient CreateManagedMqttClient() { return new ManagedMqttClient(CreateMqttClient(), new MqttNetLogger()); } public IManagedMqttClient CreateManagedMqttClient(IMqttNetLogger logger) { if (logger == null) throw new ArgumentNullException(nameof(logger)); return new ManagedMqttClient(CreateMqttClient(), logger); } public IMqttServer CreateMqttServer() { var logger = new MqttNetLogger(); return CreateMqttServer(new List { new MqttServerAdapter(logger) }, logger); } public IMqttServer CreateMqttServer(IEnumerable adapters, IMqttNetLogger logger) { if (adapters == null) throw new ArgumentNullException(nameof(adapters)); if (logger == null) throw new ArgumentNullException(nameof(logger)); return new MqttServer(adapters, logger); } } }