mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 03:24:33 +08:00
Server refactoring
This commit is contained in:
@@ -65,7 +65,6 @@
|
||||
<Button Click="Publish" Width="120">Publish</Button>
|
||||
</StackPanel>
|
||||
</PivotItem>
|
||||
|
||||
<PivotItem Header="Subscribe">
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<TextBlock>Topic:</TextBlock>
|
||||
@@ -84,6 +83,12 @@
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</PivotItem>
|
||||
<PivotItem Header="Server">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Width="120" Margin="0,0,10,0" Click="StartServer">Start</Button>
|
||||
<Button Width="120" Margin="0,0,10,0" Click="StopServer">Stop</Button>
|
||||
</StackPanel>
|
||||
</PivotItem>
|
||||
</Pivot>
|
||||
|
||||
<ScrollViewer Margin="12,10,12,0" Grid.Row="1" Background="Black" Foreground="WhiteSmoke" FontFamily="Consolas" HorizontalScrollMode="Enabled" VerticalScrollMode="Enabled" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
|
||||
|
||||
@@ -9,6 +9,7 @@ using MQTTnet.Core;
|
||||
using MQTTnet.Core.Client;
|
||||
using MQTTnet.Core.Diagnostics;
|
||||
using MQTTnet.Core.Protocol;
|
||||
using MQTTnet.Core.Server;
|
||||
using MQTTnet.Implementations;
|
||||
|
||||
namespace MQTTnet.TestApp.UniversalWindows
|
||||
@@ -16,6 +17,7 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
public sealed partial class MainPage
|
||||
{
|
||||
private IMqttClient _mqttClient;
|
||||
private IMqttServer _mqttServer;
|
||||
|
||||
public MainPage()
|
||||
{
|
||||
@@ -319,5 +321,27 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private async void StartServer(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_mqttServer != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_mqttServer = new MqttFactory().CreateMqttServer();
|
||||
await _mqttServer.StartAsync();
|
||||
}
|
||||
|
||||
private async void StopServer(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_mqttServer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await _mqttServer.StopAsync();
|
||||
_mqttServer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user