Procházet zdrojové kódy

Update documentation

release/3.x.x
Christian Kratky před 7 roky
rodič
revize
1c78cd4c31
3 změnil soubory, kde provedl 90 přidání a 19 odebrání
  1. +16
    -10
      MQTTnet.Core/Client/MqttClientOptionsBuilder.cs
  2. +6
    -0
      Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj
  3. +68
    -9
      Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs

+ 16
- 10
MQTTnet.Core/Client/MqttClientOptionsBuilder.cs Zobrazit soubor

@@ -12,15 +12,21 @@ namespace MQTTnet.Core.Client

private MqttClientTlsOptions _tlsOptions;

public MqttClientOptionsBuilder WithProtocolVersion(MqttProtocolVersion protocolVersion)
public MqttClientOptionsBuilder WithLogId(string value)
{
_options.ProtocolVersion = protocolVersion;
_options.LogId = value;
return this;
}

public MqttClientOptionsBuilder WithCommunicationTimeout(TimeSpan communicationTimeout)
public MqttClientOptionsBuilder WithProtocolVersion(MqttProtocolVersion value)
{
_options.CommunicationTimeout = communicationTimeout;
_options.ProtocolVersion = value;
return this;
}

public MqttClientOptionsBuilder WithCommunicationTimeout(TimeSpan value)
{
_options.CommunicationTimeout = value;
return this;
}

@@ -30,21 +36,21 @@ namespace MQTTnet.Core.Client
return this;
}

public MqttClientOptionsBuilder WithKeepAlivePeriod(TimeSpan keepAlivePeriod)
public MqttClientOptionsBuilder WithKeepAlivePeriod(TimeSpan value)
{
_options.KeepAlivePeriod = keepAlivePeriod;
_options.KeepAlivePeriod = value;
return this;
}

public MqttClientOptionsBuilder WithClientId(string clientId)
public MqttClientOptionsBuilder WithClientId(string value)
{
_options.ClientId = clientId;
_options.ClientId = value;
return this;
}

public MqttClientOptionsBuilder WithWillMessage(MqttApplicationMessage applicationMessage)
public MqttClientOptionsBuilder WithWillMessage(MqttApplicationMessage value)
{
_options.WillMessage = applicationMessage;
_options.WillMessage = value;
return this;
}



+ 6
- 0
Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj Zobrazit soubor

@@ -137,6 +137,12 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging">
<Version>1.1.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Console">
<Version>1.1.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>5.4.0</Version>
</PackageReference>


+ 68
- 9
Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs Zobrazit soubor

@@ -5,6 +5,7 @@ using Windows.Security.Cryptography.Certificates;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MQTTnet.Core;
using MQTTnet.Core.Client;
using MQTTnet.Core.Diagnostics;
@@ -111,7 +112,7 @@ namespace MQTTnet.TestApp.UniversalWindows
{
ReceivedMessages.Items.Add(item);
});
}

private async void Publish(object sender, RoutedEventArgs e)
@@ -227,16 +228,50 @@ namespace MQTTnet.TestApp.UniversalWindows
private async Task WikiCode()
{
{
// Create a new MQTT client
// Write all trace messages to the console window.
MqttNetTrace.TraceMessagePublished += (s, e) =>
{
Console.WriteLine($">> [{e.TraceMessage.Timestamp:O}] [{e.TraceMessage.ThreadId}] [{e.TraceMessage.Source}] [{e.TraceMessage.Level}]: {e.TraceMessage.Message}");
if (e.TraceMessage.Exception != null)
{
Console.WriteLine(e.TraceMessage.Exception);
}
};
}

{
// Add the console logger to the logger factory.
var services = new ServiceCollection()
.AddMqttClient()
.BuildServiceProvider();

var factory = new MqttFactory(services);
var client = factory.CreateMqttClient();
services.GetRequiredService<ILoggerFactory>()
.AddConsole();
}

{
// Use a custom identifier for the trace messages.
var clientOptions = new MqttClientOptionsBuilder()
.WithLogId("ClientX")
.Build();
}

{
// Create a client from the service provider manually.
var serviceProvider = new ServiceCollection()
.AddMqttClient()
.BuildServiceProvider();

var mqttClient = serviceProvider.GetRequiredService<IMqttClient>();
}
{
// Create a new MQTT client.
var factory = new MqttFactory();
var mqttClient = factory.CreateMqttClient();

{
// Create TCP based options using the builder
// Create TCP based options using the builder.
var options = new MqttClientOptionsBuilder()
.WithClientId("Client1")
.WithTcpServer("broker.hivemq.com")
@@ -245,7 +280,31 @@ namespace MQTTnet.TestApp.UniversalWindows
.WithCleanSession()
.Build();

await client.ConnectAsync(options);
await mqttClient.ConnectAsync(options);
}

{
// Use TCP connection.
var options = new MqttClientOptionsBuilder()
.WithTcpServer("broker.hivemq.com", 1883) // Port is optional
.Build();
}

{
// Use secure TCP connection.
var options = new MqttClientOptionsBuilder()
.WithTcpServer("broker.hivemq.com")
.WithTls()
.Build();
}

{
// Use WebSocket connection.
var options = new MqttClientOptionsBuilder()
.WithWebSocketServer("broker.hivemq.com:8000/mqtt")
.Build();

await mqttClient.ConnectAsync(options);
}

{
@@ -271,10 +330,10 @@ namespace MQTTnet.TestApp.UniversalWindows

{
// Subscribe to a topic
await client.SubscribeAsync(new TopicFilterBuilder().WithTopic("my/topic").Build());
await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic("my/topic").Build());

// Unsubscribe from a topic
await client.UnsubscribeAsync("my/topic");
await mqttClient.UnsubscribeAsync("my/topic");

// Publish an application message
var applicationMessage = new MqttApplicationMessageBuilder()
@@ -283,7 +342,7 @@ namespace MQTTnet.TestApp.UniversalWindows
.WithAtLeastOnceQoS()
.Build();

await client.PublishAsync(applicationMessage);
await mqttClient.PublishAsync(applicationMessage);
}
}



Načítá se…
Zrušit
Uložit