Refactor ASP net Core integration and fix breaking change.

This commit is contained in:
Christian Kratky
2018-06-17 17:19:08 +02:00
parent 8444b6b3be
commit 66048931a2
7 changed files with 51 additions and 63 deletions
@@ -4,7 +4,6 @@ using MQTTnet.AspNetCore.Client.Tcp;
using MQTTnet.Packets;
using MQTTnet.Serializer;
using System;
using System.Collections.Generic;
using System.IO.Pipelines;
using System.Threading;
using System.Threading.Tasks;
@@ -13,11 +12,6 @@ namespace MQTTnet.AspNetCore
{
public class MqttConnectionContext : IMqttChannelAdapter
{
public IMqttPacketSerializer PacketSerializer { get; }
public ConnectionContext Connection { get; }
public string Endpoint => Connection.ConnectionId;
public MqttConnectionContext(
IMqttPacketSerializer packetSerializer,
ConnectionContext connection)
@@ -26,6 +20,12 @@ namespace MQTTnet.AspNetCore
Connection = connection;
}
public string Endpoint => Connection.ConnectionId;
public ConnectionContext Connection { get; }
public IMqttPacketSerializer PacketSerializer { get; }
public event EventHandler ReadingPacketStarted;
public event EventHandler ReadingPacketCompleted;
public Task ConnectAsync(TimeSpan timeout, CancellationToken cancellationToken)
{
if (Connection is TcpConnection tcp && !tcp.IsConnected)
@@ -43,10 +43,6 @@ namespace MQTTnet.AspNetCore
return Task.CompletedTask;
}
public void Dispose()
{
}
public async Task<MqttBasePacket> ReceivePacketAsync(TimeSpan timeout, CancellationToken cancellationToken)
{
var input = Connection.Transport.Input;
@@ -106,15 +102,16 @@ namespace MQTTnet.AspNetCore
cancellationToken.ThrowIfCancellationRequested();
return null;
}
}
public Task SendPacketAsync(MqttBasePacket packet, CancellationToken cancellationToken)
{
var buffer = PacketSerializer.Serialize(packet);
return Connection.Transport.Output.WriteAsync(buffer.AsMemory(), cancellationToken).AsTask();
}
public event EventHandler ReadingPacketStarted;
public event EventHandler ReadingPacketCompleted;
public void Dispose()
{
}
}
}