ソースを参照

Update documentation

release/3.x.x
Christian Kratky 7年前
コミット
eaf27c1e12
5個のファイルの変更84行の追加11行の削除
  1. +0
    -1
      MQTTnet.Core/Server/IMqttServer.cs
  2. +0
    -1
      MQTTnet.Core/Server/MqttServer.cs
  3. +6
    -4
      Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs
  4. +19
    -4
      Tests/MQTTnet.TestApp.NetCore/ServerTest.cs
  5. +59
    -1
      Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs

+ 0
- 1
MQTTnet.Core/Server/IMqttServer.cs ファイルの表示

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MQTTnet.Core.Client;

namespace MQTTnet.Core.Server
{


+ 0
- 1
MQTTnet.Core/Server/MqttServer.cs ファイルの表示

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

namespace MQTTnet.Core.Server
{


+ 6
- 4
Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs ファイルの表示

@@ -8,17 +8,19 @@ using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using MQTTnet.AspNetCore;
using MQTTnet.Core;
using MQTTnet.Core.Client;

namespace MQTTnet.TestApp.AspNetCore2
{
public class Startup
{
// In class _Startup_ of the ASP.NET Core 2.0 project.

public void ConfigureServices(IServiceCollection services)
{
services.AddHostedMqttServer();
}

// In class _Startup_ of the ASP.NET Core 2.0 project.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseMqttEndpoint();
@@ -49,11 +51,11 @@ namespace MQTTnet.TestApp.AspNetCore2
app.UseStaticFiles();


app.UseStaticFiles( new StaticFileOptions()
app.UseStaticFiles(new StaticFileOptions
{
RequestPath = "/node_modules",
FileProvider = new PhysicalFileProvider( Path.Combine(env.ContentRootPath, "node_modules" ) )
} );
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "node_modules"))
});
}
}
}

+ 19
- 4
Tests/MQTTnet.TestApp.NetCore/ServerTest.cs ファイルの表示

@@ -35,14 +35,29 @@ namespace MQTTnet.TestApp.NetCore

options.Storage = new RetainedMessageHandler();

// Extend the timestamp for all messages from clients.
options.ApplicationMessageInterceptor = context =>
{
if (MqttTopicFilterComparer.IsMatch(context.ApplicationMessage.Topic, "/myTopic/WithTimestamp/#"))
{
// Replace the payload with the timestamp. But also extending a JSON
// based payload with the timestamp is a suitable use case.
context.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(DateTime.Now.ToString("O"));
}
// Replace the payload with the timestamp. But also extending a JSON
// based payload with the timestamp is a suitable use case.
context.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(DateTime.Now.ToString("O"));
}
};
// Protect several topics from being subscribed from every client.
options.SubscriptionsInterceptor = context =>
{
if (context.TopicFilter.Topic.StartsWith("admin/foo/bar") && context.ClientId != "theAdmin")
{
context.AcceptSubscription = false;
}

if (context.TopicFilter.Topic.StartsWith("the/secret/stuff") && context.ClientId != "Imperator")
{
context.AcceptSubscription = false;
context.CloseConnection = true;
}
};
});



+ 59
- 1
Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs ファイルの表示

@@ -264,7 +264,7 @@ namespace MQTTnet.TestApp.UniversalWindows

var mqttClient = serviceProvider.GetRequiredService<IMqttClient>();
}
{
// Create a new MQTT client.
var factory = new MqttFactory();
@@ -396,6 +396,64 @@ namespace MQTTnet.TestApp.UniversalWindows
return new ChainValidationResult[0];
};

{
// Start a MQTT server.
var mqttServer = new MqttFactory().CreateMqttServer();
await mqttServer.StartAsync();
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
await mqttServer.StopAsync();
}

{
// Configure MQTT server.
var mqttServer = new MqttFactory().CreateMqttServer(options =>
{
options.ConnectionBacklog = 100;
options.DefaultEndpointOptions.Port = 1884;
options.ConnectionValidator = packet =>
{
if (packet.ClientId != "Highlander")
{
return MqttConnectReturnCode.ConnectionRefusedIdentifierRejected;
}

return MqttConnectReturnCode.ConnectionAccepted;
};
});
}

{
// Setup client validator.
var mqttServer = new MqttFactory().CreateMqttServer(options =>
{
options.ConnectionValidator = c =>
{
if (c.ClientId.Length < 10)
{
return MqttConnectReturnCode.ConnectionRefusedIdentifierRejected;
}

if (c.Username != "mySecretUser")
{
return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
}

if (c.Password != "mySecretPassword")
{
return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
}

return MqttConnectReturnCode.ConnectionAccepted;
};
});
}

{
// Create a new MQTT server.
var mqttServer = new MqttFactory().CreateMqttServer();
}

}

private async void StartServer(object sender, RoutedEventArgs e)


読み込み中…
キャンセル
保存