chore: minor improvements
This commit is contained in:
parent
2e9539c3c0
commit
b5ac05a853
1 changed files with 8 additions and 11 deletions
|
@ -13,13 +13,15 @@ public class PacketDistributorService<TPacketIdEnum, TSession> : IHostedService
|
||||||
public PacketDistributorService(IServiceProvider serviceProvider,
|
public PacketDistributorService(IServiceProvider serviceProvider,
|
||||||
IEnumerable<Assembly> sourcesContainingPackets, IEnumerable<Assembly> sourcesContainingPacketHandlers)
|
IEnumerable<Assembly> sourcesContainingPackets, IEnumerable<Assembly> sourcesContainingPacketHandlers)
|
||||||
{
|
{
|
||||||
_packetDistributor = new PacketDistributor<TPacketIdEnum, TSession>(serviceProvider, sourcesContainingPackets,
|
_packetDistributor = new PacketDistributor<TPacketIdEnum, TSession>(serviceProvider,
|
||||||
sourcesContainingPacketHandlers);
|
sourcesContainingPackets,
|
||||||
|
sourcesContainingPacketHandlers
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return _packetDistributor.DequeuePacketAsync(cancellationToken);
|
await _packetDistributor.DequeuePacketAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
@ -32,15 +34,10 @@ public class PacketDistributorService<TPacketIdEnum, TSession> : IHostedService
|
||||||
return _packetDistributor.AddPacketAsync(packetData, operationCode, session);
|
return _packetDistributor.AddPacketAsync(packetData, operationCode, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TPacketIdEnum GetOperationCodeByPacketType(IPacket packet)
|
public DotNext.Optional<TPacketIdEnum> GetOperationCodeByPacketType(IPacket packet)
|
||||||
{
|
{
|
||||||
var type = packet.GetType();
|
var type = packet.GetType();
|
||||||
_packetDistributor.PacketIdMap.TryGetValue(type, out var value);
|
_packetDistributor.PacketIdMap.TryGetValue(type, out var value);
|
||||||
if (value is null)
|
return value ?? DotNext.Optional<TPacketIdEnum>.None;
|
||||||
{
|
|
||||||
throw new ArgumentOutOfRangeException(type.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue