From 15a564dcfea5d4d70ff3078b326128fe1e403603 Mon Sep 17 00:00:00 2001 From: Jan Eggers Date: Thu, 26 Oct 2017 07:53:22 +0200 Subject: [PATCH 1/8] removed smokebombs (stop the server in finally so other test dont fail because stop is not called in other test) --- Tests/MQTTnet.Core.Tests/MqttServerTests.cs | 271 ++++++++++++-------- 1 file changed, 165 insertions(+), 106 deletions(-) diff --git a/Tests/MQTTnet.Core.Tests/MqttServerTests.cs b/Tests/MQTTnet.Core.Tests/MqttServerTests.cs index d548ff0..97aa3f8 100644 --- a/Tests/MQTTnet.Core.Tests/MqttServerTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttServerTests.cs @@ -52,22 +52,26 @@ namespace MQTTnet.Core.Tests { var serverAdapter = new TestMqttServerAdapter(); var s = new MqttFactory().CreateMqttServer(); - await s.StartAsync(); - - var willMessage = new MqttApplicationMessageBuilder().WithTopic("My/last/will").WithAtMostOnceQoS().Build(); - var c1 = await serverAdapter.ConnectTestClient(s, "c1"); - var c2 = await serverAdapter.ConnectTestClient(s, "c2", willMessage); - var receivedMessagesCount = 0; - c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await c1.SubscribeAsync(new TopicFilter("#", MqttQualityOfServiceLevel.AtMostOnce)); + try + { + await s.StartAsync(); - await c2.DisconnectAsync(); + var willMessage = new MqttApplicationMessageBuilder().WithTopic("My/last/will").WithAtMostOnceQoS().Build(); + var c1 = await serverAdapter.ConnectTestClient(s, "c1"); + var c2 = await serverAdapter.ConnectTestClient(s, "c2", willMessage); - await Task.Delay(1000); + c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; + await c1.SubscribeAsync(new TopicFilter("#", MqttQualityOfServiceLevel.AtMostOnce)); - await s.StopAsync(); + await c2.DisconnectAsync(); + await Task.Delay(1000); + } + finally + { + await s.StopAsync(); + } Assert.AreEqual(1, receivedMessagesCount); } @@ -76,32 +80,38 @@ namespace MQTTnet.Core.Tests { var serverAdapter = new TestMqttServerAdapter(); var s = new MqttFactory().CreateMqttServer(); - await s.StartAsync(); - - var c1 = await serverAdapter.ConnectTestClient(s, "c1"); - var c2 = await serverAdapter.ConnectTestClient(s, "c2"); var receivedMessagesCount = 0; - c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - var message = new MqttApplicationMessageBuilder().WithTopic("a").WithAtLeastOnceQoS().Build(); + try + { + await s.StartAsync(); - await c2.PublishAsync(message); - Assert.AreEqual(0, receivedMessagesCount); + var c1 = await serverAdapter.ConnectTestClient(s, "c1"); + var c2 = await serverAdapter.ConnectTestClient(s, "c2"); + c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await c1.SubscribeAsync(new TopicFilter("a", MqttQualityOfServiceLevel.AtLeastOnce)); - await c2.PublishAsync(message); + var message = new MqttApplicationMessageBuilder().WithTopic("a").WithAtLeastOnceQoS().Build(); - await Task.Delay(500); - Assert.AreEqual(1, receivedMessagesCount); + await c2.PublishAsync(message); + Assert.AreEqual(0, receivedMessagesCount); - await c1.UnsubscribeAsync("a"); - await c2.PublishAsync(message); + await c1.SubscribeAsync(new TopicFilter("a", MqttQualityOfServiceLevel.AtLeastOnce)); + await c2.PublishAsync(message); - await Task.Delay(500); - Assert.AreEqual(1, receivedMessagesCount); + await Task.Delay(500); + Assert.AreEqual(1, receivedMessagesCount); + + await c1.UnsubscribeAsync("a"); + await c2.PublishAsync(message); - await s.StopAsync(); + await Task.Delay(500); + Assert.AreEqual(1, receivedMessagesCount); + } + finally + { + await s.StopAsync(); + } await Task.Delay(500); Assert.AreEqual(1, receivedMessagesCount); @@ -112,21 +122,27 @@ namespace MQTTnet.Core.Tests { var serverAdapter = new TestMqttServerAdapter(); var s = new MqttFactory().CreateMqttServer(); - await s.StartAsync(); - - var c1 = await serverAdapter.ConnectTestClient(s, "c1"); - var receivedMessagesCount = 0; - c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - var message = new MqttApplicationMessageBuilder().WithTopic("a").WithAtLeastOnceQoS().Build(); - await c1.SubscribeAsync(new TopicFilter("a", MqttQualityOfServiceLevel.AtLeastOnce)); + try + { + await s.StartAsync(); - s.PublishAsync(message).Wait(); - await Task.Delay(500); + var c1 = await serverAdapter.ConnectTestClient(s, "c1"); - await s.StopAsync(); + c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; + var message = new MqttApplicationMessageBuilder().WithTopic("a").WithAtLeastOnceQoS().Build(); + await c1.SubscribeAsync(new TopicFilter("a", MqttQualityOfServiceLevel.AtLeastOnce)); + + s.PublishAsync(message).Wait(); + await Task.Delay(500); + } + finally + { + await s.StopAsync(); + } + Assert.AreEqual(1, receivedMessagesCount); } @@ -135,20 +151,26 @@ namespace MQTTnet.Core.Tests { var serverAdapter = new TestMqttServerAdapter(); var s = new MqttFactory().CreateMqttServer(); - await s.StartAsync(); + var receivedMessagesCount = 0; - var c1 = await serverAdapter.ConnectTestClient(s, "c1"); - await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).Build()); - await c1.DisconnectAsync(); + try + { + await s.StartAsync(); - var c2 = await serverAdapter.ConnectTestClient(s, "c2"); - var receivedMessagesCount = 0; - c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce)); + var c1 = await serverAdapter.ConnectTestClient(s, "c1"); + await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).Build()); + await c1.DisconnectAsync(); - await Task.Delay(500); + var c2 = await serverAdapter.ConnectTestClient(s, "c2"); + c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; + await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce)); - await s.StopAsync(); + await Task.Delay(500); + } + finally + { + await s.StopAsync(); + } Assert.AreEqual(0, receivedMessagesCount); } @@ -158,21 +180,27 @@ namespace MQTTnet.Core.Tests { var serverAdapter = new TestMqttServerAdapter(); var s = new MqttFactory().CreateMqttServer(); - await s.StartAsync(); - - var c1 = await serverAdapter.ConnectTestClient(s, "c1"); - await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).WithRetainFlag().Build()); - await c1.DisconnectAsync(); - var c2 = await serverAdapter.ConnectTestClient(s, "c2"); var receivedMessagesCount = 0; - c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce)); + try + { + await s.StartAsync(); - await Task.Delay(500); + var c1 = await serverAdapter.ConnectTestClient(s, "c1"); + await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).WithRetainFlag().Build()); + await c1.DisconnectAsync(); - await s.StopAsync(); + var c2 = await serverAdapter.ConnectTestClient(s, "c2"); + c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; + await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce)); + await Task.Delay(500); + } + finally + { + await s.StopAsync(); + } + Assert.AreEqual(1, receivedMessagesCount); } @@ -187,21 +215,27 @@ namespace MQTTnet.Core.Tests .BuildServiceProvider(); var s = new MqttFactory(services).CreateMqttServer(); - await s.StartAsync(); + var receivedMessagesCount = 0; + try + { + await s.StartAsync(); - var c1 = await serverAdapter.ConnectTestClient(s, "c1"); - await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).WithRetainFlag().Build()); - await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[0]).WithRetainFlag().Build()); - await c1.DisconnectAsync(); + var c1 = await serverAdapter.ConnectTestClient(s, "c1"); + await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).WithRetainFlag().Build()); + await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[0]).WithRetainFlag().Build()); + await c1.DisconnectAsync(); - var c2 = await serverAdapter.ConnectTestClient(s, "c2"); - var receivedMessagesCount = 0; - c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce)); + var c2 = await serverAdapter.ConnectTestClient(s, "c2"); + c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; + await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce)); - await Task.Delay(500); + await Task.Delay(500); + } + finally + { + await s.StopAsync(); + } - await s.StopAsync(); Assert.AreEqual(0, receivedMessagesCount); } @@ -219,25 +253,37 @@ namespace MQTTnet.Core.Tests .BuildServiceProvider(); var s = new MqttFactory(services).CreateMqttServer(); // TODO: Like here? - await s.StartAsync(); - var c1 = await serverAdapter.ConnectTestClient(s, "c1"); - await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).WithRetainFlag().Build()); - await c1.DisconnectAsync(); + try + { + await s.StartAsync(); - await s.StopAsync(); + var c1 = await serverAdapter.ConnectTestClient(s, "c1"); + await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).WithRetainFlag().Build()); + await c1.DisconnectAsync(); + } + finally + { + await s.StopAsync(); + } s = services.GetRequiredService(); - await s.StartAsync(); - var c2 = await serverAdapter.ConnectTestClient(s, "c2"); var receivedMessagesCount = 0; - c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce)); + try + { + await s.StartAsync(); - await Task.Delay(500); + var c2 = await serverAdapter.ConnectTestClient(s, "c2"); + c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; + await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce)); - await s.StopAsync(); + await Task.Delay(500); + } + finally + { + await s.StopAsync(); + } Assert.AreEqual(1, receivedMessagesCount); } @@ -259,25 +305,32 @@ namespace MQTTnet.Core.Tests .BuildServiceProvider(); var s = services.GetRequiredService(); - await s.StartAsync(); + try + { + await s.StartAsync(); - var c1 = await serverAdapter.ConnectTestClient(s, "c1"); - var c2 = await serverAdapter.ConnectTestClient(s, "c2"); - await c2.SubscribeAsync(new TopicFilterBuilder().WithTopic("test").Build()); + var c1 = await serverAdapter.ConnectTestClient(s, "c1"); + var c2 = await serverAdapter.ConnectTestClient(s, "c2"); + await c2.SubscribeAsync(new TopicFilterBuilder().WithTopic("test").Build()); - var isIntercepted = false; - c2.ApplicationMessageReceived += (sender, args) => - { - isIntercepted = string.Compare("extended", Encoding.UTF8.GetString(args.ApplicationMessage.Payload), StringComparison.Ordinal) == 0; - }; + var isIntercepted = false; + c2.ApplicationMessageReceived += (sender, args) => + { + isIntercepted = string.Compare("extended", Encoding.UTF8.GetString(args.ApplicationMessage.Payload), StringComparison.Ordinal) == 0; + }; - var m = new MqttApplicationMessageBuilder().WithTopic("test").Build(); - await c1.PublishAsync(m); - await c1.DisconnectAsync(); + var m = new MqttApplicationMessageBuilder().WithTopic("test").Build(); + await c1.PublishAsync(m); + await c1.DisconnectAsync(); - await Task.Delay(500); + await Task.Delay(500); - Assert.IsTrue(isIntercepted); + Assert.IsTrue(isIntercepted); + } + finally + { + await s.StopAsync(); + } } private class TestStorage : IMqttServerStorage @@ -306,28 +359,34 @@ namespace MQTTnet.Core.Tests var serverAdapter = new TestMqttServerAdapter(); var services = new ServiceCollection() .AddMqttServer() + .AddLogging() .AddSingleton(serverAdapter) .BuildServiceProvider(); var s = services.GetRequiredService(); - await s.StartAsync(); - - var c1 = await serverAdapter.ConnectTestClient(s, "c1"); - var c2 = await serverAdapter.ConnectTestClient(s, "c2"); - var receivedMessagesCount = 0; - c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; + try + { + await s.StartAsync(); - await c1.SubscribeAsync(new TopicFilterBuilder().WithTopic(topicFilter).WithQualityOfServiceLevel(filterQualityOfServiceLevel).Build()); - await c2.PublishAsync(new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(new byte[0]).WithQualityOfServiceLevel(qualityOfServiceLevel).Build()); + var c1 = await serverAdapter.ConnectTestClient(s, "c1"); + var c2 = await serverAdapter.ConnectTestClient(s, "c2"); - await Task.Delay(500); - await c1.UnsubscribeAsync(topicFilter); + c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await Task.Delay(500); + await c1.SubscribeAsync(new TopicFilterBuilder().WithTopic(topicFilter).WithQualityOfServiceLevel(filterQualityOfServiceLevel).Build()); + await c2.PublishAsync(new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(new byte[0]).WithQualityOfServiceLevel(qualityOfServiceLevel).Build()); - await s.StopAsync(); + await Task.Delay(500); + await c1.UnsubscribeAsync(topicFilter); + await Task.Delay(500); + } + finally + { + await s.StopAsync(); + } + Assert.AreEqual(expectedReceivedMessagesCount, receivedMessagesCount); } } From 466b6a25cde8672c27f0b3f333692509081fe710 Mon Sep 17 00:00:00 2001 From: Jan Eggers Date: Thu, 26 Oct 2017 08:11:37 +0200 Subject: [PATCH 2/8] fixed unittests and addressed todo --- Frameworks/MQTTnet.NetStandard/MqttFactory.cs | 10 ++++ MQTTnet.Core/Server/IMqttServerFactory.cs | 6 ++- Tests/MQTTnet.Core.Tests/MqttServerTests.cs | 50 +++++++++++++++---- Tests/MQTTnet.Core.Tests/TestLogger.cs | 8 ++- 4 files changed, 61 insertions(+), 13 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/MqttFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttFactory.cs index 7d88480..0ff6136 100644 --- a/Frameworks/MQTTnet.NetStandard/MqttFactory.cs +++ b/Frameworks/MQTTnet.NetStandard/MqttFactory.cs @@ -4,6 +4,7 @@ using MQTTnet.Core.Client; using MQTTnet.Core.Serializer; using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using MQTTnet.Implementations; using MQTTnet.Core.ManagedClient; using MQTTnet.Core.Server; @@ -109,5 +110,14 @@ namespace MQTTnet { return _serviceProvider.GetRequiredService(); } + + public IMqttServer CreateMqttServer(Action configure) + { + var options = _serviceProvider.GetRequiredService>(); + + configure(options.Value); + + return _serviceProvider.GetRequiredService(); + } } } \ No newline at end of file diff --git a/MQTTnet.Core/Server/IMqttServerFactory.cs b/MQTTnet.Core/Server/IMqttServerFactory.cs index 61d022f..500614b 100644 --- a/MQTTnet.Core/Server/IMqttServerFactory.cs +++ b/MQTTnet.Core/Server/IMqttServerFactory.cs @@ -1,7 +1,11 @@ -namespace MQTTnet.Core.Server +using System; + +namespace MQTTnet.Core.Server { public interface IMqttServerFactory { IMqttServer CreateMqttServer(); + + IMqttServer CreateMqttServer(Action configure); } } \ No newline at end of file diff --git a/Tests/MQTTnet.Core.Tests/MqttServerTests.cs b/Tests/MQTTnet.Core.Tests/MqttServerTests.cs index 97aa3f8..4dd9f3a 100644 --- a/Tests/MQTTnet.Core.Tests/MqttServerTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttServerTests.cs @@ -51,7 +51,13 @@ namespace MQTTnet.Core.Tests public async Task MqttServer_WillMessage() { var serverAdapter = new TestMqttServerAdapter(); - var s = new MqttFactory().CreateMqttServer(); + var services = new ServiceCollection() + .AddLogging() + .AddMqttServer() + .AddSingleton(serverAdapter) + .BuildServiceProvider(); + + var s = new MqttFactory(services).CreateMqttServer(); var receivedMessagesCount = 0; try { @@ -79,7 +85,13 @@ namespace MQTTnet.Core.Tests public async Task MqttServer_Unsubscribe() { var serverAdapter = new TestMqttServerAdapter(); - var s = new MqttFactory().CreateMqttServer(); + var services = new ServiceCollection() + .AddLogging() + .AddMqttServer() + .AddSingleton(serverAdapter) + .BuildServiceProvider(); + + var s = new MqttFactory(services).CreateMqttServer(); var receivedMessagesCount = 0; @@ -121,7 +133,13 @@ namespace MQTTnet.Core.Tests public async Task MqttServer_Publish() { var serverAdapter = new TestMqttServerAdapter(); - var s = new MqttFactory().CreateMqttServer(); + var services = new ServiceCollection() + .AddLogging() + .AddMqttServer() + .AddSingleton(serverAdapter) + .BuildServiceProvider(); + + var s = new MqttFactory(services).CreateMqttServer(); var receivedMessagesCount = 0; try @@ -150,7 +168,13 @@ namespace MQTTnet.Core.Tests public async Task MqttServer_NoRetainedMessage() { var serverAdapter = new TestMqttServerAdapter(); - var s = new MqttFactory().CreateMqttServer(); + var services = new ServiceCollection() + .AddLogging() + .AddMqttServer() + .AddSingleton(serverAdapter) + .BuildServiceProvider(); + + var s = new MqttFactory(services).CreateMqttServer(); var receivedMessagesCount = 0; try @@ -179,7 +203,13 @@ namespace MQTTnet.Core.Tests public async Task MqttServer_RetainedMessage() { var serverAdapter = new TestMqttServerAdapter(); - var s = new MqttFactory().CreateMqttServer(); + var services = new ServiceCollection() + .AddLogging() + .AddMqttServer() + .AddSingleton(serverAdapter) + .BuildServiceProvider(); + + var s = new MqttFactory(services).CreateMqttServer(); var receivedMessagesCount = 0; try @@ -210,7 +240,7 @@ namespace MQTTnet.Core.Tests var serverAdapter = new TestMqttServerAdapter(); var services = new ServiceCollection() .AddLogging() - .AddMqttServer() // TODO: Is there maybe an easier way for the library user to set the options? + .AddMqttServer() .AddSingleton(serverAdapter) .BuildServiceProvider(); @@ -248,11 +278,11 @@ namespace MQTTnet.Core.Tests var serverAdapter = new TestMqttServerAdapter(); var services = new ServiceCollection() .AddLogging() - .AddMqttServer(options => options.Storage = storage) // TODO: Is there maybe an easier way for the library user to set the options? + .AddMqttServer() .AddSingleton(serverAdapter) .BuildServiceProvider(); - var s = new MqttFactory(services).CreateMqttServer(); // TODO: Like here? + var s = new MqttFactory(services).CreateMqttServer(options => options.Storage = storage); try { @@ -300,11 +330,11 @@ namespace MQTTnet.Core.Tests var serverAdapter = new TestMqttServerAdapter(); var services = new ServiceCollection() .AddLogging() - .AddMqttServer(options => options.ApplicationMessageInterceptor = Interceptor) + .AddMqttServer() .AddSingleton(serverAdapter) .BuildServiceProvider(); - var s = services.GetRequiredService(); + var s = new MqttFactory(services).CreateMqttServer(options => options.ApplicationMessageInterceptor = Interceptor); try { await s.StartAsync(); diff --git a/Tests/MQTTnet.Core.Tests/TestLogger.cs b/Tests/MQTTnet.Core.Tests/TestLogger.cs index ea597a6..f57c877 100644 --- a/Tests/MQTTnet.Core.Tests/TestLogger.cs +++ b/Tests/MQTTnet.Core.Tests/TestLogger.cs @@ -3,11 +3,11 @@ using System; namespace MQTTnet.Core.Tests { - public class TestLogger : ILogger + public class TestLogger : IDisposable, ILogger { public IDisposable BeginScope(TState state) { - throw new NotImplementedException(); + return this; } public bool IsEnabled(LogLevel logLevel) @@ -18,5 +18,9 @@ namespace MQTTnet.Core.Tests public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { } + + public void Dispose() + { + } } } From 0811938466a41e7e621c776605f78fe48bf587ee Mon Sep 17 00:00:00 2001 From: Jan Eggers Date: Thu, 26 Oct 2017 08:15:25 +0200 Subject: [PATCH 3/8] temp rename to fix casing --- .../MQTTnet.AspNetCorex.csproj | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Frameworks/MQTTnet.AspNetCore/MQTTnet.AspNetCorex.csproj diff --git a/Frameworks/MQTTnet.AspNetCore/MQTTnet.AspNetCorex.csproj b/Frameworks/MQTTnet.AspNetCore/MQTTnet.AspNetCorex.csproj new file mode 100644 index 0000000..5142cc1 --- /dev/null +++ b/Frameworks/MQTTnet.AspNetCore/MQTTnet.AspNetCorex.csproj @@ -0,0 +1,17 @@ + + + + netstandard2.0 + + + + + + + + + + + + + From 0e666f03166974d51fec145f41c519f794c9da2e Mon Sep 17 00:00:00 2001 From: Jan Eggers Date: Thu, 26 Oct 2017 08:18:13 +0200 Subject: [PATCH 4/8] use correct casing --- .../MQTTnet.AspNetCorex.csproj | 17 ----------------- .../ApplicationBuilderExtensions.cs | 2 +- .../MQTTnet.AspnetCore/MqttHostedServer.cs | 2 +- .../MqttWebSocketServerAdapter.cs | 2 +- .../ServiceCollectionExtensions.cs | 2 +- MQTTnet.sln | 2 +- .../MQTTnet.TestApp.AspNetCore2.csproj | 2 +- 7 files changed, 6 insertions(+), 23 deletions(-) delete mode 100644 Frameworks/MQTTnet.AspNetCore/MQTTnet.AspNetCorex.csproj diff --git a/Frameworks/MQTTnet.AspNetCore/MQTTnet.AspNetCorex.csproj b/Frameworks/MQTTnet.AspNetCore/MQTTnet.AspNetCorex.csproj deleted file mode 100644 index 5142cc1..0000000 --- a/Frameworks/MQTTnet.AspNetCore/MQTTnet.AspNetCorex.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - netstandard2.0 - - - - - - - - - - - - - diff --git a/Frameworks/MQTTnet.AspnetCore/ApplicationBuilderExtensions.cs b/Frameworks/MQTTnet.AspnetCore/ApplicationBuilderExtensions.cs index a62ecde..06ca74d 100644 --- a/Frameworks/MQTTnet.AspnetCore/ApplicationBuilderExtensions.cs +++ b/Frameworks/MQTTnet.AspnetCore/ApplicationBuilderExtensions.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using MQTTnet.Core.Server; -namespace MQTTnet.AspnetCore +namespace MQTTnet.AspNetCore { public static class ApplicationBuilderExtensions { diff --git a/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs b/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs index b5326ab..db72573 100644 --- a/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs +++ b/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Options; using MQTTnet.Core.Adapter; using MQTTnet.Core.Server; -namespace MQTTnet.AspnetCore +namespace MQTTnet.AspNetCore { public class MqttHostedServer : MqttServer, IHostedService { diff --git a/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs b/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs index abb30e3..5cd5d55 100644 --- a/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs +++ b/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs @@ -8,7 +8,7 @@ using MQTTnet.Core.Channel; using MQTTnet.Core.Server; using MQTTnet.Implementations; -namespace MQTTnet.AspnetCore +namespace MQTTnet.AspNetCore { public class MqttWebSocketServerAdapter : IMqttServerAdapter, IDisposable { diff --git a/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs b/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs index 1951368..f915ab4 100644 --- a/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs +++ b/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Hosting; using MQTTnet.Core.Adapter; using MQTTnet.Core.Server; -namespace MQTTnet.AspnetCore +namespace MQTTnet.AspNetCore { public static class ServiceCollectionExtensions { diff --git a/MQTTnet.sln b/MQTTnet.sln index 263fee0..bd0b214 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -33,7 +33,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.TestApp.NetCore", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.TestApp.AspNetCore2", "Tests\MQTTnet.TestApp.AspNetCore2\MQTTnet.TestApp.AspNetCore2.csproj", "{C6FF8AEA-0855-41EC-A1F3-AC262225BAB9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.AspnetCore", "Frameworks\MQTTnet.AspnetCore\MQTTnet.AspnetCore.csproj", "{F10C4060-F7EE-4A83-919F-FF723E72F94A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.AspNetCore", "Frameworks\MQTTnet.AspnetCore\MQTTnet.AspNetCore.csproj", "{F10C4060-F7EE-4A83-919F-FF723E72F94A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Tests/MQTTnet.TestApp.AspNetCore2/MQTTnet.TestApp.AspNetCore2.csproj b/Tests/MQTTnet.TestApp.AspNetCore2/MQTTnet.TestApp.AspNetCore2.csproj index 2f04208..7e4e0e3 100644 --- a/Tests/MQTTnet.TestApp.AspNetCore2/MQTTnet.TestApp.AspNetCore2.csproj +++ b/Tests/MQTTnet.TestApp.AspNetCore2/MQTTnet.TestApp.AspNetCore2.csproj @@ -14,7 +14,7 @@ - + From bb6eb246e812ddc84b546be8abeff31fbf2aef59 Mon Sep 17 00:00:00 2001 From: Jan Eggers Date: Thu, 26 Oct 2017 09:01:25 +0200 Subject: [PATCH 5/8] added AspNetCore to buildscript and fixed assemblyversion of dotnet build --- Build/MQTTnet.AspNetCore.nuspec | 30 ++++++++++++++++++++++++++++++ Build/MQTTnet.nuspec | 4 ++-- Build/build.ps1 | 8 +++++--- MQTTnet.sln | 1 + 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 Build/MQTTnet.AspNetCore.nuspec diff --git a/Build/MQTTnet.AspNetCore.nuspec b/Build/MQTTnet.AspNetCore.nuspec new file mode 100644 index 0000000..eb5f637 --- /dev/null +++ b/Build/MQTTnet.AspNetCore.nuspec @@ -0,0 +1,30 @@ + + + + MQTTnet.AspNetCore + 2.5.0 + Christian Kratky + Christian Kratky + https://github.com/chkr1011/MQTTnet/blob/master/LICENSE + https://github.com/chkr1011/MQTTnet + https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png + false + This is a support library to integrate MQTTnet into AspNetCore. + initial version + + Copyright Christian Kratky 2016-2017 + MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M ESP Smart Home Cities Automation + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index 2403cc8..54c4c47 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -51,8 +51,8 @@ - - + + \ No newline at end of file diff --git a/Build/build.ps1 b/Build/build.ps1 index 70b616b..5b766d6 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -3,9 +3,11 @@ param([string]$version) if ([string]::IsNullOrEmpty($version)) {$version = "0.0.1"} $msbuild = "MSBuild.exe" -&dotnet build ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj -c="Release" -&$msbuild ..\Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj /t:Build /p:Configuration="Release" +&dotnet build ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj -c="Release" /p:FileVersion=$version /p:AssemblyVersion=$version +&dotnet build ..\Frameworks\MQTTnet.AspNetCore\MQTTnet.AspNetCore.csproj -c="Release" /p:FileVersion=$version /p:AssemblyVersion=$version +##&$msbuild ..\Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj /t:Build /p:Configuration="Release" Remove-Item .\NuGet -Force -Recurse New-Item -ItemType Directory -Force -Path .\NuGet -.\NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version \ No newline at end of file +.\NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version +.\NuGet.exe pack MQTTnet.AspNetCore.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version \ No newline at end of file diff --git a/MQTTnet.sln b/MQTTnet.sln index bd0b214..aae1e6e 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -20,6 +20,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{67C28AC1-BC3A-420A-BE9C-FA2401431CF9}" ProjectSection(SolutionItems) = preProject Build\build.ps1 = Build\build.ps1 + Build\MQTTnet.AspNetCore.nuspec = Build\MQTTnet.AspNetCore.nuspec Build\MQTTnet.nuspec = Build\MQTTnet.nuspec EndProjectSection EndProject From e0797e5d14a2ffd54dc31ef05a0931fed2cfaacc Mon Sep 17 00:00:00 2001 From: JanEggers Date: Thu, 26 Oct 2017 21:45:36 +0200 Subject: [PATCH 6/8] enable uwp build again --- Build/build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build/build.ps1 b/Build/build.ps1 index 5b766d6..5e280e2 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -5,7 +5,7 @@ if ([string]::IsNullOrEmpty($version)) {$version = "0.0.1"} $msbuild = "MSBuild.exe" &dotnet build ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj -c="Release" /p:FileVersion=$version /p:AssemblyVersion=$version &dotnet build ..\Frameworks\MQTTnet.AspNetCore\MQTTnet.AspNetCore.csproj -c="Release" /p:FileVersion=$version /p:AssemblyVersion=$version -##&$msbuild ..\Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj /t:Build /p:Configuration="Release" +&$msbuild ..\Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj /t:Build /p:Configuration="Release" Remove-Item .\NuGet -Force -Recurse New-Item -ItemType Directory -Force -Path .\NuGet From dd447f24d2d5bb229bc9e3405c69af3e56ef297e Mon Sep 17 00:00:00 2001 From: Jan Eggers Date: Fri, 27 Oct 2017 12:29:13 +0200 Subject: [PATCH 7/8] added LogId to options and use it to create logging scope --- MQTTnet.Core/Client/IMqttClientOptions.cs | 5 +++++ MQTTnet.Core/Client/MqttClient.cs | 2 +- MQTTnet.Core/Client/MqttClientOptions.cs | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/MQTTnet.Core/Client/IMqttClientOptions.cs b/MQTTnet.Core/Client/IMqttClientOptions.cs index d2bcf9d..ae77192 100644 --- a/MQTTnet.Core/Client/IMqttClientOptions.cs +++ b/MQTTnet.Core/Client/IMqttClientOptions.cs @@ -6,6 +6,11 @@ namespace MQTTnet.Core.Client public interface IMqttClientOptions { string ClientId { get; } + + /// + /// The LogId is used to create a scope to correlate logging. If no value is provided the ClientId is used instead + /// + string LogId { get; } IMqttClientCredentials Credentials { get; } bool CleanSession { get; } MqttApplicationMessage WillMessage { get; } diff --git a/MQTTnet.Core/Client/MqttClient.cs b/MQTTnet.Core/Client/MqttClient.cs index b54288c..a52ca13 100644 --- a/MQTTnet.Core/Client/MqttClient.cs +++ b/MQTTnet.Core/Client/MqttClient.cs @@ -55,7 +55,7 @@ namespace MQTTnet.Core.Client _adapter = _communicationAdapterFactory.CreateClientMqttCommunicationAdapter(options); - _scopeHandle = _logger.BeginScope(options.ClientId); + _scopeHandle = _logger.BeginScope(options.LogId ?? options.ClientId); _logger.LogTrace("Trying to connect with server."); await _adapter.ConnectAsync(_options.CommunicationTimeout).ConfigureAwait(false); _logger.LogTrace("Connection with server established."); diff --git a/MQTTnet.Core/Client/MqttClientOptions.cs b/MQTTnet.Core/Client/MqttClientOptions.cs index 04cf8bd..1b1c1bb 100644 --- a/MQTTnet.Core/Client/MqttClientOptions.cs +++ b/MQTTnet.Core/Client/MqttClientOptions.cs @@ -9,6 +9,9 @@ namespace MQTTnet.Core.Client public string ClientId { get; set; } = Guid.NewGuid().ToString("N"); + /// + public string LogId { get; set; } + public bool CleanSession { get; set; } = true; public IMqttClientCredentials Credentials { get; set; } = new MqttClientCredentials(); From 9894dbef8796ebe5e2af79cbc80dd00ae0250331 Mon Sep 17 00:00:00 2001 From: Jan Eggers Date: Fri, 27 Oct 2017 12:29:26 +0200 Subject: [PATCH 8/8] fixed using --- Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs b/Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs index c5da4e5..18d121c 100644 --- a/Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs +++ b/Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Logging; -using MQTTnet.AspnetCore; +using MQTTnet.AspNetCore; using MQTTnet.Core; using MQTTnet.Core.Client;