diff --git a/MQTTnet.sln b/MQTTnet.sln
index 74f27256..505290e3 100644
--- a/MQTTnet.sln
+++ b/MQTTnet.sln
@@ -9,8 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9248C2E1
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{32A630A7-2598-41D7-B625-204CD906F5FB}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.UniversalWindows", "Tests\MQTTnet.TestApp.UniversalWindows\MQTTnet.TestApp.UniversalWindows.csproj", "{FF1F72D6-9524-4422-9497-3CC0002216ED}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet", "Source\MQTTnet\MQTTnet.csproj", "{3587E506-55A2-4EB3-99C7-DC01E42D25D2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{67C28AC1-BC3A-420A-BE9C-FA2401431CF9}"
@@ -91,28 +89,6 @@ Global
{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x64.Build.0 = Release|Any CPU
{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x86.ActiveCfg = Release|Any CPU
{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x86.Build.0 = Release|Any CPU
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|ARM.ActiveCfg = Debug|ARM
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|ARM.Build.0 = Debug|ARM
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|ARM.Deploy.0 = Debug|ARM
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|x64.ActiveCfg = Debug|x64
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|x64.Build.0 = Debug|x64
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|x64.Deploy.0 = Debug|x64
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|x86.ActiveCfg = Debug|x86
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|x86.Build.0 = Debug|x86
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|x86.Deploy.0 = Debug|x86
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|Any CPU.Build.0 = Release|Any CPU
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|ARM.ActiveCfg = Release|ARM
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|ARM.Build.0 = Release|ARM
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|ARM.Deploy.0 = Release|ARM
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|x64.ActiveCfg = Release|x64
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|x64.Build.0 = Release|x64
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|x64.Deploy.0 = Release|x64
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|x86.ActiveCfg = Release|x86
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|x86.Build.0 = Release|x86
- {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|x86.Deploy.0 = Release|x86
{3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|ARM.ActiveCfg = Debug|Any CPU
@@ -327,7 +303,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4}
- {FF1F72D6-9524-4422-9497-3CC0002216ED} = {A56E3128-1639-4F31-873A-325E14BB6295}
{3587E506-55A2-4EB3-99C7-DC01E42D25D2} = {32A630A7-2598-41D7-B625-204CD906F5FB}
{3D283AAD-AAA8-4339-8394-52F80B6304DB} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4}
{C6FF8AEA-0855-41EC-A1F3-AC262225BAB9} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4}
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/App.xaml b/Tests/MQTTnet.TestApp.UniversalWindows/App.xaml
deleted file mode 100644
index bdd5cc0f..00000000
--- a/Tests/MQTTnet.TestApp.UniversalWindows/App.xaml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/App.xaml.cs b/Tests/MQTTnet.TestApp.UniversalWindows/App.xaml.cs
deleted file mode 100644
index 13b5d0b4..00000000
--- a/Tests/MQTTnet.TestApp.UniversalWindows/App.xaml.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using System;
-using Windows.ApplicationModel;
-using Windows.ApplicationModel.Activation;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Navigation;
-
-namespace MQTTnet.TestApp.UniversalWindows
-{
- sealed partial class App
- {
- public App()
- {
- InitializeComponent();
- Suspending += OnSuspending;
- }
-
- protected override void OnLaunched(LaunchActivatedEventArgs e)
- {
- if (!(Window.Current.Content is Frame rootFrame))
- {
- rootFrame = new Frame();
-
- rootFrame.NavigationFailed += OnNavigationFailed;
-
- Window.Current.Content = rootFrame;
- }
-
- if (e.PrelaunchActivated == false)
- {
- if (rootFrame.Content == null)
- {
- rootFrame.Navigate(typeof(MainPage), e.Arguments);
- }
-
- Window.Current.Activate();
- }
- }
-
- void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
- {
- throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
- }
-
- private void OnSuspending(object sender, SuspendingEventArgs e)
- {
- var deferral = e.SuspendingOperation.GetDeferral();
- deferral.Complete();
- }
- }
-}
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/LockScreenLogo.scale-200.png b/Tests/MQTTnet.TestApp.UniversalWindows/Assets/LockScreenLogo.scale-200.png
deleted file mode 100644
index 735f57ad..00000000
Binary files a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/LockScreenLogo.scale-200.png and /dev/null differ
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/SplashScreen.scale-200.png b/Tests/MQTTnet.TestApp.UniversalWindows/Assets/SplashScreen.scale-200.png
deleted file mode 100644
index 023e7f1f..00000000
Binary files a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/SplashScreen.scale-200.png and /dev/null differ
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Square150x150Logo.scale-200.png b/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Square150x150Logo.scale-200.png
deleted file mode 100644
index af49fec1..00000000
Binary files a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Square150x150Logo.scale-200.png and /dev/null differ
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Square44x44Logo.scale-200.png b/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Square44x44Logo.scale-200.png
deleted file mode 100644
index ce342a2e..00000000
Binary files a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Square44x44Logo.scale-200.png and /dev/null differ
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
deleted file mode 100644
index f6c02ce9..00000000
Binary files a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Square44x44Logo.targetsize-24_altform-unplated.png and /dev/null differ
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/StoreLogo.png b/Tests/MQTTnet.TestApp.UniversalWindows/Assets/StoreLogo.png
deleted file mode 100644
index 7385b56c..00000000
Binary files a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/StoreLogo.png and /dev/null differ
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Wide310x150Logo.scale-200.png b/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Wide310x150Logo.scale-200.png
deleted file mode 100644
index 288995b3..00000000
Binary files a/Tests/MQTTnet.TestApp.UniversalWindows/Assets/Wide310x150Logo.scale-200.png and /dev/null differ
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/JsonServerStorage.cs b/Tests/MQTTnet.TestApp.UniversalWindows/JsonServerStorage.cs
deleted file mode 100644
index 1c8434bf..00000000
--- a/Tests/MQTTnet.TestApp.UniversalWindows/JsonServerStorage.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-using System.Collections.Generic;
-using System.IO;
-using System.Threading.Tasks;
-using MQTTnet.Server;
-using Newtonsoft.Json;
-
-namespace MQTTnet.TestApp.UniversalWindows
-{
- public sealed class JsonServerStorage : IMqttServerStorage
- {
- readonly string _filename = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Retained.json");
-
- public Task SaveRetainedMessagesAsync(IList messages)
- {
- var json = JsonConvert.SerializeObject(messages);
- File.WriteAllText(_filename, json);
-
- return Task.CompletedTask;
- }
-
- public async Task> LoadRetainedMessagesAsync()
- {
- await Task.CompletedTask;
-
- if (!File.Exists(_filename))
- {
- return new List();
- }
-
- try
- {
- var json = File.ReadAllText(_filename);
- return JsonConvert.DeserializeObject>(json);
- }
- catch
- {
- return new List();
- }
- }
-
- public void Clear()
- {
- if (File.Exists(_filename))
- {
- File.Delete(_filename);
- }
- }
- }
-}
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj b/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj
deleted file mode 100644
index 3c8c989b..00000000
--- a/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj
+++ /dev/null
@@ -1,196 +0,0 @@
-
-
-
-
- Debug
- x86
- {FF1F72D6-9524-4422-9497-3CC0002216ED}
- AppContainerExe
- Properties
- MQTTnet.TestApp.UniversalWindows
- MQTTnet.TestApp.UniversalWindows
- en-US
- UAP
- 10.0.18362.0
- 10.0.10240.0
- 14
- 512
- {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- true
- MQTTnet.TestApp.UniversalWindows_TemporaryKey.pfx
- 1B25E1E3A70C4FEF793B882295F383301B861796
- win10;win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot
- True
-
-
- true
- bin\x86\Debug\
- DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP
- ;2008
- full
- x86
- false
- prompt
- true
-
-
- bin\x86\Release\
- TRACE;NETFX_CORE;WINDOWS_UWP
- true
- ;2008
- pdbonly
- x86
- false
- prompt
- true
- false
-
-
- true
- bin\ARM\Debug\
- DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP
- ;2008
- full
- ARM
- false
- prompt
- true
-
-
- bin\ARM\Release\
- TRACE;NETFX_CORE;WINDOWS_UWP
- true
- ;2008
- pdbonly
- ARM
- false
- prompt
- true
- true
-
-
- true
- bin\x64\Debug\
- DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP
- ;2008
- full
- x64
- false
- prompt
- true
-
-
- bin\x64\Release\
- TRACE;NETFX_CORE;WINDOWS_UWP
- true
- ;2008
- pdbonly
- x64
- false
- prompt
- true
- true
-
-
-
- App.xaml
-
-
-
- MainPage.xaml
-
-
-
-
-
- Designer
-
-
- .editorconfig
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MSBuild:Compile
- Designer
-
-
- MSBuild:Compile
- Designer
-
-
-
-
- {C400533A-8EBA-4F0B-BF4D-295C3708604B}
- MQTTnet.Extensions.ManagedClient
-
-
- {c444e9c8-95fa-430e-9126-274129de16cd}
- MQTTnet.Extensions.Rpc
-
-
- {2BD01D53-4CA5-4142-BE8D-313876395E3E}
- MQTTnet.Extensions.WebSocket4Net
-
-
- {3587e506-55a2-4eb3-99c7-dc01e42d25d2}
- MQTTnet
-
-
-
-
- 6.2.10
-
-
- 4.0.0
-
-
-
- 14.0
-
-
- true
- bin\Debug\
- DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS
- ;2008
- true
- full
- x86
- false
- prompt
- MinimumRecommendedRules.ruleset
- true
-
-
- bin\Release\
- TRACE;NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS
- true
- ;2008
- true
- pdbonly
- x86
- false
- prompt
- MinimumRecommendedRules.ruleset
- true
-
-
-
-
\ No newline at end of file
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows_TemporaryKey.pfx b/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows_TemporaryKey.pfx
deleted file mode 100644
index b8877c01..00000000
Binary files a/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows_TemporaryKey.pfx and /dev/null differ
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml
deleted file mode 100644
index 11e68c65..00000000
--- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml
+++ /dev/null
@@ -1,266 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Server:
-
-
- Port:
-
-
- Username:
-
-
- Password:
-
-
- Client ID:
-
-
- Keep Alive interval:
-
-
- Transport:
-
- TCP
- WS
- WS (WebSocket4Net)
- Use TLS
-
-
- Protocol:
-
- 5.0.0
- 3.1.1
- 3.1.0
-
-
-
- Clean session
- Use managed client
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Topic:
-
-
- Content type:
-
-
- Payload:
-
-
- Payload format:
-
- Plain text
- Base64 string
-
-
- QoS level:
-
- 0 (At most once)
- 1 (At least once)
- 2 (Exactly once)
-
-
- Response topic:
-
-
-
- Retain
-
-
-
-
-
-
-
- Method:
-
-
- Payload:
-
-
- Text
- Base64
-
-
- QoS:
-
- 0 (At most once)
- 1 (At least once)
- 2 (Exactly once)
-
-
- Responses:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Topic:
-
-
- QoS:
-
- 0 (At most once)
- 1 (At least once)
- 2 (Exactly once)
-
-
- Received messages:
- Add received messages to list
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Port:
-
-
- Persist retained messages in JSON format
- Clear previously retained messages on startup
- Allow persistent sessions
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs
deleted file mode 100644
index 836e01f6..00000000
--- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs
+++ /dev/null
@@ -1,834 +0,0 @@
-using MQTTnet.Client;
-using MQTTnet.Client.Connecting;
-using MQTTnet.Client.Disconnecting;
-using MQTTnet.Client.Options;
-using MQTTnet.Diagnostics;
-using MQTTnet.Exceptions;
-using MQTTnet.Extensions.ManagedClient;
-using MQTTnet.Extensions.Rpc;
-using MQTTnet.Extensions.Rpc.Options;
-using MQTTnet.Extensions.WebSocket4Net;
-using MQTTnet.Formatter;
-using MQTTnet.Implementations;
-using MQTTnet.Protocol;
-using MQTTnet.Server;
-using MQTTnet.Server.Status;
-using System;
-using System.Collections.Concurrent;
-using System.Collections.ObjectModel;
-using System.Text;
-using System.Threading.Tasks;
-using Windows.Security.Cryptography.Certificates;
-using Windows.UI.Core;
-using Windows.UI.Xaml;
-
-namespace MQTTnet.TestApp.UniversalWindows
-{
- public sealed partial class MainPage
- {
- private readonly ConcurrentQueue _traceMessages = new ConcurrentQueue();
- private readonly ObservableCollection _sessions = new ObservableCollection();
-
- private IMqttClient _mqttClient;
- private IManagedMqttClient _managedMqttClient;
- private IMqttServer _mqttServer;
-
- public MainPage()
- {
- InitializeComponent();
-
- ClientId.Text = Guid.NewGuid().ToString("D");
-
- MqttNetGlobalLogger.LogMessagePublished += OnTraceMessagePublished;
- }
-
- private async void OnTraceMessagePublished(object sender, MqttNetLogMessagePublishedEventArgs e)
- {
- _traceMessages.Enqueue(e.LogMessage);
- await UpdateLogAsync();
- }
-
- private async Task UpdateLogAsync()
- {
- while (_traceMessages.Count > 100)
- {
- _traceMessages.TryDequeue(out _);
- }
-
- var logText = new StringBuilder();
- foreach (var traceMessage in _traceMessages)
- {
- logText.AppendFormat(
- "[{0:yyyy-MM-dd HH:mm:ss.fff}] [{1}] [{2}] [{3}] [{4}]{5}",
- traceMessage.Timestamp,
- traceMessage.Level,
- traceMessage.Source,
- traceMessage.ThreadId,
- traceMessage.Message,
- Environment.NewLine);
-
- if (traceMessage.Exception != null)
- {
- logText.AppendLine(traceMessage.Exception.ToString());
- }
- }
-
- await Trace.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
- {
- Trace.Text = logText.ToString();
- });
- }
-
- private async void Connect(object sender, RoutedEventArgs e)
- {
- var mqttFactory = new MqttFactory();
-
- var tlsOptions = new MqttClientTlsOptions
- {
- UseTls = UseTls.IsChecked == true,
- IgnoreCertificateChainErrors = true,
- IgnoreCertificateRevocationErrors = true,
- AllowUntrustedCertificates = true
- };
-
- var options = new MqttClientOptions
- {
- ClientId = ClientId.Text,
- ProtocolVersion = MqttProtocolVersion.V500
- };
-
- if (UseTcp.IsChecked == true)
- {
- options.ChannelOptions = new MqttClientTcpOptions
- {
- Server = Server.Text,
- Port = int.Parse(Port.Text),
- TlsOptions = tlsOptions
- };
- }
-
- if (UseWs.IsChecked == true)
- {
- options.ChannelOptions = new MqttClientWebSocketOptions
- {
- Uri = Server.Text,
- TlsOptions = tlsOptions
- };
- }
-
- if (UseWs4Net.IsChecked == true)
- {
- options.ChannelOptions = new MqttClientWebSocketOptions
- {
- Uri = Server.Text,
- TlsOptions = tlsOptions
- };
-
- mqttFactory.UseWebSocket4Net();
- }
-
- if (options.ChannelOptions == null)
- {
- throw new InvalidOperationException();
- }
-
- if (!string.IsNullOrEmpty(User.Text))
- {
- options.Credentials = new MqttClientCredentials
- {
- Username = User.Text,
- Password = Encoding.UTF8.GetBytes(Password.Text)
- };
- }
-
- options.CleanSession = CleanSession.IsChecked == true;
- options.KeepAlivePeriod = TimeSpan.FromSeconds(double.Parse(KeepAliveInterval.Text));
-
- if (UseMqtt310.IsChecked == true)
- {
- options.ProtocolVersion = MqttProtocolVersion.V310;
- }
- else if (UseMqtt311.IsChecked == true)
- {
- options.ProtocolVersion = MqttProtocolVersion.V311;
- }
- else if (UseMqtt500.IsChecked == true)
- {
- options.ProtocolVersion = MqttProtocolVersion.V500;
- }
-
- try
- {
- if (_mqttClient != null)
- {
- await _mqttClient.DisconnectAsync();
- _mqttClient.UseApplicationMessageReceivedHandler(HandleReceivedApplicationMessage);
- _mqttClient.ConnectedHandler = new MqttClientConnectedHandlerDelegate(x => OnConnected());
- _mqttClient.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(x => OnDisconnected());
- }
-
- if (UseManagedClient.IsChecked == true)
- {
- _managedMqttClient = mqttFactory.CreateManagedMqttClient();
- _managedMqttClient.UseApplicationMessageReceivedHandler(HandleReceivedApplicationMessage);
- _managedMqttClient.ConnectedHandler = new MqttClientConnectedHandlerDelegate(x => OnConnected());
- _managedMqttClient.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(x => OnDisconnected());
-
- await _managedMqttClient.StartAsync(new ManagedMqttClientOptions
- {
- ClientOptions = options
- });
- }
- else
- {
- _mqttClient = mqttFactory.CreateMqttClient();
- _mqttClient.UseApplicationMessageReceivedHandler(HandleReceivedApplicationMessage);
- _mqttClient.ConnectedHandler = new MqttClientConnectedHandlerDelegate(x => OnConnected());
- _mqttClient.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(x => OnDisconnected());
-
- await _mqttClient.ConnectAsync(options);
- }
- }
- catch (Exception exception)
- {
- Trace.Text += exception + Environment.NewLine;
- }
- }
-
- private void OnDisconnected()
- {
- _traceMessages.Enqueue(new MqttNetLogMessage
- {
- Timestamp = DateTime.UtcNow,
- ThreadId = -1,
- Level = MqttNetLogLevel.Info,
- Message = "! DISCONNECTED EVENT FIRED",
- });
-
- Task.Run(UpdateLogAsync);
- }
-
- private void OnConnected()
- {
- _traceMessages.Enqueue(new MqttNetLogMessage
- {
- Timestamp = DateTime.UtcNow,
- ThreadId = -1,
- Level = MqttNetLogLevel.Info,
- Message = "! CONNECTED EVENT FIRED",
- });
-
- Task.Run(UpdateLogAsync);
- }
-
- private async Task HandleReceivedApplicationMessage(MqttApplicationMessageReceivedEventArgs eventArgs)
- {
- var item = $"Timestamp: {DateTime.Now:O} | Topic: {eventArgs.ApplicationMessage.Topic} | Payload: {eventArgs.ApplicationMessage.ConvertPayloadToString()} | QoS: {eventArgs.ApplicationMessage.QualityOfServiceLevel}";
-
- await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
- {
- if (AddReceivedMessagesToList.IsChecked == true)
- {
- ReceivedMessages.Items.Add(item);
- }
- });
- }
-
- private async void Publish(object sender, RoutedEventArgs e)
- {
- try
- {
- var qos = MqttQualityOfServiceLevel.AtMostOnce;
- if (QoS1.IsChecked == true)
- {
- qos = MqttQualityOfServiceLevel.AtLeastOnce;
- }
-
- if (QoS2.IsChecked == true)
- {
- qos = MqttQualityOfServiceLevel.ExactlyOnce;
- }
-
- var payload = Array.Empty();
- if (PlainText.IsChecked == true)
- {
- payload = Encoding.UTF8.GetBytes(Payload.Text);
- }
-
- if (Base64.IsChecked == true)
- {
- payload = Convert.FromBase64String(Payload.Text);
- }
-
- var message = new MqttApplicationMessageBuilder()
- .WithContentType(ContentType.Text)
- .WithResponseTopic(ResponseTopic.Text)
- .WithTopic(Topic.Text)
- .WithPayload(payload)
- .WithQualityOfServiceLevel(qos)
- .WithRetainFlag(Retain.IsChecked == true)
- .Build();
-
- if (_mqttClient != null)
- {
- await _mqttClient.PublishAsync(message);
- }
-
- if (_managedMqttClient != null)
- {
- await _managedMqttClient.PublishAsync(message);
- }
- }
- catch (Exception exception)
- {
- Trace.Text += exception + Environment.NewLine;
- }
- }
-
- private async void Disconnect(object sender, RoutedEventArgs e)
- {
- try
- {
- if (_mqttClient != null)
- {
- await _mqttClient.DisconnectAsync();
- _mqttClient.Dispose();
- _mqttClient = null;
- }
-
- if (_managedMqttClient != null)
- {
- await _managedMqttClient.StopAsync();
- _managedMqttClient.Dispose();
- _managedMqttClient = null;
- }
- }
- catch (Exception exception)
- {
- Trace.Text += exception + Environment.NewLine;
- }
- }
-
- private void ClearLog(object sender, RoutedEventArgs e)
- {
- while (_traceMessages.Count > 0)
- {
- _traceMessages.TryDequeue(out _);
- }
-
- Trace.Text = string.Empty;
- }
-
- private async void Subscribe(object sender, RoutedEventArgs e)
- {
- try
- {
- var qos = MqttQualityOfServiceLevel.AtMostOnce;
- if (SubscribeQoS1.IsChecked == true)
- {
- qos = MqttQualityOfServiceLevel.AtLeastOnce;
- }
-
- if (SubscribeQoS2.IsChecked == true)
- {
- qos = MqttQualityOfServiceLevel.ExactlyOnce;
- }
-
- var topicFilter = new MqttTopicFilter { Topic = SubscribeTopic.Text, QualityOfServiceLevel = qos };
-
- if (_mqttClient != null)
- {
- await _mqttClient.SubscribeAsync(topicFilter);
- }
-
- if (_managedMqttClient != null)
- {
- await _managedMqttClient.SubscribeAsync(topicFilter);
- }
- }
- catch (Exception exception)
- {
- Trace.Text += exception + Environment.NewLine;
- }
- }
-
- private async void Unsubscribe(object sender, RoutedEventArgs e)
- {
- try
- {
- if (_mqttClient != null)
- {
- await _mqttClient.UnsubscribeAsync(SubscribeTopic.Text);
- }
-
- if (_managedMqttClient != null)
- {
- await _managedMqttClient.UnsubscribeAsync(SubscribeTopic.Text);
- }
- }
- catch (Exception exception)
- {
- Trace.Text += exception + Environment.NewLine;
- }
- }
-
- // This code is for the Wiki at GitHub!
- // ReSharper disable once UnusedMember.Local
-
- private async void StartServer(object sender, RoutedEventArgs e)
- {
- if (_mqttServer != null)
- {
- return;
- }
-
- JsonServerStorage storage = null;
- if (ServerPersistRetainedMessages.IsChecked == true)
- {
- storage = new JsonServerStorage();
-
- if (ServerClearRetainedMessages.IsChecked == true)
- {
- storage.Clear();
- }
- }
-
- _mqttServer = new MqttFactory().CreateMqttServer();
-
- var options = new MqttServerOptions();
- options.DefaultEndpointOptions.Port = int.Parse(ServerPort.Text);
- options.Storage = storage;
- options.EnablePersistentSessions = ServerAllowPersistentSessions.IsChecked == true;
-
- await _mqttServer.StartAsync(options);
- }
-
- private async void StopServer(object sender, RoutedEventArgs e)
- {
- if (_mqttServer == null)
- {
- return;
- }
-
- await _mqttServer.StopAsync();
- _mqttServer = null;
- }
-
- private void ClearReceivedMessages(object sender, RoutedEventArgs e)
- {
- ReceivedMessages.Items.Clear();
- }
-
- private async void ExecuteRpc(object sender, RoutedEventArgs e)
- {
- var qos = MqttQualityOfServiceLevel.AtMostOnce;
- if (RpcQoS1.IsChecked == true)
- {
- qos = MqttQualityOfServiceLevel.AtLeastOnce;
- }
-
- if (RpcQoS2.IsChecked == true)
- {
- qos = MqttQualityOfServiceLevel.ExactlyOnce;
- }
-
- var payload = Array.Empty();
- if (RpcText.IsChecked == true)
- {
- payload = Encoding.UTF8.GetBytes(RpcPayload.Text);
- }
-
- if (RpcBase64.IsChecked == true)
- {
- payload = Convert.FromBase64String(RpcPayload.Text);
- }
-
- try
- {
- var rpcClient = new MqttRpcClient(_mqttClient, new MqttRpcClientOptions());
- var response = await rpcClient.ExecuteAsync(TimeSpan.FromSeconds(5), RpcMethod.Text, payload, qos);
-
- RpcResponses.Items.Add(RpcMethod.Text + " >>> " + Encoding.UTF8.GetString(response));
- }
- catch (MqttCommunicationTimedOutException)
- {
- RpcResponses.Items.Add(RpcMethod.Text + " >>> [TIMEOUT]");
- }
- catch (Exception exception)
- {
- RpcResponses.Items.Add(RpcMethod.Text + " >>> [EXCEPTION (" + exception.Message + ")]");
- }
- }
-
- private void ClearRpcResponses(object sender, RoutedEventArgs e)
- {
- RpcResponses.Items.Clear();
- }
-
- private void ClearSessions(object sender, RoutedEventArgs e)
- {
- _sessions.Clear();
- }
-
- private void RefreshSessions(object sender, RoutedEventArgs e)
- {
- if (_mqttServer == null)
- {
- return;
- }
-
- var sessions = _mqttServer.GetClientStatusAsync().GetAwaiter().GetResult();
- _sessions.Clear();
-
- foreach (var session in sessions)
- {
- _sessions.Add(session);
- }
-
- ListViewSessions.DataContext = _sessions;
- }
-
- #region Wiki Code
-
-#pragma warning disable IDE0051 // Remove unused private members
- private async Task WikiCode()
-#pragma warning restore IDE0051 // Remove unused private members
- {
- {
- // Use a custom identifier for the trace messages.
- var clientOptions = new MqttClientOptionsBuilder()
- .Build();
- }
-
- {
- // Create a new MQTT client.
- var factory = new MqttFactory();
- var client = factory.CreateMqttClient();
-
- // Create TCP based options using the builder.
- var options = new MqttClientOptionsBuilder()
- .WithClientId("Client1")
- .WithTcpServer("broker.hivemq.com")
- .WithCredentials("bud", "%spencer%")
- .WithTls()
- .WithCleanSession()
- .Build();
-
- await client.ConnectAsync(options);
-
- // Reconnecting
-
- client.UseDisconnectedHandler(async e =>
- {
- Console.WriteLine("### DISCONNECTED FROM SERVER ###");
- await Task.Delay(TimeSpan.FromSeconds(5));
-
- try
- {
- await client.ConnectAsync(options);
- }
- catch
- {
- Console.WriteLine("### RECONNECTING FAILED ###");
- }
- });
-
- // Consuming messages
-
- client.UseApplicationMessageReceivedHandler(e =>
- {
- Console.WriteLine("### RECEIVED APPLICATION MESSAGE ###");
- Console.WriteLine($"+ Topic = {e.ApplicationMessage.Topic}");
- Console.WriteLine($"+ Payload = {Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}");
- Console.WriteLine($"+ QoS = {e.ApplicationMessage.QualityOfServiceLevel}");
- Console.WriteLine($"+ Retain = {e.ApplicationMessage.Retain}");
- Console.WriteLine();
- });
-
- void Handler(MqttApplicationMessageReceivedEventArgs args)
- {
- //...
- }
-
- client.UseApplicationMessageReceivedHandler(e => Handler(e));
-
- // Subscribe after connect
-
- client.UseConnectedHandler(async e =>
- {
- Console.WriteLine("### CONNECTED WITH SERVER ###");
-
- // Subscribe to a topic
- await client.SubscribeAsync(new MqttTopicFilterBuilder().WithTopic("my/topic").Build());
-
- Console.WriteLine("### SUBSCRIBED ###");
- });
-
- // Subscribe to a topic
- await client.SubscribeAsync(new MqttTopicFilterBuilder().WithTopic("my/topic").Build());
-
- // Unsubscribe from a topic
- await client.UnsubscribeAsync("my/topic");
-
- // Publish an application message
- var applicationMessage = new MqttApplicationMessageBuilder()
- .WithTopic("A/B/C")
- .WithPayload("Hello World")
- .WithAtLeastOnceQoS()
- .Build();
-
- await client.PublishAsync(applicationMessage);
- }
-
- {
-
- {
- // 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();
- }
-
- {
- // Create TCP based options manually
- var options = new MqttClientOptions
- {
- ClientId = "Client1",
- Credentials = new MqttClientCredentials
- {
- Username = "bud",
- Password = Encoding.UTF8.GetBytes("%spencer%")
- },
- ChannelOptions = new MqttClientTcpOptions
- {
- Server = "broker.hivemq.org",
- TlsOptions = new MqttClientTlsOptions
- {
- UseTls = true
- }
- },
- };
- }
- }
-
- // ----------------------------------
- {
- var options = new MqttServerOptions
- {
- ConnectionValidator = new MqttServerConnectionValidatorDelegate(c =>
- {
- if (c.ClientId.Length < 10)
- {
- c.ReasonCode = MqttConnectReasonCode.ClientIdentifierNotValid;
- return;
- }
-
- if (c.Username != "mySecretUser")
- {
- c.ReasonCode = MqttConnectReasonCode.BadUserNameOrPassword;
- return;
- }
-
- if (c.Password != "mySecretPassword")
- {
- c.ReasonCode = MqttConnectReasonCode.BadUserNameOrPassword;
- return;
- }
-
- c.ReasonCode = MqttConnectReasonCode.Success;
- })
- };
-
- var factory = new MqttFactory();
- var mqttServer = factory.CreateMqttServer();
- await mqttServer.StartAsync(options);
-
- Console.WriteLine("Press any key to exit.");
- Console.ReadLine();
-
- await mqttServer.StopAsync();
- }
-
- // ----------------------------------
-
- // For UWP apps:
- MqttTcpChannel.CustomIgnorableServerCertificateErrorsResolver = o =>
- {
- if (o.Server == "server_with_revoked_cert")
- {
- return new[] { ChainValidationResult.Revoked };
- }
-
- return Array.Empty();
- };
-
- {
- // Start a MQTT server.
- var mqttServer = new MqttFactory().CreateMqttServer();
- await mqttServer.StartAsync(new MqttServerOptions());
- Console.WriteLine("Press any key to exit.");
- Console.ReadLine();
- await mqttServer.StopAsync();
- }
-
- {
- // Configure MQTT server.
- var optionsBuilder = new MqttServerOptionsBuilder()
- .WithConnectionBacklog(100)
- .WithDefaultEndpointPort(1884);
-
- var options = new MqttServerOptions
- {
- };
-
- options.ConnectionValidator = new MqttServerConnectionValidatorDelegate(c =>
- {
- if (c.ClientId != "Highlander")
- {
- c.ReasonCode = MqttConnectReasonCode.ClientIdentifierNotValid;
- return;
- }
-
- c.ReasonCode = MqttConnectReasonCode.Success;
- });
-
- var mqttServer = new MqttFactory().CreateMqttServer();
- await mqttServer.StartAsync(optionsBuilder.Build());
- }
-
- {
- // Setup client validator.
- var options = new MqttServerOptions
- {
- ConnectionValidator = new MqttServerConnectionValidatorDelegate(c =>
- {
- if (c.ClientId.Length < 10)
- {
- c.ReasonCode = MqttConnectReasonCode.ClientIdentifierNotValid;
- return;
- }
-
- if (c.Username != "mySecretUser")
- {
- c.ReasonCode = MqttConnectReasonCode.BadUserNameOrPassword;
- return;
- }
-
- if (c.Password != "mySecretPassword")
- {
- c.ReasonCode = MqttConnectReasonCode.BadUserNameOrPassword;
- return;
- }
-
- c.ReasonCode = MqttConnectReasonCode.Success;
- })
- };
- }
-
- {
- // Create a new MQTT server.
- var mqttServer = new MqttFactory().CreateMqttServer();
- }
-
- {
- // Setup application message interceptor.
- var options = new MqttServerOptionsBuilder()
- .WithApplicationMessageInterceptor(context =>
- {
- if (context.ApplicationMessage.Topic == "my/custom/topic")
- {
- context.ApplicationMessage.Payload = Encoding.UTF8.GetBytes("The server injected payload.");
- }
-
- // It is also possible to read the payload and extend it. For example by adding a timestamp in a JSON document.
- // This is useful when the IoT device has no own clock and the creation time of the message might be important.
- })
- .Build();
- }
-
- {
- // Setup subscription interceptor.
- var options = new MqttServerOptionsBuilder()
- .WithSubscriptionInterceptor(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;
- }
- })
- .Build();
- }
-
- {
- // 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 MqttTopicFilterBuilder().WithTopic("my/topic").Build());
- await mqttClient.StartAsync(options);
- }
-
- {
- // Use a custom log ID for the logger.
- var factory = new MqttFactory();
- var client = factory.CreateMqttClient(new MqttNetLogger("MyCustomId"));
- }
-
- {
- var client = new MqttFactory().CreateMqttClient();
-
- var message = new MqttApplicationMessageBuilder()
- .WithTopic("MyTopic")
- .WithPayload("Hello World")
- .WithExactlyOnceQoS()
- .WithRetainFlag()
- .Build();
-
- await client.PublishAsync(message);
- }
-
- {
- // Write all trace messages to the console window.
- MqttNetGlobalLogger.LogMessagePublished += (s, e) =>
- {
- var trace = $">> [{e.LogMessage.Timestamp:O}] [{e.LogMessage.ThreadId}] [{e.LogMessage.Source}] [{e.LogMessage.Level}]: {e.LogMessage.Message}";
- if (e.LogMessage.Exception != null)
- {
- trace += Environment.NewLine + e.LogMessage.Exception.ToString();
- }
-
- Console.WriteLine(trace);
- };
- }
- }
-
- #endregion
- }
-}
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/Package.appxmanifest b/Tests/MQTTnet.TestApp.UniversalWindows/Package.appxmanifest
deleted file mode 100644
index 81914fad..00000000
--- a/Tests/MQTTnet.TestApp.UniversalWindows/Package.appxmanifest
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
- MQTTnet.TestApp.UniversalWindows
- test
- Assets\StoreLogo.png
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/Properties/AssemblyInfo.cs b/Tests/MQTTnet.TestApp.UniversalWindows/Properties/AssemblyInfo.cs
deleted file mode 100644
index d125e02e..00000000
--- a/Tests/MQTTnet.TestApp.UniversalWindows/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-[assembly: AssemblyTitle("MQTTnet.TestApp.UniversalWindows")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Christian Kratky")]
-[assembly: AssemblyProduct("MQTTnet")]
-[assembly: AssemblyCopyright("Copyright © Christian Kratky 2016-2017")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
-[assembly: ComVisible(false)]
\ No newline at end of file
diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/Properties/Default.rd.xml b/Tests/MQTTnet.TestApp.UniversalWindows/Properties/Default.rd.xml
deleted file mode 100644
index 7c40ffeb..00000000
--- a/Tests/MQTTnet.TestApp.UniversalWindows/Properties/Default.rd.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file