Skip to content

Commit

Permalink
Rename InspectPackage method (#1713)
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 authored Apr 23, 2023
1 parent 8b3b9d3 commit cb3c44f
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [Client] MQTTv5 features are now checked and an exception is thrown if they are used when using protocol version 3.1.1 and lower. These checks can be disabled in client options. (BREAKING CHANGE!).
* [Client] Added support for disabling packet fragmentation (required for i.e. AWS, #1690, thanks to @logicaloud).
* [Client] Added new overloads for options builder.
* [Client] Renamed _InspectPackage_ to _InspectPacketAsync_ (BREAKING CHANGE).
* [ManagedClient] Exposed added and removed topics in _ManagedProcessFailedEventArgs_ (#1678, thanks to @scottbrogden-iheartmedia).
* [Server] Exposed MQTT v5 sent properties from the affected client in _ClientDisconnectedAsync_ event.
* [Server] Fixed wrong client ID passed to _InterceptingUnsubscriptionEventArgs_ (#1631, thanks to @ghord).
Expand Down
4 changes: 2 additions & 2 deletions Samples/Diagnostics/PackageInspection_Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static async Task Inspect_Outgoing_Package()
.WithTcpServer("broker.hivemq.com")
.Build();

mqttClient.InspectPackage += OnInspectPackage;
mqttClient.InspectPacketAsync += OnInspectPacket;

await mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);

Expand All @@ -39,7 +39,7 @@ public static async Task Inspect_Outgoing_Package()
}
}

static Task OnInspectPackage(InspectMqttPacketEventArgs eventArgs)
static Task OnInspectPacket(InspectMqttPacketEventArgs eventArgs)
{
if (eventArgs.Direction == MqttPacketFlowDirection.Inbound)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/MQTTnet.Tests/Diagnostics/PacketInspection_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task Inspect_Client_Packets()

var packets = new List<string>();

mqttClient.InspectPackage += eventArgs =>
mqttClient.InspectPacketAsync += eventArgs =>
{
packets.Add(eventArgs.Direction + ":" + Convert.ToBase64String(eventArgs.Buffer));
return CompletedTask.Instance;
Expand Down
2 changes: 1 addition & 1 deletion Source/MQTTnet.Tests/Server/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ public async Task Disconnect_Client_with_Reason()

var client = testEnvironment.CreateClient();

client.InspectPackage += e =>
client.InspectPacketAsync += e =>
{
if (e.Buffer.Length > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/MQTTnet/Client/IMqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface IMqttClient : IDisposable

event Func<MqttClientDisconnectedEventArgs, Task> DisconnectedAsync;

event Func<InspectMqttPacketEventArgs, Task> InspectPackage;
event Func<InspectMqttPacketEventArgs, Task> InspectPacketAsync;

bool IsConnected { get; }

Expand Down
2 changes: 1 addition & 1 deletion Source/MQTTnet/Client/MqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public event Func<MqttClientDisconnectedEventArgs, Task> DisconnectedAsync
remove => _disconnectedEvent.RemoveHandler(value);
}

public event Func<InspectMqttPacketEventArgs, Task> InspectPackage
public event Func<InspectMqttPacketEventArgs, Task> InspectPacketAsync
{
add => _inspectPacketEvent.AddHandler(value);
remove => _inspectPacketEvent.RemoveHandler(value);
Expand Down
2 changes: 1 addition & 1 deletion Source/MQTTnet/LowLevelClient/ILowLevelMqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace MQTTnet.LowLevelClient
{
public interface ILowLevelMqttClient : IDisposable
{
event Func<InspectMqttPacketEventArgs, Task> InspectPackage;
event Func<InspectMqttPacketEventArgs, Task> InspectPacketAsync;

bool IsConnected { get; }

Expand Down
14 changes: 10 additions & 4 deletions Source/MQTTnet/LowLevelClient/LowLevelMqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public LowLevelMqttClient(IMqttClientAdapterFactory clientAdapterFactory, IMqttN
_logger = logger.WithSource(nameof(LowLevelMqttClient));
}

public event Func<InspectMqttPacketEventArgs, Task> InspectPackage
public event Func<InspectMqttPacketEventArgs, Task> InspectPacketAsync
{
add => _inspectPacketEvent.AddHandler(value);
remove => _inspectPacketEvent.RemoveHandler(value);
Expand All @@ -52,13 +52,19 @@ public async Task ConnectAsync(MqttClientOptions options, CancellationToken canc
throw new InvalidOperationException("Low level MQTT client is already connected. Disconnect first before connecting again.");
}

var newAdapter = _clientAdapterFactory.CreateClientAdapter(options, new MqttPacketInspector(_inspectPacketEvent, _rootLogger), _rootLogger);
MqttPacketInspector packetInspector = null;
if (_inspectPacketEvent.HasHandlers)
{
packetInspector = new MqttPacketInspector(_inspectPacketEvent, _rootLogger);
}

var newAdapter = _clientAdapterFactory.CreateClientAdapter(options, packetInspector, _rootLogger);

try
{
_logger.Verbose("Trying to connect with server '{0}'.", options.ChannelOptions);
_logger.Verbose("Trying to connect with server '{0}'", options.ChannelOptions);
await newAdapter.ConnectAsync(cancellationToken).ConfigureAwait(false);
_logger.Verbose("Connection with server established.");
_logger.Verbose("Connection with server established");
}
catch (Exception)
{
Expand Down

0 comments on commit cb3c44f

Please sign in to comment.