mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
Add Directory.Build.props. (#2120)
* Add Directory.Build.props. * Adjust Analysis related properties and add conditional enablement for ContinuousIntegrationBuild. * Adopt new changes in master --------- Co-authored-by: christian <6939810+chkr1011@users.noreply.github.com>
This commit is contained in:
@@ -490,7 +490,7 @@ m/XriWr/Cq4h/JfB7NTsezVslgkBaoU=
|
||||
}
|
||||
}
|
||||
|
||||
class SampleClientKerberosAuthenticationHandler : IMqttEnhancedAuthenticationHandler
|
||||
sealed class SampleClientKerberosAuthenticationHandler : IMqttEnhancedAuthenticationHandler
|
||||
{
|
||||
public async Task HandleEnhancedAuthenticationAsync(MqttEnhancedAuthenticationEventArgs eventArgs)
|
||||
{
|
||||
|
||||
@@ -142,7 +142,7 @@ public static class Client_Subscribe_Samples
|
||||
response.DumpToConsole();
|
||||
}
|
||||
|
||||
static void ConcurrentProcessingDisableAutoAcknowledge(CancellationToken shutdownToken, IMqttClient mqttClient)
|
||||
static void ConcurrentProcessingDisableAutoAcknowledge(IMqttClient mqttClient, CancellationToken shutdownToken)
|
||||
{
|
||||
/*
|
||||
* This sample shows how to achieve concurrent processing and not have message AutoAcknowledged
|
||||
@@ -170,7 +170,7 @@ public static class Client_Subscribe_Samples
|
||||
};
|
||||
}
|
||||
|
||||
static void ConcurrentProcessingWithLimit(CancellationToken shutdownToken, IMqttClient mqttClient)
|
||||
static void ConcurrentProcessingWithLimit(IMqttClient mqttClient, CancellationToken shutdownToken)
|
||||
{
|
||||
/*
|
||||
* This sample shows how to achieve concurrent processing, with:
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using MQTTnet.Diagnostics.Logger;
|
||||
|
||||
@@ -51,7 +52,7 @@ public static class Logger_Samples
|
||||
mqttEventLogger.LogMessagePublished += (_, args) =>
|
||||
{
|
||||
var output = new StringBuilder();
|
||||
output.AppendLine($">> [{args.LogMessage.Timestamp:O}] [{args.LogMessage.ThreadId}] [{args.LogMessage.Source}] [{args.LogMessage.Level}]: {args.LogMessage.Message}");
|
||||
output.AppendLine(CultureInfo.InvariantCulture, $">> [{args.LogMessage.Timestamp:O}] [{args.LogMessage.ThreadId}] [{args.LogMessage.Source}] [{args.LogMessage.Level}]: {args.LogMessage.Message}");
|
||||
if (args.LogMessage.Exception != null)
|
||||
{
|
||||
output.AppendLine(args.LogMessage.Exception.ToString());
|
||||
|
||||
@@ -8,17 +8,19 @@ namespace MQTTnet.Samples.Helpers;
|
||||
|
||||
internal static class ObjectExtensions
|
||||
{
|
||||
static readonly JsonSerializerOptions SerializerOptions = new()
|
||||
{
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
public static TObject DumpToConsole<TObject>(this TObject @object)
|
||||
{
|
||||
var output = "NULL";
|
||||
if (@object != null)
|
||||
{
|
||||
output = JsonSerializer.Serialize(@object, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
output = JsonSerializer.Serialize(@object, SerializerOptions);
|
||||
}
|
||||
|
||||
|
||||
Console.WriteLine($"[{@object?.GetType().Name}]:\r\n{output}");
|
||||
return @object;
|
||||
}
|
||||
|
||||
@@ -2,19 +2,10 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<DisableImplicitAspNetCoreAnalyzers>true</DisableImplicitAspNetCoreAnalyzers>
|
||||
<EnableNETAnalyzers>false</EnableNETAnalyzers>
|
||||
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
|
||||
<NoWarn>1591;NETSDK1138;NU1803;NU1901;NU1902</NoWarn>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<NuGetAuditMode>all</NuGetAuditMode>
|
||||
<NuGetAudit>true</NuGetAudit>
|
||||
<NuGetAuditLevel>low</NuGetAuditLevel>
|
||||
<AnalysisLevel>latest-Recommended</AnalysisLevel>
|
||||
<NoWarn>$(NoWarn);CA1707</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+4
-3
@@ -2,6 +2,7 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
Console.BackgroundColor = ConsoleColor.White;
|
||||
@@ -28,7 +29,7 @@ Console.Write("Please choose sample class (press Enter to continue): ");
|
||||
Console.ResetColor();
|
||||
|
||||
var input = Console.ReadLine();
|
||||
var selectedIndex = int.Parse(input ?? "0");
|
||||
var selectedIndex = int.Parse(input ?? "0", CultureInfo.InvariantCulture);
|
||||
var selectedSampleClass = sampleClasses[selectedIndex];
|
||||
var sampleMethods = selectedSampleClass.GetMethods(BindingFlags.Static | BindingFlags.Public).OrderBy(m => m.Name).ToList();
|
||||
|
||||
@@ -45,7 +46,7 @@ Console.Write("Please choose sample (press Enter to continue): ");
|
||||
Console.ResetColor();
|
||||
|
||||
input = Console.ReadLine();
|
||||
selectedIndex = int.Parse(input ?? "0");
|
||||
selectedIndex = int.Parse(input ?? "0", CultureInfo.InvariantCulture);
|
||||
var selectedSampleMethod = sampleMethods[selectedIndex];
|
||||
|
||||
Console.WriteLine();
|
||||
@@ -58,7 +59,7 @@ try
|
||||
{
|
||||
if (selectedSampleMethod.Invoke(null, null) is Task task)
|
||||
{
|
||||
await task;
|
||||
await task;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
// ReSharper disable EmptyConstructor
|
||||
// ReSharper disable MemberCanBeMadeStatic.Local
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -52,14 +53,14 @@ public static class Server_ASP_NET_Samples
|
||||
// Inject other services via constructor.
|
||||
}
|
||||
|
||||
public Task OnClientConnected(ClientConnectedEventArgs eventArgs)
|
||||
public static Task OnClientConnected(ClientConnectedEventArgs eventArgs)
|
||||
{
|
||||
Console.WriteLine($"Client '{eventArgs.ClientId}' connected.");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
public Task ValidateConnection(ValidatingConnectionEventArgs eventArgs)
|
||||
public static Task ValidateConnection(ValidatingConnectionEventArgs eventArgs)
|
||||
{
|
||||
Console.WriteLine($"Client '{eventArgs.ClientId}' wants to connect. Accepting!");
|
||||
return Task.CompletedTask;
|
||||
@@ -68,6 +69,7 @@ public static class Server_ASP_NET_Samples
|
||||
|
||||
sealed class Startup
|
||||
{
|
||||
[SuppressMessage("Performance", "CA1822:Mark members as static")]
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment environment, MqttController mqttController)
|
||||
{
|
||||
app.UseRouting();
|
||||
@@ -88,11 +90,12 @@ public static class Server_ASP_NET_Samples
|
||||
* Attach event handlers etc. if required.
|
||||
*/
|
||||
|
||||
server.ValidatingConnectionAsync += mqttController.ValidateConnection;
|
||||
server.ClientConnectedAsync += mqttController.OnClientConnected;
|
||||
server.ValidatingConnectionAsync += MqttController.ValidateConnection;
|
||||
server.ClientConnectedAsync += MqttController.OnClientConnected;
|
||||
});
|
||||
}
|
||||
|
||||
[SuppressMessage("Performance", "CA1822:Mark members as static")]
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddHostedMqttServer(
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System.Globalization;
|
||||
using MQTTnet.Diagnostics.Logger;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Server;
|
||||
@@ -161,7 +162,7 @@ public static class Server_Simple_Samples
|
||||
return server;
|
||||
}
|
||||
|
||||
class ConsoleLogger : IMqttNetLogger
|
||||
sealed class ConsoleLogger : IMqttNetLogger
|
||||
{
|
||||
readonly object _consoleSyncRoot = new();
|
||||
|
||||
@@ -191,7 +192,7 @@ public static class Server_Simple_Samples
|
||||
|
||||
if (parameters?.Length > 0)
|
||||
{
|
||||
message = string.Format(message, parameters);
|
||||
message = string.Format(CultureInfo.InvariantCulture, message, parameters);
|
||||
}
|
||||
|
||||
lock (_consoleSyncRoot)
|
||||
|
||||
Reference in New Issue
Block a user