@@ -2,7 +2,5 @@ | |||||
x:Class="MQTTnet.TestApp.UniversalWindows.App" | x:Class="MQTTnet.TestApp.UniversalWindows.App" | ||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||||
xmlns:local="using:MQTTnet.TestApp.UniversalWindows" | |||||
RequestedTheme="Light"> | RequestedTheme="Light"> | ||||
</Application> | </Application> |
@@ -137,7 +137,10 @@ | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform"> | <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform"> | ||||
<Version>5.3.3</Version> | |||||
<Version>5.4.0</Version> | |||||
</PackageReference> | |||||
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls"> | |||||
<Version>2.0.0</Version> | |||||
</PackageReference> | </PackageReference> | ||||
</ItemGroup> | </ItemGroup> | ||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' "> | <PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' "> | ||||
@@ -2,9 +2,10 @@ | |||||
x:Class="MQTTnet.TestApp.UniversalWindows.MainPage" | x:Class="MQTTnet.TestApp.UniversalWindows.MainPage" | ||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||||
xmlns:local="using:MQTTnet.TestApp.UniversalWindows" | |||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||||
d:DesignHeight="800" | |||||
d:DesignWidth="800" | |||||
mc:Ignorable="d"> | mc:Ignorable="d"> | ||||
<Grid Margin="10"> | <Grid Margin="10"> | ||||
@@ -12,33 +13,86 @@ | |||||
<Grid.RowDefinitions> | <Grid.RowDefinitions> | ||||
<RowDefinition Height="Auto" /> | <RowDefinition Height="Auto" /> | ||||
<RowDefinition Height="*" /> | <RowDefinition Height="*" /> | ||||
<RowDefinition Height="Auto" /> | |||||
</Grid.RowDefinitions> | </Grid.RowDefinitions> | ||||
<StackPanel Grid.Row="0" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | |||||
<TextBlock>Server:</TextBlock> | |||||
<TextBox x:Name="Server"></TextBox> | |||||
<TextBlock>User:</TextBlock> | |||||
<TextBox x:Name="User"></TextBox> | |||||
<TextBlock>Password:</TextBlock> | |||||
<TextBox x:Name="Password"></TextBox> | |||||
<TextBlock>ClientId:</TextBlock> | |||||
<TextBox x:Name="ClientId"></TextBox> | |||||
<StackPanel Orientation="Horizontal"> | |||||
<RadioButton x:Name="UseTcp" IsChecked="True">TCP</RadioButton> | |||||
<RadioButton x:Name="UseWs" >WS</RadioButton> | |||||
</StackPanel> | |||||
<CheckBox x:Name="UseTls">Use TLS</CheckBox> | |||||
<Button Click="Connect">Connect</Button> | |||||
<TextBlock>Trace:</TextBlock> | |||||
</StackPanel> | |||||
<Pivot Grid.Row="0" > | |||||
<PivotItem Header="Connection"> | |||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | |||||
<TextBlock>Server:</TextBlock> | |||||
<TextBox x:Name="Server"></TextBox> | |||||
<TextBlock>User:</TextBlock> | |||||
<TextBox x:Name="User"></TextBox> | |||||
<TextBlock>Password:</TextBlock> | |||||
<TextBox x:Name="Password"></TextBox> | |||||
<TextBlock>ClientId:</TextBlock> | |||||
<TextBox x:Name="ClientId"></TextBox> | |||||
<StackPanel Orientation="Horizontal"> | |||||
<RadioButton x:Name="UseTcp" IsChecked="True" GroupName="connection">TCP</RadioButton> | |||||
<RadioButton x:Name="UseWs" GroupName="connection">WS</RadioButton> | |||||
<CheckBox x:Name="UseTls">Use TLS</CheckBox> | |||||
</StackPanel> | |||||
<StackPanel Orientation="Horizontal"> | |||||
<Button Click="Connect" Width="120" Margin="0,0,10,0">Connect</Button> | |||||
<Button Click="Disconnect" Width="120">Disconnect</Button> | |||||
</StackPanel> | |||||
</StackPanel> | |||||
</PivotItem> | |||||
<PivotItem Header="Publish"> | |||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | |||||
<TextBlock>Topic:</TextBlock> | |||||
<TextBox x:Name="Topic"></TextBox> | |||||
<TextBlock>Payload:</TextBlock> | |||||
<TextBox x:Name="Payload"></TextBox> | |||||
<StackPanel Orientation="Horizontal"> | |||||
<RadioButton x:Name="Text" IsChecked="True" GroupName="payload">Text</RadioButton> | |||||
<RadioButton x:Name="Base64" GroupName="payload">Base64</RadioButton> | |||||
</StackPanel> | |||||
<TextBlock>Retain:</TextBlock> | |||||
<CheckBox x:Name="Retain"></CheckBox> | |||||
<ScrollViewer Grid.Row="1" Background="Black" Foreground="WhiteSmoke" FontFamily="Consolas" HorizontalScrollMode="Enabled" VerticalScrollMode="Enabled" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"> | |||||
<TextBlock x:Name="Trace"></TextBlock> | |||||
<TextBlock>QoS:</TextBlock> | |||||
<StackPanel Orientation="Horizontal"> | |||||
<RadioButton Margin="0,0,10,0" x:Name="QoS0" IsChecked="True" GroupName="qos">0 (At most once)</RadioButton> | |||||
<RadioButton Margin="0,0,10,0" x:Name="QoS1" GroupName="qos">1 (At least once)</RadioButton> | |||||
<RadioButton Margin="0,0,10,0" x:Name="QoS2" GroupName="qos">2 (Exactly once)</RadioButton> | |||||
</StackPanel> | |||||
<Button Click="Publish" Width="120">Publish</Button> | |||||
</StackPanel> | |||||
</PivotItem> | |||||
<PivotItem Header="Subscribe"> | |||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | |||||
<TextBlock>Topic:</TextBlock> | |||||
<TextBox x:Name="SubscribeTopic"></TextBox> | |||||
<TextBlock>QoS:</TextBlock> | |||||
<StackPanel Orientation="Horizontal"> | |||||
<RadioButton Margin="0,0,10,0" x:Name="SubscribeQoS0" IsChecked="True" GroupName="sqos">0 (At most once)</RadioButton> | |||||
<RadioButton Margin="0,0,10,0" x:Name="SubscribeQoS1" GroupName="sqos">1 (At least once)</RadioButton> | |||||
<RadioButton Margin="0,0,10,0" x:Name="SubscribeQoS2" GroupName="sqos">2 (Exactly once)</RadioButton> | |||||
</StackPanel> | |||||
<StackPanel Orientation="Horizontal"> | |||||
<Button Click="Subscribe" Width="120" Margin="0,0,10,0">Subscribe</Button> | |||||
<Button Click="Unsubscribe" Width="120">Unsubscribe</Button> | |||||
</StackPanel> | |||||
</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"> | |||||
<TextBlock x:Name="Trace" FontSize="11"></TextBlock> | |||||
</ScrollViewer> | </ScrollViewer> | ||||
<StackPanel Margin="12,0,12,10" Grid.Row="2"> | |||||
<Button Click="Clear" Width="120">Clear</Button> | |||||
</StackPanel> | |||||
</Grid> | </Grid> | ||||
</Page> | </Page> |
@@ -1,9 +1,13 @@ | |||||
using System; | using System; | ||||
using System.Text; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Windows.UI.Core; | using Windows.UI.Core; | ||||
using Windows.UI.Xaml; | using Windows.UI.Xaml; | ||||
using MQTTnet.Core; | |||||
using MQTTnet.Core.Client; | using MQTTnet.Core.Client; | ||||
using MQTTnet.Core.Diagnostics; | using MQTTnet.Core.Diagnostics; | ||||
using MQTTnet.Core.Packets; | |||||
using MQTTnet.Core.Protocol; | |||||
namespace MQTTnet.TestApp.UniversalWindows | namespace MQTTnet.TestApp.UniversalWindows | ||||
{ | { | ||||
@@ -22,7 +26,7 @@ namespace MQTTnet.TestApp.UniversalWindows | |||||
{ | { | ||||
await Trace.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => | await Trace.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => | ||||
{ | { | ||||
var text = $"[{DateTime.Now:O}] [{e.Level}] [{e.Source}] [{e.ThreadId}] [{e.Message}]{Environment.NewLine}"; | |||||
var text = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] [{e.Level}] [{e.Source}] [{e.ThreadId}] [{e.Message}]{Environment.NewLine}"; | |||||
if (e.Exception != null) | if (e.Exception != null) | ||||
{ | { | ||||
text += $"{e.Exception}{Environment.NewLine}"; | text += $"{e.Exception}{Environment.NewLine}"; | ||||
@@ -60,5 +64,112 @@ namespace MQTTnet.TestApp.UniversalWindows | |||||
Trace.Text += exception + Environment.NewLine; | Trace.Text += exception + Environment.NewLine; | ||||
} | } | ||||
} | } | ||||
private async void Publish(object sender, RoutedEventArgs e) | |||||
{ | |||||
if (_mqttClient == null) | |||||
{ | |||||
return; | |||||
} | |||||
try | |||||
{ | |||||
var qos = MqttQualityOfServiceLevel.AtMostOnce; | |||||
if (QoS1.IsChecked == true) | |||||
{ | |||||
qos = MqttQualityOfServiceLevel.AtLeastOnce; | |||||
} | |||||
if (QoS2.IsChecked == true) | |||||
{ | |||||
qos = MqttQualityOfServiceLevel.ExactlyOnce; | |||||
} | |||||
var payload = new byte[0]; | |||||
if (Text.IsChecked == true) | |||||
{ | |||||
payload = Encoding.UTF8.GetBytes(Payload.Text); | |||||
} | |||||
if (Base64.IsChecked == true) | |||||
{ | |||||
payload = Convert.FromBase64String(Payload.Text); | |||||
} | |||||
var message = new MqttApplicationMessage( | |||||
Topic.Text, | |||||
payload, | |||||
qos, | |||||
Retain.IsChecked == true); | |||||
await _mqttClient.PublishAsync(message); | |||||
} | |||||
catch (Exception exception) | |||||
{ | |||||
Trace.Text += exception + Environment.NewLine; | |||||
} | |||||
} | |||||
private async void Disconnect(object sender, RoutedEventArgs e) | |||||
{ | |||||
try | |||||
{ | |||||
await _mqttClient.DisconnectAsync(); | |||||
} | |||||
catch (Exception exception) | |||||
{ | |||||
Trace.Text += exception + Environment.NewLine; | |||||
} | |||||
} | |||||
private void Clear(object sender, RoutedEventArgs e) | |||||
{ | |||||
Trace.Text = string.Empty; | |||||
} | |||||
private async void Subscribe(object sender, RoutedEventArgs e) | |||||
{ | |||||
if (_mqttClient == null) | |||||
{ | |||||
return; | |||||
} | |||||
try | |||||
{ | |||||
var qos = MqttQualityOfServiceLevel.AtMostOnce; | |||||
if (SubscribeQoS1.IsChecked == true) | |||||
{ | |||||
qos = MqttQualityOfServiceLevel.AtLeastOnce; | |||||
} | |||||
if (SubscribeQoS2.IsChecked == true) | |||||
{ | |||||
qos = MqttQualityOfServiceLevel.ExactlyOnce; | |||||
} | |||||
await _mqttClient.SubscribeAsync(new TopicFilter(SubscribeTopic.Text, qos)); | |||||
} | |||||
catch (Exception exception) | |||||
{ | |||||
Trace.Text += exception + Environment.NewLine; | |||||
} | |||||
} | |||||
private async void Unsubscribe(object sender, RoutedEventArgs e) | |||||
{ | |||||
if (_mqttClient == null) | |||||
{ | |||||
return; | |||||
} | |||||
try | |||||
{ | |||||
await _mqttClient.UnsubscribeAsync(SubscribeTopic.Text); | |||||
} | |||||
catch (Exception exception) | |||||
{ | |||||
Trace.Text += exception + Environment.NewLine; | |||||
} | |||||
} | |||||
} | } | ||||
} | } |
@@ -15,7 +15,7 @@ | |||||
</Resources> | </Resources> | ||||
<Applications> | <Applications> | ||||
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="MQTTnet.TestApp.UniversalWindows.App"> | <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="MQTTnet.TestApp.UniversalWindows.App"> | ||||
<uap:VisualElements DisplayName="MQTTnet.TestApp.UniversalWindows" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="MQTTnet.TestApp.UniversalWindows" BackgroundColor="transparent"> | |||||
<uap:VisualElements DisplayName="MQTTnet Test App" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="Test application for MQTT based communication" BackgroundColor="transparent"> | |||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"> | <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"> | ||||
</uap:DefaultTile> | </uap:DefaultTile> | ||||
<uap:SplashScreen Image="Assets\SplashScreen.png" /> | <uap:SplashScreen Image="Assets\SplashScreen.png" /> | ||||