Refactoring

This commit is contained in:
Gerardo
2017-10-18 17:14:13 +02:00
parent bc19f66812
commit 1f3b24d20f
5 changed files with 14 additions and 9 deletions
@@ -7,7 +7,7 @@ namespace MQTTnet.Implementations
{ {
public class MqttCommunicationAdapterFactory : IMqttCommunicationAdapterFactory public class MqttCommunicationAdapterFactory : IMqttCommunicationAdapterFactory
{ {
public IMqttCommunicationAdapter CreateMqttCommunicationAdapter(MqttClientQueuedOptions options) public IMqttCommunicationAdapter CreateMqttCommunicationAdapter(MqttClientOptions options)
{ {
if (options == null) throw new ArgumentNullException(nameof(options)); if (options == null) throw new ArgumentNullException(nameof(options));
@@ -21,6 +21,12 @@ namespace MQTTnet.Implementations
return new MqttChannelCommunicationAdapter(new MqttWebSocketChannel(webSocketOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion }); return new MqttChannelCommunicationAdapter(new MqttWebSocketChannel(webSocketOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion });
} }
if (options is MqttClientQueuedOptions queuedOptions)
{
return new MqttChannelCommunicationAdapter(new MqttTcpChannel(queuedOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion });
}
throw new NotSupportedException(); throw new NotSupportedException();
} }
} }
@@ -89,7 +89,7 @@ namespace MQTTnet.Implementations
RawReceiveStream = ReceiveStream; RawReceiveStream = ReceiveStream;
} }
private static Certificate LoadCertificate(MqttClientQueuedOptions options) private static Certificate LoadCertificate(MqttClientOptions options)
{ {
if (options.TlsOptions.Certificates == null || !options.TlsOptions.Certificates.Any()) if (options.TlsOptions.Certificates == null || !options.TlsOptions.Certificates.Any())
{ {
@@ -12,7 +12,7 @@ namespace MQTTnet.Core.Tests
_adapter = adapter; _adapter = adapter;
} }
public IMqttCommunicationAdapter CreateMqttCommunicationAdapter(MqttClientQueuedOptions options) public IMqttCommunicationAdapter CreateMqttCommunicationAdapter(MqttClientOptions options)
{ {
return _adapter; return _adapter;
} }
+4 -5
View File
@@ -6,7 +6,6 @@ using MQTTnet.Core.Protocol;
using MQTTnet.Core.Server; using MQTTnet.Core.Server;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -297,16 +296,16 @@ namespace MQTTnet.TestApp.NetCore
private class TestStorage : IMqttClientQueuedStorage private class TestStorage : IMqttClientQueuedStorage
{ {
string serializationFile = Path.Combine(Environment.CurrentDirectory, "messages.bin"); string serializationFile = System.IO.Path.Combine(Environment.CurrentDirectory, "messages.bin");
private IList<MqttApplicationMessage> _messages = new List<MqttApplicationMessage>(); private IList<MqttApplicationMessage> _messages = new List<MqttApplicationMessage>();
public Task<IList<MqttApplicationMessage>> LoadInflightMessagesAsync() public Task<IList<MqttApplicationMessage>> LoadInflightMessagesAsync()
{ {
//deserialize //deserialize
// MqttApplicationMessage is not serializable // MqttApplicationMessage is not serializable
if (File.Exists(serializationFile)) if (System.IO.File.Exists(serializationFile))
{ {
using (Stream stream = File.Open(serializationFile, FileMode.Open)) using (System.IO.Stream stream = System.IO.File.Open(serializationFile, System.IO.FileMode.Open))
{ {
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
@@ -325,7 +324,7 @@ namespace MQTTnet.TestApp.NetCore
_messages = messages; _messages = messages;
//serialize //serialize
// MqttApplicationMessage is not serializable // MqttApplicationMessage is not serializable
using (System.IO.Stream stream = File.Open(serializationFile, FileMode.Create)) using (System.IO.Stream stream = System.IO.File.Open(serializationFile, System.IO.FileMode.Create))
{ {
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
IList<TemporaryApplicationMessage> temp = new List<TemporaryApplicationMessage>(); IList<TemporaryApplicationMessage> temp = new List<TemporaryApplicationMessage>();
@@ -41,7 +41,7 @@ namespace MQTTnet.TestApp.UniversalWindows
private async void Connect(object sender, RoutedEventArgs e) private async void Connect(object sender, RoutedEventArgs e)
{ {
MqttClientQueuedOptions options = null; MqttClientOptions options = null;
if (UseTcp.IsChecked == true) if (UseTcp.IsChecked == true)
{ {
options = new MqttClientTcpOptions options = new MqttClientTcpOptions