From f844a8be5ee1293a5e5d9ed133e3e55dfb72d2a1 Mon Sep 17 00:00:00 2001 From: JTrotta Date: Tue, 29 May 2018 11:32:16 +0200 Subject: [PATCH] ManagedMqttClietStorage now works --- .../MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs | 4 ++++ .../ManagedClient/ManagedMqttClientStorageManager.cs | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs index f1ce45d..9d0f72a 100644 --- a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs @@ -66,6 +66,10 @@ namespace MQTTnet.ManagedClient { _storageManager = new ManagedMqttClientStorageManager(_options.Storage); await _storageManager.LoadQueuedMessagesAsync().ConfigureAwait(false); + foreach (var loadedMessage in _storageManager.ApplicationMessages) + { + _messageQueue.Add(loadedMessage); + } } _connectionCancellationToken = new CancellationTokenSource(); diff --git a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs index 0e71776..156fba0 100644 --- a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs @@ -11,6 +11,8 @@ namespace MQTTnet.ManagedClient private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); private readonly IManagedMqttClientStorage _storage; + public List ApplicationMessages => _applicationMessages; + public ManagedMqttClientStorageManager(IManagedMqttClientStorage storage) { _storage = storage ?? throw new ArgumentNullException(nameof(storage)); @@ -19,10 +21,7 @@ namespace MQTTnet.ManagedClient public async Task LoadQueuedMessagesAsync() { var loadedMessages = await _storage.LoadQueuedMessagesAsync().ConfigureAwait(false); - foreach (var loadedMessage in loadedMessages) - { - _applicationMessages.Add(loadedMessage); - } + _applicationMessages.AddRange(loadedMessages); } public async Task AddAsync(MqttApplicationMessage applicationMessage)