Ver a proveniência

moved files into the correct place

release/3.x.x
JanEggers há 6 anos
ascendente
cometimento
e65c3f2f2b
12 ficheiros alterados com 121 adições e 114 eliminações
  1. +0
    -114
      Frameworks/MQTTnet.AspnetCore/MqttConnectionContext.cs
  2. +0
    -0
      Source/MQTTnet.AspnetCore/Client/MqttClientConnectionContextFactory.cs
  3. +0
    -0
      Source/MQTTnet.AspnetCore/Client/Tcp/BufferExtensions.cs
  4. +0
    -0
      Source/MQTTnet.AspnetCore/Client/Tcp/DuplexPipe.cs
  5. +0
    -0
      Source/MQTTnet.AspnetCore/Client/Tcp/SocketAwaitable.cs
  6. +0
    -0
      Source/MQTTnet.AspnetCore/Client/Tcp/SocketReceiver.cs
  7. +0
    -0
      Source/MQTTnet.AspnetCore/Client/Tcp/SocketSender.cs
  8. +1
    -0
      Source/MQTTnet.AspnetCore/Client/Tcp/TcpConnection.cs
  9. +0
    -0
      Source/MQTTnet.AspnetCore/ConnectionBuilderExtensions.cs
  10. +120
    -0
      Source/MQTTnet.AspnetCore/MqttConnectionContext.cs
  11. +0
    -0
      Source/MQTTnet.AspnetCore/MqttConnectionHandler.cs
  12. +0
    -0
      Source/MQTTnet.AspnetCore/ReaderExtensions.cs

+ 0
- 114
Frameworks/MQTTnet.AspnetCore/MqttConnectionContext.cs Ver ficheiro

@@ -1,114 +0,0 @@
using Microsoft.AspNetCore.Connections;
using MQTTnet.Adapter;
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;

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)
{
PacketSerializer = packetSerializer;
Connection = connection;
}

public Task ConnectAsync(TimeSpan timeout, CancellationToken cancellationToken)
{
if (Connection is TcpConnection tcp && !tcp.IsConnected)
{
return tcp.StartAsync();
}
return Task.CompletedTask;
}

public Task DisconnectAsync(TimeSpan timeout, CancellationToken cancellationToken)
{
Connection.Transport.Input.Complete();
Connection.Transport.Output.Complete();

return Task.CompletedTask;
}

public void Dispose()
{
}

public async Task<MqttBasePacket> ReceivePacketAsync(TimeSpan timeout, CancellationToken cancellationToken)
{
var input = Connection.Transport.Input;

while (!cancellationToken.IsCancellationRequested)
{
ReadResult readResult;
ReadingPacketStarted?.Invoke(this, EventArgs.Empty);

var readTask = input.ReadAsync(cancellationToken);
if (readTask.IsCompleted)
{
readResult = readTask.Result;
}
else
{
readResult = await readTask;
}

var buffer = readResult.Buffer;

var consumed = buffer.Start;
var observed = buffer.Start;

try
{
if (!buffer.IsEmpty)
{
if (PacketSerializer.TryDeserialize(buffer, out var packet, out consumed, out observed))
{
return packet;
}
}
else if (readResult.IsCompleted)
{
break;
}
}
finally
{
// The buffer was sliced up to where it was consumed, so we can just advance to the start.
// We mark examined as buffer.End so that if we didn't receive a full frame, we'll wait for more data
// before yielding the read again.
input.AdvanceTo(consumed, observed);
ReadingPacketCompleted?.Invoke(this, EventArgs.Empty);
}
}

cancellationToken.ThrowIfCancellationRequested();
return null;
}

public async Task SendPacketsAsync(TimeSpan timeout, IEnumerable<MqttBasePacket> packets, CancellationToken cancellationToken)
{
foreach (var packet in packets)
{
var buffer = PacketSerializer.Serialize(packet);
await Connection.Transport.Output.WriteAsync(buffer.AsMemory());
}
}
public event EventHandler ReadingPacketStarted;
public event EventHandler ReadingPacketCompleted;
}
}

