From b52645f77a0e58367c4988176c72a633438c1b1f Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sat, 21 Oct 2017 20:05:25 +0200 Subject: [PATCH] Add new interface for application message receivers --- .../Client/IApplicationMessageReceiver.cs | 9 ++++++++ MQTTnet.Core/Client/IMqttClient.cs | 3 +-- .../ManagedClient/ManagedMqttClient.cs | 22 +++---------------- 3 files changed, 13 insertions(+), 21 deletions(-) create mode 100644 MQTTnet.Core/Client/IApplicationMessageReceiver.cs diff --git a/MQTTnet.Core/Client/IApplicationMessageReceiver.cs b/MQTTnet.Core/Client/IApplicationMessageReceiver.cs new file mode 100644 index 0000000..2d53cb8 --- /dev/null +++ b/MQTTnet.Core/Client/IApplicationMessageReceiver.cs @@ -0,0 +1,9 @@ +using System; + +namespace MQTTnet.Core.Client +{ + public interface IApplicationMessageReceiver + { + event EventHandler ApplicationMessageReceived; + } +} diff --git a/MQTTnet.Core/Client/IMqttClient.cs b/MQTTnet.Core/Client/IMqttClient.cs index 04b5dcd..9caefbd 100644 --- a/MQTTnet.Core/Client/IMqttClient.cs +++ b/MQTTnet.Core/Client/IMqttClient.cs @@ -5,11 +5,10 @@ using MQTTnet.Core.Packets; namespace MQTTnet.Core.Client { - public interface IMqttClient + public interface IMqttClient : IApplicationMessageReceiver { bool IsConnected { get; } - event EventHandler ApplicationMessageReceived; event EventHandler Connected; event EventHandler Disconnected; diff --git a/MQTTnet.Core/ManagedClient/ManagedMqttClient.cs b/MQTTnet.Core/ManagedClient/ManagedMqttClient.cs index 1a23912..0612078 100644 --- a/MQTTnet.Core/ManagedClient/ManagedMqttClient.cs +++ b/MQTTnet.Core/ManagedClient/ManagedMqttClient.cs @@ -12,7 +12,7 @@ using MQTTnet.Core.Protocol; namespace MQTTnet.Core.ManagedClient { - public class ManagedMqttClient + public class ManagedMqttClient : IApplicationMessageReceiver { private readonly ManagedMqttClientStorageManager _storageManager = new ManagedMqttClientStorageManager(); private readonly BlockingCollection _messageQueue = new BlockingCollection(); @@ -38,12 +38,12 @@ namespace MQTTnet.Core.ManagedClient _mqttClient.ApplicationMessageReceived += OnApplicationMessageReceived; } + public bool IsConnected => _mqttClient.IsConnected; + public event EventHandler Connected; public event EventHandler Disconnected; public event EventHandler ApplicationMessageReceived; - public bool IsConnected => _mqttClient.IsConnected; - public async Task StartAsync(IManagedMqttClientOptions options) { if (options == null) throw new ArgumentNullException(nameof(options)); @@ -242,22 +242,6 @@ namespace MQTTnet.Core.ManagedClient } } - private async Task SaveAsync(List messages) - { - if (messages == null) - { - return; - } - - var storage = _options.Storage; - if (storage != null) - { - return; - } - - await _options.Storage.SaveQueuedMessagesAsync(messages); - } - private async Task PushSubscriptionsAsync() { _trace.Information(nameof(ManagedMqttClient), "Synchronizing subscriptions");