Parcourir la source

Add new interface for application message receivers

release/3.x.x
Christian Kratky il y a 7 ans
Parent
révision
b52645f77a
3 fichiers modifiés avec 13 ajouts et 21 suppressions
  1. +9
    -0
      MQTTnet.Core/Client/IApplicationMessageReceiver.cs
  2. +1
    -2
      MQTTnet.Core/Client/IMqttClient.cs
  3. +3
    -19
      MQTTnet.Core/ManagedClient/ManagedMqttClient.cs

+ 9
- 0
MQTTnet.Core/Client/IApplicationMessageReceiver.cs Voir le fichier

@@ -0,0 +1,9 @@
using System;

namespace MQTTnet.Core.Client
{
public interface IApplicationMessageReceiver
{
event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;
}
}

+ 1
- 2
MQTTnet.Core/Client/IMqttClient.cs Voir le fichier

@@ -5,11 +5,10 @@ using MQTTnet.Core.Packets;

namespace MQTTnet.Core.Client
{
public interface IMqttClient
public interface IMqttClient : IApplicationMessageReceiver
{
bool IsConnected { get; }

event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;
event EventHandler<MqttClientConnectedEventArgs> Connected;
event EventHandler<MqttClientDisconnectedEventArgs> Disconnected;



+ 3
- 19
MQTTnet.Core/ManagedClient/ManagedMqttClient.cs Voir le fichier

@@ -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<MqttApplicationMessage> _messageQueue = new BlockingCollection<MqttApplicationMessage>();
@@ -38,12 +38,12 @@ namespace MQTTnet.Core.ManagedClient
_mqttClient.ApplicationMessageReceived += OnApplicationMessageReceived;
}

public bool IsConnected => _mqttClient.IsConnected;

public event EventHandler<MqttClientConnectedEventArgs> Connected;
public event EventHandler<MqttClientDisconnectedEventArgs> Disconnected;
public event EventHandler<MqttApplicationMessageReceivedEventArgs> 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<MqttApplicationMessage> 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");


Chargement…
Annuler
Enregistrer