chore: formatting
This commit is contained in:
parent
2955b62012
commit
2b31505a9b
4 changed files with 124 additions and 103 deletions
|
@ -1,9 +1,9 @@
|
||||||
name: Release Rai.PacketMediator
|
name: Release Rai.PacketMediator
|
||||||
run-name: ${{ gitea.actor }} is building the Server application
|
run-name: ${{ gitea.actor }} is building the Server application
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*.*.*'
|
- v*.*.*
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- .run/**
|
- .run/**
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ jobs:
|
||||||
dotnet build RaiNote.PacketMediator.csproj -c Release
|
dotnet build RaiNote.PacketMediator.csproj -c Release
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
needs: [ build ]
|
needs: [build]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
@ -60,7 +60,7 @@ jobs:
|
||||||
dotnet nuget push "*.nupkg" --api-key ${{secrets.nuget_api_key}} --source https://forge.rainote.dev/api/packages/rainote/nuget/index.json
|
dotnet nuget push "*.nupkg" --api-key ${{secrets.nuget_api_key}} --source https://forge.rainote.dev/api/packages/rainote/nuget/index.json
|
||||||
|
|
||||||
generate-licences:
|
generate-licences:
|
||||||
needs: [ build, preprocess ]
|
needs: [build, preprocess]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: catthehacker/ubuntu:act-latest@sha256:efe7d859ca6f98a21b3b0471ab48455af597a064d719f65332d0f105aadcad65
|
container: catthehacker/ubuntu:act-latest@sha256:efe7d859ca6f98a21b3b0471ab48455af597a064d719f65332d0f105aadcad65
|
||||||
steps:
|
steps:
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
// Licensed to Timothy Schenk under the Apache 2.0 License.
|
// Licensed to Timothy Schenk under the Apache 2.0 License.
|
||||||
|
|
||||||
Console.WriteLine("Hello World!");
|
Console.WriteLine("Hello World!");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Licensed to Timothy Schenk under the Apache 2.0 License.
|
// Licensed to Timothy Schenk under the Apache 2.0 License.
|
||||||
|
|
||||||
namespace PacketMediator.Samples;
|
namespace PacketMediator.Samples;
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,14 @@ public class PacketDistributor<TPacketIdEnum, TSession> where TPacketIdEnum : En
|
||||||
public PacketDistributor(IServiceProvider serviceProvider,
|
public PacketDistributor(IServiceProvider serviceProvider,
|
||||||
IEnumerable<Assembly> sourcesContainingPackets, IEnumerable<Assembly> sourcesContainingPacketHandlers)
|
IEnumerable<Assembly> sourcesContainingPackets, IEnumerable<Assembly> sourcesContainingPacketHandlers)
|
||||||
{
|
{
|
||||||
_channel = Channel.CreateUnbounded<ValueTuple<byte[], TPacketIdEnum, TSession>>(new UnboundedChannelOptions
|
_channel = Channel.CreateUnbounded<ValueTuple<byte[], TPacketIdEnum, TSession>>(
|
||||||
|
new UnboundedChannelOptions
|
||||||
{
|
{
|
||||||
AllowSynchronousContinuations = false,
|
AllowSynchronousContinuations = false,
|
||||||
SingleReader = false,
|
SingleReader = false,
|
||||||
SingleWriter = false
|
SingleWriter = false
|
||||||
});
|
}
|
||||||
|
);
|
||||||
var containingPackets = sourcesContainingPackets as Assembly[] ?? sourcesContainingPackets.ToArray();
|
var containingPackets = sourcesContainingPackets as Assembly[] ?? sourcesContainingPackets.ToArray();
|
||||||
var allIncomingPackets = GetAllPackets(containingPackets, typeof(IIncomingPacket));
|
var allIncomingPackets = GetAllPackets(containingPackets, typeof(IIncomingPacket));
|
||||||
var allOutgoingPackets = GetAllPackets(containingPackets, typeof(IOutgoingPacket));
|
var allOutgoingPackets = GetAllPackets(containingPackets, typeof(IOutgoingPacket));
|
||||||
|
@ -45,9 +47,11 @@ public class PacketDistributor<TPacketIdEnum, TSession> where TPacketIdEnum : En
|
||||||
{
|
{
|
||||||
var packetHandler =
|
var packetHandler =
|
||||||
ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider,
|
ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider,
|
||||||
packetHandlerPair.Value);
|
packetHandlerPair.Value
|
||||||
|
);
|
||||||
_packetHandlersInstantiation.TryAdd(packetHandlerPair.Key, packetHandler as IPacketHandler<TSession>);
|
_packetHandlersInstantiation.TryAdd(packetHandlerPair.Key, packetHandler as IPacketHandler<TSession>);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
allIncomingPackets.ForEach(packetsType =>
|
allIncomingPackets.ForEach(packetsType =>
|
||||||
{
|
{
|
||||||
var lambda = CodeGenerator.Lambda<Func<byte[], IIncomingPacket>>(fun =>
|
var lambda = CodeGenerator.Lambda<Func<byte[], IIncomingPacket>>(fun =>
|
||||||
|
@ -60,9 +64,12 @@ public class PacketDistributor<TPacketIdEnum, TSession> where TPacketIdEnum : En
|
||||||
CodeGenerator.Call(packetVariable, nameof(IIncomingPacket.Deserialize), argPacketData);
|
CodeGenerator.Call(packetVariable, nameof(IIncomingPacket.Deserialize), argPacketData);
|
||||||
|
|
||||||
CodeGenerator.Return(packetVariable);
|
CodeGenerator.Return(packetVariable);
|
||||||
}).Compile();
|
}
|
||||||
|
)
|
||||||
|
.Compile();
|
||||||
tempDeserializationMap.TryAdd(packetsType.Key, lambda);
|
tempDeserializationMap.TryAdd(packetsType.Key, lambda);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
_deserializationMap = tempDeserializationMap.ToImmutableDictionary();
|
_deserializationMap = tempDeserializationMap.ToImmutableDictionary();
|
||||||
}
|
}
|
||||||
|
@ -74,11 +81,13 @@ public class PacketDistributor<TPacketIdEnum, TSession> where TPacketIdEnum : En
|
||||||
{
|
{
|
||||||
var packetsWithId = sourcesContainingPackets.SelectMany(a => a.GetTypes()
|
var packetsWithId = sourcesContainingPackets.SelectMany(a => a.GetTypes()
|
||||||
.Where(type => type is { IsInterface: false, IsAbstract: false } &&
|
.Where(type => type is { IsInterface: false, IsAbstract: false } &&
|
||||||
type.GetInterfaces().Contains(packetType)
|
type.GetInterfaces().Contains(packetType) &&
|
||||||
&& type.GetCustomAttributes<PacketIdAttribute<TPacketIdEnum>>().Any()
|
type.GetCustomAttributes<PacketIdAttribute<TPacketIdEnum>>().Any()
|
||||||
))
|
)
|
||||||
|
)
|
||||||
.Select(type =>
|
.Select(type =>
|
||||||
new { Type = type, Attribute = type.GetCustomAttribute<PacketIdAttribute<TPacketIdEnum>>() })
|
new { Type = type, Attribute = type.GetCustomAttribute<PacketIdAttribute<TPacketIdEnum>>() }
|
||||||
|
)
|
||||||
.Select(x => new KeyValuePair<TPacketIdEnum, Type>(x.Attribute!.Code, x.Type));
|
.Select(x => new KeyValuePair<TPacketIdEnum, Type>(x.Attribute!.Code, x.Type));
|
||||||
|
|
||||||
return packetsWithId;
|
return packetsWithId;
|
||||||
|
@ -89,20 +98,32 @@ public class PacketDistributor<TPacketIdEnum, TSession> where TPacketIdEnum : En
|
||||||
{
|
{
|
||||||
var packetHandlersWithId = sourcesContainingPacketHandlers.SelectMany(assembly => assembly.GetTypes()
|
var packetHandlersWithId = sourcesContainingPacketHandlers.SelectMany(assembly => assembly.GetTypes()
|
||||||
.Where(t =>
|
.Where(t =>
|
||||||
t is { IsClass: true, IsAbstract: false } && Array.Exists(t
|
t is { IsClass: true, IsAbstract: false } &&
|
||||||
.GetInterfaces(), i =>
|
Array.Exists(t
|
||||||
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPacketHandler<,>)))
|
.GetInterfaces(),
|
||||||
|
i =>
|
||||||
|
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPacketHandler<,>)
|
||||||
|
)
|
||||||
|
)
|
||||||
.Select(packetHandlerType => new
|
.Select(packetHandlerType => new
|
||||||
{
|
{
|
||||||
Type = packetHandlerType,
|
Type = packetHandlerType,
|
||||||
PacketId = packetHandlerType
|
PacketId = packetHandlerType
|
||||||
.GetInterfaces().First(t1 =>
|
.GetInterfaces()
|
||||||
|
.First(t1 =>
|
||||||
t1 is { IsGenericType: true } &&
|
t1 is { IsGenericType: true } &&
|
||||||
t1.GetGenericTypeDefinition() == typeof(IPacketHandler<,>)).GetGenericArguments()
|
t1.GetGenericTypeDefinition() == typeof(IPacketHandler<,>)
|
||||||
.First(genericType => genericType.GetInterfaces().Any(packetType =>
|
)
|
||||||
packetType == typeof(IPacket)))
|
.GetGenericArguments()
|
||||||
|
.First(genericType => genericType.GetInterfaces()
|
||||||
|
.Any(packetType =>
|
||||||
|
packetType == typeof(IPacket)
|
||||||
|
)
|
||||||
|
)
|
||||||
.GetCustomAttribute<PacketIdAttribute<TPacketIdEnum>>()
|
.GetCustomAttribute<PacketIdAttribute<TPacketIdEnum>>()
|
||||||
}))
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
.Where(x => x.PacketId != null)
|
.Where(x => x.PacketId != null)
|
||||||
.Select(x => new KeyValuePair<TPacketIdEnum, Type>(x.PacketId!.Code, x.Type));
|
.Select(x => new KeyValuePair<TPacketIdEnum, Type>(x.PacketId!.Code, x.Type));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue