Kaynağa Gözat

Merge pull request #90 from JanEggers/develop

added dependencies to nuspec and fixed build
release/3.x.x
Christian 7 yıl önce
committed by GitHub
ebeveyn
işleme
6e5b991406
Veri tabanında bu imza için bilinen anahtar bulunamadı GPG Anahtar Kimliği: 4AEE18F83AFDEB23
11 değiştirilmiş dosya ile 80 ekleme ve 17 silme
  1. +15
    -0
      Build/MQTTnet.nuspec
  2. +1
    -1
      Build/build.ps1
  3. +8
    -2
      Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs
  4. +3
    -1
      Frameworks/MQTTnet.NetStandard/MqttFactory.cs
  5. +2
    -2
      Frameworks/MQTTnet.NetStandard/ServiceCollectionExtensions.cs
  6. +15
    -0
      MQTTnet.Core/Server/IMqttClientRetainedMessageManager.cs
  7. +1
    -1
      MQTTnet.Core/Server/MqttClientRetainedMessagesManager.cs
  8. +7
    -4
      MQTTnet.Core/Server/MqttClientSession.cs
  9. +0
    -4
      MQTTnet.Core/Server/MqttClientSessionsManager.cs
  10. +11
    -2
      MQTTnet.Core/Server/MqttServer.cs
  11. +17
    -0
      Tests/MQTTnet.Core.Tests/MqttServerTests.cs

+ 15
- 0
Build/MQTTnet.nuspec Dosyayı Görüntüle

@@ -33,11 +33,26 @@

<group targetFramework="netstandard1.3">
<dependency id="NETStandard.Library" version="1.6.1" />
<dependency id="Microsoft.Extensions.DependencyInjection" version="1.1.1" />
<dependency id="Microsoft.Extensions.Logging" version="1.1.2" />
<dependency id="Microsoft.Extensions.Options" version="1.1.2" />
<dependency id="System.Net.Security" version="4.3.2" />
<dependency id="System.Net.WebSockets" version="4.3.0" />
<dependency id="System.Net.WebSockets.Client" version="4.3.1" />
<dependency id="System.Threading.Thread" version="4.3.0" />
</group>
<group targetFramework="uap10.0">
<dependency id="Microsoft.NETCore.UniversalWindowsPlatform" version="5.4.0" />
<dependency id="Microsoft.Extensions.DependencyInjection" version="1.1.1" />
<dependency id="Microsoft.Extensions.Logging" version="1.1.2" />
<dependency id="Microsoft.Extensions.Options" version="1.1.2" />
</group>
<group targetFramework="net451">
<dependency id="Microsoft.Extensions.DependencyInjection" version="1.1.1" />
<dependency id="Microsoft.Extensions.Logging" version="1.1.2" />
<dependency id="Microsoft.Extensions.Options" version="1.1.2" />
</group>

</dependencies>


+ 1
- 1
Build/build.ps1 Dosyayı Görüntüle

@@ -11,7 +11,7 @@ if ($path) {
&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="net451" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m
&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard1.3" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m
&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="uap10.0" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m
&dotnet build ..\Frameworks\MQTTnet.AspNetCore\MQTTnet.AspNetCore.csproj -c="Release" /p:FileVersion=$version /p:AssemblyVersion=$version
&$msbuild ..\Frameworks\MQTTnet.AspNetCore\MQTTnet.AspNetCore.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard2.0" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m

Remove-Item .\NuGet -Force -Recurse
New-Item -ItemType Directory -Force -Path .\NuGet


+ 8
- 2
Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs Dosyayı Görüntüle

@@ -11,8 +11,14 @@ namespace MQTTnet.AspNetCore
{
public class MqttHostedServer : MqttServer, IHostedService
{
public MqttHostedServer(IOptions<MqttServerOptions> options, IEnumerable<IMqttServerAdapter> adapters, ILogger<MqttServer> logger, MqttClientSessionsManager clientSessionsManager)
: base(options, adapters, logger, clientSessionsManager)
public MqttHostedServer(
IOptions<MqttServerOptions> options,
IEnumerable<IMqttServerAdapter> adapters,
ILogger<MqttServer> logger,
MqttClientSessionsManager clientSessionsManager,
IMqttClientRetainedMessageManager clientRetainedMessageManager
)
: base(options, adapters, logger, clientSessionsManager, clientRetainedMessageManager)
{
}



+ 3
- 1
Frameworks/MQTTnet.NetStandard/MqttFactory.cs Dosyayı Görüntüle

@@ -99,7 +99,9 @@ namespace MQTTnet
clientSessionsManager,
_serviceProvider.GetRequiredService<MqttClientSubscriptionsManager>(),
_serviceProvider.GetRequiredService<ILogger<MqttClientSession>>(),
_serviceProvider.GetRequiredService<ILogger<MqttClientPendingMessagesQueue>>());
_serviceProvider.GetRequiredService<ILogger<MqttClientPendingMessagesQueue>>(),
_serviceProvider.GetRequiredService<IMqttClientRetainedMessageManager>()
);
}

public IMqttClient CreateMqttClient()


+ 2
- 2
Frameworks/MQTTnet.NetStandard/ServiceCollectionExtensions.cs Dosyayı Görüntüle

@@ -33,9 +33,9 @@ namespace MQTTnet
services.AddTransient<IMqttServerAdapter, MqttServerAdapter>();
services.AddTransient<IMqttPacketSerializer, MqttPacketSerializer>();

services.AddTransient<MqttClientSessionsManager>();
services.AddSingleton<MqttClientSessionsManager>();
services.AddTransient<MqttClientSubscriptionsManager>();
services.AddTransient<MqttClientRetainedMessagesManager>();
services.AddSingleton<IMqttClientRetainedMessageManager, MqttClientRetainedMessagesManager>();
return services;
}



+ 15
- 0
MQTTnet.Core/Server/IMqttClientRetainedMessageManager.cs Dosyayı Görüntüle

@@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using MQTTnet.Core.Packets;

namespace MQTTnet.Core.Server
{
public interface IMqttClientRetainedMessageManager
{
Task LoadMessagesAsync();

Task HandleMessageAsync(string clientId, MqttApplicationMessage applicationMessage);

List<MqttApplicationMessage> GetMessages(MqttSubscribePacket subscribePacket);
}
}

+ 1
- 1
MQTTnet.Core/Server/MqttClientRetainedMessagesManager.cs Dosyayı Görüntüle

@@ -8,7 +8,7 @@ using Microsoft.Extensions.Options;

