diff --git a/Frameworks/MQTTnet.NetFramework/MqttClientFactory.cs b/Frameworks/MQTTnet.NetFramework/MqttClientFactory.cs
index ac997bc..6b011d1 100644
--- a/Frameworks/MQTTnet.NetFramework/MqttClientFactory.cs
+++ b/Frameworks/MQTTnet.NetFramework/MqttClientFactory.cs
@@ -7,7 +7,7 @@ using MQTTnet.Implementations;
namespace MQTTnet
{
- public class MqttClientFactory
+ public class MqttClientFactory : IMqttClientFactory
{
public IMqttClient CreateMqttClient(MqttClientOptions options)
{
@@ -21,9 +21,9 @@ namespace MQTTnet
switch (options.ConnectionType)
{
case MqttConnectionType.Tcp:
- return new MqttTcpChannel();
+ return new MqttTcpChannel();
case MqttConnectionType.Ws:
- return new MqttWebSocketChannel();
+ return new MqttWebSocketChannel();
default:
throw new NotSupportedException();
diff --git a/Frameworks/MQTTnet.NetFramework/MqttServerFactory.cs b/Frameworks/MQTTnet.NetFramework/MqttServerFactory.cs
index 00da03a..70e14f3 100644
--- a/Frameworks/MQTTnet.NetFramework/MqttServerFactory.cs
+++ b/Frameworks/MQTTnet.NetFramework/MqttServerFactory.cs
@@ -6,7 +6,7 @@ using MQTTnet.Implementations;
namespace MQTTnet
{
- public class MqttServerFactory
+ public class MqttServerFactory : IMqttServerFactory
{
public IMqttServer CreateMqttServer(MqttServerOptions options)
{
diff --git a/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs
index fe6b4f0..6b011d1 100644
--- a/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs
+++ b/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs
@@ -1,13 +1,13 @@
using System;
using MQTTnet.Core.Adapter;
+using MQTTnet.Core.Channel;
using MQTTnet.Core.Client;
using MQTTnet.Core.Serializer;
using MQTTnet.Implementations;
-using MQTTnet.Core.Channel;
namespace MQTTnet
{
- public class MqttClientFactory
+ public class MqttClientFactory : IMqttClientFactory
{
public IMqttClient CreateMqttClient(MqttClientOptions options)
{
@@ -30,4 +30,4 @@ namespace MQTTnet
}
}
}
-}
+}
\ No newline at end of file
diff --git a/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs
index 00da03a..70e14f3 100644
--- a/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs
+++ b/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs
@@ -6,7 +6,7 @@ using MQTTnet.Implementations;
namespace MQTTnet
{
- public class MqttServerFactory
+ public class MqttServerFactory : IMqttServerFactory
{
public IMqttServer CreateMqttServer(MqttServerOptions options)
{
diff --git a/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj b/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj
index f4205c3..b042a77 100644
--- a/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj
+++ b/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj
@@ -113,8 +113,8 @@
-
+
@@ -127,7 +127,7 @@
- 5.3.3
+ 5.4.0
diff --git a/Frameworks/MQTTnet.UniversalWindows/MqttClientFactory.cs b/Frameworks/MQTTnet.UniversalWindows/MqttClientFactory.cs
index 502539f..6b011d1 100644
--- a/Frameworks/MQTTnet.UniversalWindows/MqttClientFactory.cs
+++ b/Frameworks/MQTTnet.UniversalWindows/MqttClientFactory.cs
@@ -7,7 +7,7 @@ using MQTTnet.Implementations;
namespace MQTTnet
{
- public class MqttClientFactory
+ public class MqttClientFactory : IMqttClientFactory
{
public IMqttClient CreateMqttClient(MqttClientOptions options)
{
diff --git a/Frameworks/MQTTnet.UniversalWindows/MqttServerFactory.cs b/Frameworks/MQTTnet.UniversalWindows/MqttServerFactory.cs
index 00da03a..70e14f3 100644
--- a/Frameworks/MQTTnet.UniversalWindows/MqttServerFactory.cs
+++ b/Frameworks/MQTTnet.UniversalWindows/MqttServerFactory.cs
@@ -6,7 +6,7 @@ using MQTTnet.Implementations;
namespace MQTTnet
{
- public class MqttServerFactory
+ public class MqttServerFactory : IMqttServerFactory
{
public IMqttServer CreateMqttServer(MqttServerOptions options)
{
diff --git a/MQTTnet.Core/Client/IMqttClientFactory.cs b/MQTTnet.Core/Client/IMqttClientFactory.cs
new file mode 100644
index 0000000..cecc5ab
--- /dev/null
+++ b/MQTTnet.Core/Client/IMqttClientFactory.cs
@@ -0,0 +1,7 @@
+namespace MQTTnet.Core.Client
+{
+ public interface IMqttClientFactory
+ {
+ IMqttClient CreateMqttClient(MqttClientOptions options);
+ }
+}
\ No newline at end of file
diff --git a/MQTTnet.Core/MqttApplicationMessageFactory.cs b/MQTTnet.Core/MqttApplicationMessageFactory.cs
new file mode 100644
index 0000000..55025a3
--- /dev/null
+++ b/MQTTnet.Core/MqttApplicationMessageFactory.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Globalization;
+using System.IO;
+using System.Text;
+using MQTTnet.Core.Protocol;
+
+namespace MQTTnet.Core
+{
+ public class MqttApplicationMessageFactory
+ {
+ public MqttApplicationMessage CreateApplicationMessage(string topic, MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce, bool retain = false)
+ {
+ if (topic == null) throw new ArgumentNullException(nameof(topic));
+
+ return CreateApplicationMessage(topic, new byte[0], qualityOfServiceLevel, retain);
+ }
+
+ public MqttApplicationMessage CreateApplicationMessage(string topic, byte[] payload, MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce, bool retain = false)
+ {
+ if (topic == null) throw new ArgumentNullException(nameof(topic));
+
+ if (payload == null)
+ {
+ payload = new byte[0];
+ }
+
+ return new MqttApplicationMessage(topic, payload, qualityOfServiceLevel, retain);
+ }
+
+ public MqttApplicationMessage CreateApplicationMessage(string topic, TPayload payload, MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce, bool retain = false)
+ {
+ if (topic == null) throw new ArgumentNullException(nameof(topic));
+
+ var payloadString = Convert.ToString(payload, CultureInfo.InvariantCulture);
+ var payloadBuffer = string.IsNullOrEmpty(payloadString) ? new byte[0] : Encoding.UTF8.GetBytes(payloadString);
+
+ return CreateApplicationMessage(topic, payloadBuffer, qualityOfServiceLevel, retain);
+ }
+
+ public MqttApplicationMessage CreateApplicationMessage(string topic, Stream payload, MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce, bool retain = false)
+ {
+ if (topic == null) throw new ArgumentNullException(nameof(topic));
+
+ byte[] payloadBuffer;
+ if (payload == null || payload.Length == 0)
+ {
+ payloadBuffer = new byte[0];
+ }
+ else
+ {
+ payloadBuffer = new byte[payload.Length - payload.Position];
+ payload.Read(payloadBuffer, 0, payloadBuffer.Length);
+ }
+
+ return CreateApplicationMessage(topic, payloadBuffer, qualityOfServiceLevel, retain);
+ }
+ }
+}
diff --git a/MQTTnet.Core/Server/IMqttServerFactory.cs b/MQTTnet.Core/Server/IMqttServerFactory.cs
new file mode 100644
index 0000000..4d33a92
--- /dev/null
+++ b/MQTTnet.Core/Server/IMqttServerFactory.cs
@@ -0,0 +1,7 @@
+namespace MQTTnet.Core.Server
+{
+ public interface IMqttServerFactory
+ {
+ IMqttServer CreateMqttServer(MqttServerOptions options);
+ }
+}
\ No newline at end of file