From 9da7d179ebf2b0eef5c9cb10379105e436f17a03 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Tue, 2 Apr 2024 14:57:56 +0200 Subject: [PATCH] Examples: Update dependencies & fix warnings (#141) --- .../ClientBenchmarkApp/ClientBenchmark.cs | 47 +++++++++---------- .../ConnectReceiveAndPublish.csproj | 2 +- Examples/Reconnect/Program.cs | 10 ++-- Examples/Reconnect/Reconnect.csproj | 2 +- .../SendMessageOnLoop.csproj | 2 +- 5 files changed, 27 insertions(+), 36 deletions(-) diff --git a/Benchmarks/ClientBenchmarkApp/ClientBenchmark.cs b/Benchmarks/ClientBenchmarkApp/ClientBenchmark.cs index a790cf78..44a8327a 100644 --- a/Benchmarks/ClientBenchmarkApp/ClientBenchmark.cs +++ b/Benchmarks/ClientBenchmarkApp/ClientBenchmark.cs @@ -18,17 +18,34 @@ public class ClientBenchmarks : IDisposable { private readonly string smallPayload = new string(/*lang=json,strict*/ "{\"interference\": \"1029384\"}"); - private HiveMQClient client; + private readonly string payload256k; - private string payload256k; + private readonly string payload256b; - private string payload256b; + private HiveMQClient client; public ClientBenchmarks() { Console.WriteLine("Starting HiveMQ client benchmarks..."); this.client = null!; - this.SetupPayloads(); + + // Generate a 256 byte payload + var sb = new StringBuilder(); + for (var i = 0; i < 256; i++) + { + sb.Append('a'); + } + + this.payload256b = sb.ToString(); + + // Generate a 256k payload + sb = new StringBuilder(); + for (var i = 0; i < 256 * 1024; i++) + { + sb.Append('a'); + } + + this.payload256k = sb.ToString(); } [GlobalSetup] @@ -153,26 +170,4 @@ await this.client.PublishAsync( } public void Dispose() => GC.SuppressFinalize(this); - - private void SetupPayloads() - { - // Generate a 256 byte payload - var sb = new StringBuilder(); - for (var i = 0; i < 256; i++) - { - sb.Append('a'); - } - - this.payload256b = sb.ToString(); - - // Generate a 256k payload - sb = new StringBuilder(); - for (var i = 0; i < 256 * 1024; i++) - { - sb.Append('a'); - } - - this.payload256k = sb.ToString(); - } - } diff --git a/Examples/ConnectReceiveAndPublish/ConnectReceiveAndPublish.csproj b/Examples/ConnectReceiveAndPublish/ConnectReceiveAndPublish.csproj index 5e293872..94690f8f 100644 --- a/Examples/ConnectReceiveAndPublish/ConnectReceiveAndPublish.csproj +++ b/Examples/ConnectReceiveAndPublish/ConnectReceiveAndPublish.csproj @@ -12,7 +12,7 @@ - + diff --git a/Examples/Reconnect/Program.cs b/Examples/Reconnect/Program.cs index 611f5155..c214774b 100644 --- a/Examples/Reconnect/Program.cs +++ b/Examples/Reconnect/Program.cs @@ -1,8 +1,8 @@ +using System.Text.Json; +using System.Diagnostics; using HiveMQtt.Client; using HiveMQtt.Client.Exceptions; using HiveMQtt.Client.Options; -using System.Text.Json; -using System.Diagnostics; var topic = "hivemqtt/waiting/game"; @@ -122,11 +122,7 @@ Console.WriteLine("Publishing a test message..."); var resultPublish = await client.PublishAsync( topic, - JsonSerializer.Serialize(new - { - Command = "Hello", - }) -).ConfigureAwait(false); + JsonSerializer.Serialize(new { Command = "Hello", })).ConfigureAwait(false); while (true) { diff --git a/Examples/Reconnect/Reconnect.csproj b/Examples/Reconnect/Reconnect.csproj index 9b7ca1d7..da623a8a 100644 --- a/Examples/Reconnect/Reconnect.csproj +++ b/Examples/Reconnect/Reconnect.csproj @@ -17,7 +17,7 @@ 4 - + diff --git a/Examples/SendMessageOnLoop/SendMessageOnLoop.csproj b/Examples/SendMessageOnLoop/SendMessageOnLoop.csproj index 5e293872..94690f8f 100644 --- a/Examples/SendMessageOnLoop/SendMessageOnLoop.csproj +++ b/Examples/SendMessageOnLoop/SendMessageOnLoop.csproj @@ -12,7 +12,7 @@ - +