diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ee49d4b5..dfe256aa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,6 +67,14 @@ jobs: - name: "Dotnet Cake Pack" run: dotnet cake --target=Pack shell: pwsh + publish: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4.1.6 + - name: Push to NuGet if: github.event_name == 'release' run: dotnet nuget push ./Artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate + shell: pwsh diff --git a/Source/HiveMQtt/Client/HiveMQClient.cs b/Source/HiveMQtt/Client/HiveMQClient.cs index 9542b751..eeee4d27 100644 --- a/Source/HiveMQtt/Client/HiveMQClient.cs +++ b/Source/HiveMQtt/Client/HiveMQClient.cs @@ -503,7 +503,7 @@ private async Task HandleDisconnectionAsync(bool clean = true) // Cancel all background tasks and close the socket this.ConnectState = ConnectState.Disconnected; - await this.cancellationTokenSource.CancelAsync().ConfigureAwait(false); + this.cancellationTokenSource.Cancel(); this.CloseSocket(); if (clean) diff --git a/Source/HiveMQtt/Client/HiveMQClientEvents.cs b/Source/HiveMQtt/Client/HiveMQClientEvents.cs index 44f8d402..3c459b07 100644 --- a/Source/HiveMQtt/Client/HiveMQClientEvents.cs +++ b/Source/HiveMQtt/Client/HiveMQClientEvents.cs @@ -45,7 +45,7 @@ protected virtual void BeforeConnectEventLauncher(HiveMQClientOptions options) { if (t.IsFaulted) { - Logger.Error("BeforeConnectEventLauncher exception: " + t.Exception.Message); + Logger.Error("BeforeConnectEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -68,7 +68,7 @@ protected virtual void AfterConnectEventLauncher(ConnectResult results) { if (t.IsFaulted) { - Logger.Error("AfterConnectEventLauncher exception: " + t.Exception.Message); + Logger.Error("AfterConnectEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -91,7 +91,7 @@ protected virtual void BeforeDisconnectEventLauncher() { if (t.IsFaulted) { - Logger.Error("BeforeDisconnectEventLauncher exception: " + t.Exception.Message); + Logger.Error("BeforeDisconnectEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -114,7 +114,7 @@ protected virtual void AfterDisconnectEventLauncher(bool clean = false) { if (t.IsFaulted) { - Logger.Error("AfterDisconnectEventLauncher exception: " + t.Exception.Message); + Logger.Error("AfterDisconnectEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -137,7 +137,7 @@ protected virtual void BeforeSubscribeEventLauncher(SubscribeOptions options) { if (t.IsFaulted) { - Logger.Error("BeforeSubscribeEventLauncher exception: " + t.Exception.Message); + Logger.Error("BeforeSubscribeEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -160,7 +160,7 @@ protected virtual void AfterSubscribeEventLauncher(SubscribeResult results) { if (t.IsFaulted) { - Logger.Error("AfterSubscribeEventLauncher exception: " + t.Exception.Message); + Logger.Error("AfterSubscribeEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -183,7 +183,7 @@ protected virtual void BeforeUnsubscribeEventLauncher(List subscri { if (t.IsFaulted) { - Logger.Error("BeforeUnsubscribeEventLauncher exception: " + t.Exception.Message); + Logger.Error("BeforeUnsubscribeEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -206,7 +206,7 @@ protected virtual void AfterUnsubscribeEventLauncher(UnsubscribeResult results) { if (t.IsFaulted) { - Logger.Error("AfterUnsubscribeEventLauncher exception: " + t.Exception.Message); + Logger.Error("AfterUnsubscribeEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -233,7 +233,7 @@ protected virtual void OnMessageReceivedEventLauncher(PublishPacket packet) { if (t.IsFaulted) { - Logger.Error("OnMessageReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnMessageReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -254,7 +254,7 @@ protected virtual void OnMessageReceivedEventLauncher(PublishPacket packet) { if (t.IsFaulted) { - Logger.Error($"per-subscription MessageReceivedEventLauncher faulted ({packet.Message.Topic}): " + t.Exception.Message); + Logger.Error($"per-subscription MessageReceivedEventLauncher faulted ({packet.Message.Topic}): " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -293,7 +293,7 @@ protected virtual void OnConnectSentEventLauncher(ConnectPacket packet) { if (t.IsFaulted) { - Logger.Error("OnConnectSentEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnConnectSentEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -316,7 +316,7 @@ protected virtual void OnConnAckReceivedEventLauncher(ConnAckPacket packet) { if (t.IsFaulted) { - Logger.Error("OnConnAckReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnConnAckReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -339,7 +339,7 @@ protected virtual void OnDisconnectSentEventLauncher(DisconnectPacket packet) { if (t.IsFaulted) { - Logger.Error("OnDisconnectSentEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnDisconnectSentEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -362,7 +362,7 @@ protected virtual void OnDisconnectReceivedEventLauncher(DisconnectPacket packet { if (t.IsFaulted) { - Logger.Error("OnDisconnectReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnDisconnectReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -385,7 +385,7 @@ protected virtual void OnPingReqSentEventLauncher(PingReqPacket packet) { if (t.IsFaulted) { - Logger.Error("OnPingReqSentEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnPingReqSentEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -408,7 +408,7 @@ protected virtual void OnPingRespReceivedEventLauncher(PingRespPacket packet) { if (t.IsFaulted) { - Logger.Error("OnPingRespReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnPingRespReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -431,7 +431,7 @@ protected virtual void OnSubscribeSentEventLauncher(SubscribePacket packet) { if (t.IsFaulted) { - Logger.Error("OnSubscribeSentEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnSubscribeSentEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -454,7 +454,7 @@ protected virtual void OnSubAckReceivedEventLauncher(SubAckPacket packet) { if (t.IsFaulted) { - Logger.Error("OnSubAckReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnSubAckReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -477,7 +477,7 @@ protected virtual void OnUnsubscribeSentEventLauncher(UnsubscribePacket packet) { if (t.IsFaulted) { - Logger.Error("OnUnsubscribeSentEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnUnsubscribeSentEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -500,7 +500,7 @@ protected virtual void OnUnsubAckReceivedEventLauncher(UnsubAckPacket packet) { if (t.IsFaulted) { - Logger.Error("OnUnsubAckReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnUnsubAckReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -523,7 +523,7 @@ protected virtual void OnPublishReceivedEventLauncher(PublishPacket packet) { if (t.IsFaulted) { - Logger.Error("OnPublishReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnPublishReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -546,7 +546,7 @@ protected virtual void OnPublishSentEventLauncher(PublishPacket packet) { if (t.IsFaulted) { - Logger.Error("OnPublishSentEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnPublishSentEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -569,7 +569,7 @@ protected virtual void OnPubAckReceivedEventLauncher(PubAckPacket packet) { if (t.IsFaulted) { - Logger.Error("OnPubAckReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnPubAckReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -592,7 +592,7 @@ protected virtual void OnPubAckSentEventLauncher(PubAckPacket packet) { if (t.IsFaulted) { - Logger.Error("OnPubAckSentEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnPubAckSentEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -615,7 +615,7 @@ protected virtual void OnPubRecReceivedEventLauncher(PubRecPacket packet) { if (t.IsFaulted) { - Logger.Error("OnPubRecReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnPubRecReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -638,7 +638,7 @@ protected virtual void OnPubRecSentEventLauncher(PubRecPacket packet) { if (t.IsFaulted) { - Logger.Error("OnPubRecSentEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnPubRecSentEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -661,7 +661,7 @@ protected virtual void OnPubRelReceivedEventLauncher(PubRelPacket packet) { if (t.IsFaulted) { - Logger.Error("OnPubRelReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnPubRelReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -684,7 +684,7 @@ protected virtual void OnPubRelSentEventLauncher(PubRelPacket packet) { if (t.IsFaulted) { - Logger.Error("OnPubRelSentEventLauncher exception: " + t.Exception.Message); + Logger.Error("OnPubRelSentEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -707,7 +707,7 @@ protected virtual void OnPubCompReceivedEventLauncher(PubCompPacket packet) { if (t.IsFaulted) { - Logger.Error("PubCompReceivedEventLauncher exception: " + t.Exception.Message); + Logger.Error("PubCompReceivedEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); @@ -730,7 +730,7 @@ protected virtual void OnPubCompSentEventLauncher(PubCompPacket packet) { if (t.IsFaulted) { - Logger.Error("PubCompSentEventLauncher exception: " + t.Exception.Message); + Logger.Error("PubCompSentEventLauncher exception: " + t.Exception?.Message); } }, TaskScheduler.Default); diff --git a/Source/HiveMQtt/HiveMQtt.csproj b/Source/HiveMQtt/HiveMQtt.csproj index 4ae07516..7e9e30bc 100644 --- a/Source/HiveMQtt/HiveMQtt.csproj +++ b/Source/HiveMQtt/HiveMQtt.csproj @@ -1,11 +1,15 @@ - net8.0 HiveMQtt The HiveMQ MQTT Client is a MQTT 5.0 compatible C# library. + + net6.0;net7.0;net8.0 + true + + v