namespace MQTTnet.Core.Server
{
public sealed class MqttClientRetainedMessagesManager
public sealed class MqttClientRetainedMessagesManager : IMqttClientRetainedMessageManager
{
private readonly Dictionary<string, MqttApplicationMessage> _retainedMessages = new Dictionary<string, MqttApplicationMessage>();
private readonly ILogger<MqttClientRetainedMessagesManager> _logger;


+ 7
- 4
MQTTnet.Core/Server/MqttClientSession.cs Dosyayı Görüntüle

@@ -15,6 +15,7 @@ namespace MQTTnet.Core.Server
{
public sealed class MqttClientSession : IDisposable
{
private readonly IMqttClientRetainedMessageManager _clientRetainedMessageManager;
private readonly HashSet<ushort> _unacknowledgedPublishPackets = new HashSet<ushort>();

private readonly MqttClientSubscriptionsManager _subscriptionsManager;
@@ -33,10 +34,12 @@ namespace MQTTnet.Core.Server
MqttClientSessionsManager sessionsManager,
MqttClientSubscriptionsManager subscriptionsManager,
ILogger<MqttClientSession> logger,
ILogger<MqttClientPendingMessagesQueue> messageQueueLogger)
ILogger<MqttClientPendingMessagesQueue> messageQueueLogger,
IMqttClientRetainedMessageManager clientRetainedMessageManager)
{
_clientRetainedMessageManager = clientRetainedMessageManager ?? throw new ArgumentNullException(nameof(clientRetainedMessageManager));
_sessionsManager = sessionsManager ?? throw new ArgumentNullException(nameof(sessionsManager));
_subscriptionsManager = subscriptionsManager ?? throw new ArgumentNullException(nameof(sessionsManager));
_subscriptionsManager = subscriptionsManager ?? throw new ArgumentNullException(nameof(subscriptionsManager));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));

ClientId = clientId;
@@ -206,7 +209,7 @@ namespace MQTTnet.Core.Server

private void EnqueueRetainedMessages(MqttSubscribePacket subscribePacket)
{
var retainedMessages = _sessionsManager.RetainedMessagesManager.GetMessages(subscribePacket);
var retainedMessages = _clientRetainedMessageManager.GetMessages(subscribePacket);
foreach (var publishPacket in retainedMessages)
{
EnqueuePublishPacket(publishPacket.ToPublishPacket());
@@ -227,7 +230,7 @@ namespace MQTTnet.Core.Server

if (applicationMessage.Retain)
{
await _sessionsManager.RetainedMessagesManager.HandleMessageAsync(ClientId, applicationMessage);
await _clientRetainedMessageManager.HandleMessageAsync(ClientId, applicationMessage);
}

switch (applicationMessage.QualityOfServiceLevel)


+ 0
- 4
MQTTnet.Core/Server/MqttClientSessionsManager.cs Dosyayı Görüntüle

@@ -24,12 +24,10 @@ namespace MQTTnet.Core.Server
public MqttClientSessionsManager(
IOptions<MqttServerOptions> options,
ILogger<MqttClientSessionsManager> logger,
MqttClientRetainedMessagesManager retainedMessagesManager,
IMqttClientSesssionFactory clientSesssionFactory)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_options = options.Value ?? throw new ArgumentNullException(nameof(options));
RetainedMessagesManager = retainedMessagesManager ?? throw new ArgumentNullException(nameof(options));
_clientSesssionFactory = clientSesssionFactory ?? throw new ArgumentNullException(nameof(clientSesssionFactory));
}

@@ -37,8 +35,6 @@ namespace MQTTnet.Core.Server
public event EventHandler<MqttClientDisconnectedEventArgs> ClientDisconnected;
public event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;

public MqttClientRetainedMessagesManager RetainedMessagesManager { get; }

public async Task RunClientSessionAsync(IMqttCommunicationAdapter clientAdapter, CancellationToken cancellationToken)
{
var clientId = string.Empty;


+ 11
- 2
MQTTnet.Core/Server/MqttServer.cs Dosyayı Görüntüle

@@ -6,11 +6,13 @@ using MQTTnet.Core.Adapter;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;

namespace MQTTnet.Core.Server
{
public class MqttServer : IMqttServer
{
private readonly IMqttClientRetainedMessageManager _clientRetainedMessageManager;
private readonly ILogger<MqttServer> _logger;
private readonly MqttClientSessionsManager _clientSessionsManager;
private readonly ICollection<IMqttServerAdapter> _adapters;
@@ -18,11 +20,18 @@ namespace MQTTnet.Core.Server

private CancellationTokenSource _cancellationTokenSource;

public MqttServer(IOptions<MqttServerOptions> options, IEnumerable<IMqttServerAdapter> adapters, ILogger<MqttServer> logger, MqttClientSessionsManager clientSessionsManager)
public MqttServer(
IOptions<MqttServerOptions> options,
IEnumerable<IMqttServerAdapter> adapters,
ILogger<MqttServer> logger,
MqttClientSessionsManager clientSessionsManager,
IMqttClientRetainedMessageManager clientRetainedMessageManager
)
{
_options = options.Value ?? throw new ArgumentNullException(nameof(options));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_clientSessionsManager = clientSessionsManager ?? throw new ArgumentNullException(nameof(clientSessionsManager));
_clientRetainedMessageManager = clientRetainedMessageManager ?? throw new ArgumentNullException(nameof(clientRetainedMessageManager));

if (adapters == null)
{
@@ -79,7 +88,7 @@ namespace MQTTnet.Core.Server

_cancellationTokenSource = new CancellationTokenSource();

await _clientSessionsManager.RetainedMessagesManager.LoadMessagesAsync();
await _clientRetainedMessageManager.LoadMessagesAsync();

foreach (var adapter in _adapters)
{


+ 17
- 0
Tests/MQTTnet.Core.Tests/MqttServerTests.cs Dosyayı Görüntüle

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -8,6 +9,7 @@ using MQTTnet.Core.Client;
using MQTTnet.Core.Protocol;
using MQTTnet.Core.Server;
using Microsoft.Extensions.DependencyInjection;
using MQTTnet.Core.Packets;

namespace MQTTnet.Core.Tests
{
@@ -210,6 +212,7 @@ namespace MQTTnet.Core.Tests
.BuildServiceProvider();

var s = new MqttFactory(services).CreateMqttServer();
var retainMessagemanager = services.GetRequiredService<IMqttClientRetainedMessageManager>();

var receivedMessagesCount = 0;
try
@@ -220,6 +223,20 @@ namespace MQTTnet.Core.Tests
await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).WithRetainFlag().Build());
await c1.DisconnectAsync();

var subscribe = new MqttSubscribePacket()
{
TopicFilters = new List<TopicFilter>()
{
new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce)
}
};

//make shure the retainedMessageManagerreceived the package
while (!retainMessagemanager.GetMessages(subscribe).Any())
{
await Task.Delay(TimeSpan.FromMilliseconds(10));
}

var c2 = await serverAdapter.ConnectTestClient(s, "c2");
c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++;
await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce));


Yükleniyor…
İptal
Kaydet