Преглед на файлове

Add authentication result to disconnected handler.

release/3.x.x
Christian Kratky преди 5 години
родител
ревизия
1a8bcae47c
променени са 3 файла, в които са добавени 17 реда и са изтрити 10 реда
  1. +1
    -0
      Build/MQTTnet.nuspec
  2. +5
    -1
      Source/MQTTnet/Client/Disconnecting/MqttClientDisconnectedEventArgs.cs
  3. +11
    -9
      Source/MQTTnet/Client/MqttClient.cs

+ 1
- 0
Build/MQTTnet.nuspec Целия файл

@@ -13,6 +13,7 @@
<releaseNotes>
* [Core] Fixed missing properties from PUBLISH packet in _MqttApplicationMessage_ (thanks to @pcbing).
* [Core] Fixed wrong encoding of PUBREL and PUBCOMP packets for MQTTv5 (thanks to @perphilipp).
* [Client] Added the authentication result to the disconnected handler (only set when connecting failed).
* [Server] Fixed a bug which returns wrong flag for existing session in CONNACK packet (thanks to @avengerstark).
* [nuget] .NET Framework builds are now using 4.5.2 or 4.6.1 builds instead of netstandard 2.0.
</releaseNotes>


+ 5
- 1
Source/MQTTnet/Client/Disconnecting/MqttClientDisconnectedEventArgs.cs Целия файл

@@ -1,17 +1,21 @@
using System;
using MQTTnet.Client.Connecting;

namespace MQTTnet.Client.Disconnecting
{
public class MqttClientDisconnectedEventArgs : EventArgs
{
public MqttClientDisconnectedEventArgs(bool clientWasConnected, Exception exception)
public MqttClientDisconnectedEventArgs(bool clientWasConnected, Exception exception, MqttClientAuthenticateResult authenticateResult)
{
ClientWasConnected = clientWasConnected;
Exception = exception;
AuthenticateResult = authenticateResult;
}

public bool ClientWasConnected { get; }

public Exception Exception { get; }

public MqttClientAuthenticateResult AuthenticateResult { get; }
}
}

+ 11
- 9
Source/MQTTnet/Client/MqttClient.cs Целия файл

@@ -61,6 +61,8 @@ namespace MQTTnet.Client

ThrowIfConnected("It is not allowed to connect with a server after the connection is established.");

MqttClientAuthenticateResult authenticateResult = null;

try
{
Options = options;
@@ -81,7 +83,7 @@ namespace MQTTnet.Client

_packetReceiverTask = Task.Run(() => TryReceivePacketsAsync(backgroundCancellationToken), backgroundCancellationToken);

var authenticateResult = await AuthenticateAsync(adapter, options.WillMessage, cancellationToken).ConfigureAwait(false);
authenticateResult = await AuthenticateAsync(adapter, options.WillMessage, cancellationToken).ConfigureAwait(false);

_sendTracker.Restart();

@@ -108,7 +110,7 @@ namespace MQTTnet.Client

if (!DisconnectIsPending())
{
await DisconnectInternalAsync(null, exception).ConfigureAwait(false);
await DisconnectInternalAsync(null, exception, authenticateResult).ConfigureAwait(false);
}

throw;
@@ -131,7 +133,7 @@ namespace MQTTnet.Client
{
if (!DisconnectIsPending())
{
await DisconnectInternalAsync(null, null).ConfigureAwait(false);
await DisconnectInternalAsync(null, null, null).ConfigureAwait(false);
}
}
}
@@ -232,7 +234,7 @@ namespace MQTTnet.Client
if (IsConnected) throw new MqttProtocolViolationException(message);
}

private async Task DisconnectInternalAsync(Task sender, Exception exception)
private async Task DisconnectInternalAsync(Task sender, Exception exception, MqttClientAuthenticateResult authenticateResult)
{
var clientWasConnected = IsConnected;

@@ -267,7 +269,7 @@ namespace MQTTnet.Client
var disconnectedHandler = DisconnectedHandler;
if (disconnectedHandler != null)
{
await disconnectedHandler.HandleDisconnectedAsync(new MqttClientDisconnectedEventArgs(clientWasConnected, exception)).ConfigureAwait(false);
await disconnectedHandler.HandleDisconnectedAsync(new MqttClientDisconnectedEventArgs(clientWasConnected, exception, authenticateResult)).ConfigureAwait(false);
}
}
}
@@ -376,7 +378,7 @@ namespace MQTTnet.Client

if (!DisconnectIsPending())
{
await DisconnectInternalAsync(_keepAlivePacketsSenderTask, exception).ConfigureAwait(false);
await DisconnectInternalAsync(_keepAlivePacketsSenderTask, exception, null).ConfigureAwait(false);
}
}
finally
@@ -404,7 +406,7 @@ namespace MQTTnet.Client
{
if (!DisconnectIsPending())
{
await DisconnectInternalAsync(_packetReceiverTask, null).ConfigureAwait(false);
await DisconnectInternalAsync(_packetReceiverTask, null, null).ConfigureAwait(false);
}

return;
@@ -436,7 +438,7 @@ namespace MQTTnet.Client

if (!DisconnectIsPending())
{
await DisconnectInternalAsync(_packetReceiverTask, exception).ConfigureAwait(false);
await DisconnectInternalAsync(_packetReceiverTask, exception, null).ConfigureAwait(false);
}
}
finally
@@ -497,7 +499,7 @@ namespace MQTTnet.Client

if (!DisconnectIsPending())
{
await DisconnectInternalAsync(_packetReceiverTask, exception).ConfigureAwait(false);
await DisconnectInternalAsync(_packetReceiverTask, exception, null).ConfigureAwait(false);
}
}
}


Зареждане…
Отказ
Запис