This commit is contained in:
Christian
2022-02-20 21:10:46 +01:00
committed by GitHub
parent 47e674e4d3
commit 2ce9b94ec9
608 changed files with 22364 additions and 19420 deletions
@@ -1,9 +0,0 @@
using System.Threading.Tasks;
namespace MQTTnet.Client.Disconnecting
{
public interface IMqttClientDisconnectedHandler
{
Task HandleDisconnectedAsync(MqttClientDisconnectedEventArgs eventArgs);
}
}
@@ -1,4 +1,8 @@
namespace MQTTnet.Client.Disconnecting
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace MQTTnet.Client
{
public sealed class MqttClientDisconnectOptions
{
@@ -6,7 +10,7 @@
/// Gets or sets the reason code.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientDisconnectReason ReasonCode { get; set; } = MqttClientDisconnectReason.NormalDisconnection;
public MqttClientDisconnectReason Reason { get; set; } = MqttClientDisconnectReason.NormalDisconnection;
/// <summary>
/// Gets or sets the reason string.
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace MQTTnet.Client
{
public sealed class MqttClientDisconnectOptionsBuilder
{
MqttClientDisconnectReason _reason = MqttClientDisconnectReason.NormalDisconnection;
string _reasonString;
public MqttClientDisconnectOptionsBuilder WithReasonString(string value)
{
_reasonString = value;
return this;
}
public MqttClientDisconnectOptionsBuilder WithReason(MqttClientDisconnectReason value)
{
_reason = value;
return this;
}
public MqttClientDisconnectOptions Build()
{
return new MqttClientDisconnectOptions
{
Reason = _reason,
ReasonString = _reasonString
};
}
}
}
@@ -1,4 +1,8 @@
namespace MQTTnet.Client.Disconnecting
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace MQTTnet.Client
{
public enum MqttClientDisconnectReason
{
@@ -1,37 +1,29 @@
using System;
using MQTTnet.Client.Connecting;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace MQTTnet.Client.Disconnecting
using System;
namespace MQTTnet.Client
{
public sealed class MqttClientDisconnectedEventArgs : EventArgs
{
public MqttClientDisconnectedEventArgs(bool clientWasConnected, Exception exception, MqttClientConnectResult connectResult, MqttClientDisconnectReason reason)
{
ClientWasConnected = clientWasConnected;
Exception = exception;
ConnectResult = connectResult;
Reason = reason;
public bool ClientWasConnected { get; internal set; }
ReasonCode = reason;
}
public bool ClientWasConnected { get; }
public Exception Exception { get; }
public Exception Exception { get; internal set; }
/// <summary>
/// Gets the authentication result.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientConnectResult ConnectResult { get; }
public MqttClientConnectResult ConnectResult { get; internal set; }
/// <summary>
/// Gets or sets the reason.
/// Hint: MQTT 5 feature only.
/// </summary>
public MqttClientDisconnectReason Reason { get; set; }
[Obsolete("Please use 'Reason' instead. This property will be removed in the future!")]
public MqttClientDisconnectReason ReasonCode { get; set; }
public MqttClientDisconnectReason Reason { get; internal set; }
public string ReasonString { get; internal set; }
}
}
@@ -1,31 +0,0 @@
using System;
using System.Threading.Tasks;
namespace MQTTnet.Client.Disconnecting
{
public class MqttClientDisconnectedHandlerDelegate : IMqttClientDisconnectedHandler
{
private readonly Func<MqttClientDisconnectedEventArgs, Task> _handler;
public MqttClientDisconnectedHandlerDelegate(Action<MqttClientDisconnectedEventArgs> handler)
{
if (handler == null) throw new ArgumentNullException(nameof(handler));
_handler = context =>
{
handler(context);
return Task.FromResult(0);
};
}
public MqttClientDisconnectedHandlerDelegate(Func<MqttClientDisconnectedEventArgs, Task> handler)
{
_handler = handler ?? throw new ArgumentNullException(nameof(handler));
}
public Task HandleDisconnectedAsync(MqttClientDisconnectedEventArgs eventArgs)
{
return _handler(eventArgs);
}
}
}