PacketMediator/IPacketHandler.cs
Timothy Schenk 1078aad539
Some checks failed
Release Rai.PacketMediator / preprocess (push) Successful in 2s
Release Rai.PacketMediator / build (push) Successful in 19s
Release Rai.PacketMediator / publish (push) Failing after 22s
Release Rai.PacketMediator / generate-licences (push) Successful in 31s
chore: Initial commit + v0.0.1
2024-02-08 13:10:25 +01:00

35 lines
1.2 KiB
C#

// Licensed to Timothy Schenk under the GNU AGPL Version 3 License.
using System.Diagnostics;
using JetBrains.Annotations;
namespace Rai.PacketMediator;
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public interface IPacketHandler<in TIncomingPacket, in TSession> : IPacketHandler<TSession>
where TIncomingPacket : IIncomingPacket
{
async Task<bool> IPacketHandler<TSession>.TryHandleAsync(IIncomingPacket packet, TSession session,
CancellationToken cancellationToken)
{
if (packet is not TIncomingPacket tPacket)
{
return false;
}
using var activity = new ActivitySource(nameof(PacketMediator)).StartActivity(nameof(HandleAsync));
activity?.AddTag("Handler", ToString());
activity?.AddTag("Packet", packet.ToString());
await HandleAsync(tPacket, session, cancellationToken);
return true;
}
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public Task HandleAsync(TIncomingPacket packet, TSession session, CancellationToken cancellationToken);
}
public interface IPacketHandler<in TSession>
{
Task<bool> TryHandleAsync(IIncomingPacket packet, TSession session, CancellationToken cancellationToken);
}