Frameworks/MQTTnet.AspnetCore/Client/MqttClientConnectionContextFactory.cs → Source/MQTTnet.AspnetCore/Client/MqttClientConnectionContextFactory.cs Ver ficheiro


Frameworks/MQTTnet.AspnetCore/Client/Tcp/BufferExtensions.cs → Source/MQTTnet.AspnetCore/Client/Tcp/BufferExtensions.cs Ver ficheiro


Frameworks/MQTTnet.AspnetCore/Client/Tcp/DuplexPipe.cs → Source/MQTTnet.AspnetCore/Client/Tcp/DuplexPipe.cs Ver ficheiro


Frameworks/MQTTnet.AspnetCore/Client/Tcp/SocketAwaitable.cs → Source/MQTTnet.AspnetCore/Client/Tcp/SocketAwaitable.cs Ver ficheiro


Frameworks/MQTTnet.AspnetCore/Client/Tcp/SocketReceiver.cs → Source/MQTTnet.AspnetCore/Client/Tcp/SocketReceiver.cs Ver ficheiro


Frameworks/MQTTnet.AspnetCore/Client/Tcp/SocketSender.cs → Source/MQTTnet.AspnetCore/Client/Tcp/SocketSender.cs Ver ficheiro


Frameworks/MQTTnet.AspnetCore/Client/Tcp/TcpConnection.cs → Source/MQTTnet.AspnetCore/Client/Tcp/TcpConnection.cs Ver ficheiro

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipelines;
using System.Net;

Frameworks/MQTTnet.AspnetCore/ConnectionBuilderExtensions.cs → Source/MQTTnet.AspnetCore/ConnectionBuilderExtensions.cs Ver ficheiro


+ 120
- 0
Source/MQTTnet.AspnetCore/MqttConnectionContext.cs Ver ficheiro

@@ -0,0 +1,120 @@
using Microsoft.AspNetCore.Connections;
using MQTTnet.Adapter;
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;

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)
{
PacketSerializer = packetSerializer;
Connection = connection;
}

public Task ConnectAsync(TimeSpan timeout, CancellationToken cancellationToken)
{
if (Connection is TcpConnection tcp && !tcp.IsConnected)
{
return tcp.StartAsync();
}
return Task.CompletedTask;
}

public Task DisconnectAsync(TimeSpan timeout, CancellationToken cancellationToken)
{
Connection.Transport.Input.Complete();
Connection.Transport.Output.Complete();

return Task.CompletedTask;
}

public void Dispose()
{
}

public async Task<MqttBasePacket> ReceivePacketAsync(TimeSpan timeout, CancellationToken cancellationToken)
{
var input = Connection.Transport.Input;

try
{
while (!cancellationToken.IsCancellationRequested)
{
ReadResult readResult;
var readTask = input.ReadAsync(cancellationToken);
if (readTask.IsCompleted)
{
readResult = readTask.Result;
}
else
{
readResult = await readTask;
}

var buffer = readResult.Buffer;

var consumed = buffer.Start;
var observed = buffer.Start;

try
{
if (!buffer.IsEmpty)
{
if (PacketSerializer.TryDeserialize(buffer, out var packet, out consumed, out observed))
{
return packet;
}
else
{
// we did receive something but the message is not yet complete
ReadingPacketStarted?.Invoke(this, EventArgs.Empty);
}
}
else if (readResult.IsCompleted)
{
break;
}
}
finally
{
// The buffer was sliced up to where it was consumed, so we can just advance to the start.
// We mark examined as buffer.End so that if we didn't receive a full frame, we'll wait for more data
// before yielding the read again.
input.AdvanceTo(consumed, observed);
}
}
}
finally
{
ReadingPacketCompleted?.Invoke(this, EventArgs.Empty);
}

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

Frameworks/MQTTnet.AspnetCore/MqttConnectionHandler.cs → Source/MQTTnet.AspnetCore/MqttConnectionHandler.cs Ver ficheiro


Frameworks/MQTTnet.AspnetCore/ReaderExtensions.cs → Source/MQTTnet.AspnetCore/ReaderExtensions.cs Ver ficheiro


Carregando…
Cancelar
Guardar