Browse Source

Add interfaces for factories

release/3.x.x
Christian Kratky 7 years ago
parent
commit
651f0aa15c
10 changed files with 84 additions and 12 deletions
  1. +3
    -3
      Frameworks/MQTTnet.NetFramework/MqttClientFactory.cs
  2. +1
    -1
      Frameworks/MQTTnet.NetFramework/MqttServerFactory.cs
  3. +3
    -3
      Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs
  4. +1
    -1
      Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs
  5. +2
    -2
      Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj
  6. +1
    -1
      Frameworks/MQTTnet.UniversalWindows/MqttClientFactory.cs
  7. +1
    -1
      Frameworks/MQTTnet.UniversalWindows/MqttServerFactory.cs
  8. +7
    -0
      MQTTnet.Core/Client/IMqttClientFactory.cs
  9. +58
    -0
      MQTTnet.Core/MqttApplicationMessageFactory.cs
  10. +7
    -0
      MQTTnet.Core/Server/IMqttServerFactory.cs

+ 3
- 3
Frameworks/MQTTnet.NetFramework/MqttClientFactory.cs View File

@@ -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();


+ 1
- 1
Frameworks/MQTTnet.NetFramework/MqttServerFactory.cs View File

@@ -6,7 +6,7 @@ using MQTTnet.Implementations;

namespace MQTTnet
{
public class MqttServerFactory
public class MqttServerFactory : IMqttServerFactory
{
public IMqttServer CreateMqttServer(MqttServerOptions options)
{


+ 3
- 3
Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs View File

@@ -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
}
}
}
}
}

+ 1
- 1
Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs View File

@@ -6,7 +6,7 @@ using MQTTnet.Implementations;

namespace MQTTnet
{
public class MqttServerFactory
public class MqttServerFactory : IMqttServerFactory
{
public IMqttServer CreateMqttServer(MqttServerOptions options)
{


+ 2
- 2
Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj View File

@@ -113,8 +113,8 @@
<Compile Include="Implementations\MqttWebSocketChannel.cs" />
<Compile Include="MqttClientFactory.cs" />
<Compile Include="Implementations\MqttServerAdapter.cs" />
<Compile Include="MqttServerFactory.cs" />
<Compile Include="Implementations\MqttTcpChannel.cs" />
<Compile Include="MqttServerFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Implementations\WebSocketStream.cs" />
<EmbeddedResource Include="Properties\MQTTnet.Universal.rd.xml" />
@@ -127,7 +127,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>5.3.3</Version>
<Version>5.4.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>


+ 1
- 1
Frameworks/MQTTnet.UniversalWindows/MqttClientFactory.cs View File

@@ -7,7 +7,7 @@ using MQTTnet.Implementations;

namespace MQTTnet
{
public class MqttClientFactory
public class MqttClientFactory : IMqttClientFactory
{
public IMqttClient CreateMqttClient(MqttClientOptions options)
{


+ 1
- 1
Frameworks/MQTTnet.UniversalWindows/MqttServerFactory.cs View File

@@ -6,7 +6,7 @@ using MQTTnet.Implementations;

namespace MQTTnet
{
public class MqttServerFactory
public class MqttServerFactory : IMqttServerFactory
{
public IMqttServer CreateMqttServer(MqttServerOptions options)
{


+ 7
- 0
MQTTnet.Core/Client/IMqttClientFactory.cs View File

@@ -0,0 +1,7 @@
namespace MQTTnet.Core.Client
{
public interface IMqttClientFactory
{
IMqttClient CreateMqttClient(MqttClientOptions options);
}
}

+ 58
- 0
MQTTnet.Core/MqttApplicationMessageFactory.cs View File

@@ -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<TPayload>(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);
}
}
}

+ 7
- 0
MQTTnet.Core/Server/IMqttServerFactory.cs View File

@@ -0,0 +1,7 @@
namespace MQTTnet.Core.Server
{
public interface IMqttServerFactory
{
IMqttServer CreateMqttServer(MqttServerOptions options);
}
}

Loading…
Cancel
Save