Christian Kratky пре 7 година
родитељ
комит
587622af81
2 измењених фајлова са 30 додато и 14 уклоњено
  1. +14
    -14
      Frameworks/MQTTnet.NetStandard/MqttFactory.cs
  2. +16
    -0
      Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs

+ 14
- 14
Frameworks/MQTTnet.NetStandard/MqttFactory.cs Прегледај датотеку

@@ -16,20 +16,6 @@ namespace MQTTnet
{
private readonly IServiceProvider _serviceProvider;

private static IServiceProvider BuildServiceProvider()
{
var serviceProvider = new ServiceCollection()
.AddMqttClient()
.AddMqttServer()
.AddLogging()
.BuildServiceProvider();

serviceProvider.GetRequiredService<ILoggerFactory>()
.AddMqttTrace();

return serviceProvider;
}

public MqttFactory()
: this(BuildServiceProvider())
{
@@ -128,5 +114,19 @@ namespace MQTTnet

return _serviceProvider.GetRequiredService<IMqttServer>();
}

private static IServiceProvider BuildServiceProvider()
{
var serviceProvider = new ServiceCollection()
.AddMqttClient()
.AddMqttServer()
.AddLogging()
.BuildServiceProvider();

serviceProvider.GetRequiredService<ILoggerFactory>()
.AddMqttTrace();

return serviceProvider;
}
}
}

+ 16
- 0
Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs Прегледај датотеку

@@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging;
using MQTTnet.Core;
using MQTTnet.Core.Client;
using MQTTnet.Core.Diagnostics;
using MQTTnet.Core.ManagedClient;
using MQTTnet.Core.Protocol;
using MQTTnet.Core.Server;
using MQTTnet.Implementations;
@@ -454,6 +455,21 @@ namespace MQTTnet.TestApp.UniversalWindows
var mqttServer = new MqttFactory().CreateMqttServer();
}

{
// Setup and start a managed MQTT client.
var options = new ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
.WithClientOptions(new MqttClientOptionsBuilder()
.WithClientId("Client1")
.WithTcpServer("broker.hivemq.com")
.WithTls().Build())
.Build();

var mqttClient = new MqttFactory().CreateManagedMqttClient();
await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic("my/topic").Build());
await mqttClient.StartAsync(options);
}

}

private async void StartServer(object sender, RoutedEventArgs e)


Loading…
Откажи
Сачувај