mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 17:23:04 +08:00
Expose custom session items in session status.
This commit is contained in:
@@ -8,9 +8,9 @@ namespace MQTTnet.Server
|
||||
{
|
||||
public class MqttClientSession
|
||||
{
|
||||
private readonly IMqttNetLogger _logger;
|
||||
readonly IMqttNetLogger _logger;
|
||||
|
||||
private readonly DateTime _createdTimestamp = DateTime.UtcNow;
|
||||
readonly DateTime _createdTimestamp = DateTime.UtcNow;
|
||||
|
||||
public MqttClientSession(string clientId, IDictionary<object, object> items, MqttServerEventDispatcher eventDispatcher, IMqttServerOptions serverOptions, IMqttNetLogger logger)
|
||||
{
|
||||
@@ -73,6 +73,7 @@ namespace MQTTnet.Server
|
||||
status.ClientId = ClientId;
|
||||
status.CreatedTimestamp = _createdTimestamp;
|
||||
status.PendingApplicationMessagesCount = ApplicationMessagesQueue.Count;
|
||||
status.Items = Items;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using MQTTnet.Formatter;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Formatter;
|
||||
|
||||
namespace MQTTnet.Server.Status
|
||||
{
|
||||
@@ -9,7 +9,7 @@ namespace MQTTnet.Server.Status
|
||||
string ClientId { get; }
|
||||
|
||||
string Endpoint { get; }
|
||||
|
||||
|
||||
MqttProtocolVersion ProtocolVersion { get; }
|
||||
|
||||
DateTime LastPacketReceivedTimestamp { get; }
|
||||
@@ -29,7 +29,7 @@ namespace MQTTnet.Server.Status
|
||||
long BytesSent { get; }
|
||||
|
||||
long BytesReceived { get; }
|
||||
|
||||
|
||||
Task DisconnectAsync();
|
||||
|
||||
void ResetStatistics();
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MQTTnet.Server.Status
|
||||
{
|
||||
public interface IMqttSessionStatus
|
||||
{
|
||||
string ClientId { get; set; }
|
||||
string ClientId { get; }
|
||||
|
||||
long PendingApplicationMessagesCount { get; set; }
|
||||
long PendingApplicationMessagesCount { get; }
|
||||
|
||||
IDictionary<object, object> Items { get; }
|
||||
|
||||
Task ClearPendingApplicationMessagesAsync();
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
using System;
|
||||
using MQTTnet.Formatter;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Formatter;
|
||||
|
||||
namespace MQTTnet.Server.Status
|
||||
{
|
||||
public class MqttClientStatus : IMqttClientStatus
|
||||
{
|
||||
private readonly MqttClientConnection _connection;
|
||||
readonly MqttClientConnection _connection;
|
||||
|
||||
public MqttClientStatus(MqttClientConnection connection)
|
||||
{
|
||||
_connection = connection;
|
||||
_connection = connection ?? throw new ArgumentNullException(nameof(connection));
|
||||
}
|
||||
|
||||
public string ClientId { get; set; }
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MQTTnet.Server.Status
|
||||
{
|
||||
public class MqttSessionStatus : IMqttSessionStatus
|
||||
{
|
||||
private readonly MqttClientSession _session;
|
||||
private readonly MqttClientSessionsManager _sessionsManager;
|
||||
readonly MqttClientSession _session;
|
||||
readonly MqttClientSessionsManager _sessionsManager;
|
||||
|
||||
public MqttSessionStatus(MqttClientSession session, MqttClientSessionsManager sessionsManager)
|
||||
{
|
||||
@@ -17,14 +18,16 @@ namespace MQTTnet.Server.Status
|
||||
public string ClientId { get; set; }
|
||||
|
||||
public long PendingApplicationMessagesCount { get; set; }
|
||||
|
||||
|
||||
public DateTime CreatedTimestamp { get; set; }
|
||||
|
||||
public IDictionary<object, object> Items { get; set; }
|
||||
|
||||
public Task DeleteAsync()
|
||||
{
|
||||
return _sessionsManager.DeleteSessionAsync(ClientId);
|
||||
}
|
||||
|
||||
|
||||
public Task ClearPendingApplicationMessagesAsync()
|
||||
{
|
||||
_session.ApplicationMessagesQueue.Clear();
|
||||
|
||||
Reference in New Issue
Block a user