Compare commits

...

36 commits

Author SHA1 Message Date
1bd3334dae chore(deps): update dependency meziantou.analyzer to v2.0.163
Signed-off-by: noreply@rainote.dev
2024-08-15 20:20:17 +00:00
9e505b9eb2 chore(deps): update dependency xunit to v2.9.0
Signed-off-by: noreply@rainote.dev
2024-08-15 20:20:08 +00:00
32d843bdc6 chore(deps): update dependency dotnet-sdk to v8.0.400
Signed-off-by: noreply@rainote.dev
2024-08-15 20:20:02 +00:00
b70a73e344 chore(deps): update dependency microsoft.visualstudio.threading.analyzers to v17.11.20
Signed-off-by: noreply@rainote.dev
2024-08-15 20:19:55 +00:00
495dac671c chore(deps): update .net dotnext to v5.12.0
Signed-off-by: noreply@rainote.dev
2024-08-14 00:01:25 +00:00
2b31505a9b
chore: formatting 2024-08-07 21:57:19 +02:00
2955b62012
chore: update pre-commit 2024-08-07 21:55:55 +02:00
fb3ca21fe6
fix: nullable must be handled 2024-08-07 21:33:12 +02:00
f749ae2058
chore: avoid error for now 2024-08-07 21:33:12 +02:00
b34628b673 chore(deps): update dependency xunit.runner.visualstudio to v2.8.2
Signed-off-by: noreply@rainote.dev
2024-08-07 19:32:02 +00:00
c0f3db95ce chore(deps): update dependency microsoft.visualstudio.threading.analyzers to v17.10.48
Signed-off-by: noreply@rainote.dev
2024-08-07 19:31:49 +00:00
dc03cbd848 chore(deps): update dependency microsoft.net.test.sdk to v17.10.0
Signed-off-by: noreply@rainote.dev
2024-08-07 19:31:35 +00:00
436335cb65 chore(deps): update dependency jetbrains.annotations to v2024
Signed-off-by: noreply@rainote.dev
2024-08-07 19:31:31 +00:00
b6da3f68a3 chore(deps): update dependency dotnet-sdk to v8.0.303
Signed-off-by: noreply@rainote.dev
2024-08-07 19:30:59 +00:00
b5ac05a853
chore: minor improvements 2024-08-07 19:05:41 +02:00
2e9539c3c0
chore: weird issue 2024-04-04 17:24:38 +02:00
d27e6eb8b4
chore: nuget improvements
Some checks failed
Release Rai.PacketMediator / preprocess (push) Successful in 2s
Release Rai.PacketMediator / build (push) Successful in 21s
Release Rai.PacketMediator / generate-licences (push) Successful in 33s
Release Rai.PacketMediator / publish (push) Failing after 23s
2024-04-04 17:21:43 +02:00
a66cb25802
fix: incorrect path
All checks were successful
Release Rai.PacketMediator / preprocess (push) Successful in 3s
Release Rai.PacketMediator / build (push) Successful in 22s
Release Rai.PacketMediator / publish (push) Successful in 25s
Release Rai.PacketMediator / generate-licences (push) Successful in 33s
2024-04-04 16:40:47 +02:00
4dc8fbe845
chore: nuget adjustments for packet ID
Some checks failed
Release Rai.PacketMediator / preprocess (push) Successful in 3s
Release Rai.PacketMediator / build (push) Failing after 18s
Release Rai.PacketMediator / publish (push) Has been skipped
Release Rai.PacketMediator / generate-licences (push) Has been skipped
2024-04-04 16:32:04 +02:00
3b7cf431fa Merge pull request 'chore(deps): update catthehacker/ubuntu:act-latest docker digest to efe7d85' (#17) from renovate/catthehacker-ubuntu-act-latest into main
Reviewed-on: #17
2024-04-04 14:18:17 +00:00
94f96ef5c2 chore(deps): update catthehacker/ubuntu:act-latest docker digest to efe7d85
Signed-off-by: noreply@rainote.dev
2024-04-04 14:18:17 +00:00
5a8b5478b5 Merge pull request 'chore(deps): update dependency microsoft.extensions.logging.abstractions to v8.0.1' (#10) from renovate/microsoft.extensions.logging.abstractions-8.x into main
Reviewed-on: #10
2024-04-04 14:10:14 +00:00
60736d7e60 chore(deps): update dependency microsoft.extensions.logging.abstractions to v8.0.1
Signed-off-by: noreply@rainote.dev
2024-04-04 14:10:14 +00:00
3caa69af9b Merge pull request 'chore(deps): update .net dotnext' (#18) from renovate/net-dotnext into main
Reviewed-on: #18
2024-04-04 14:10:05 +00:00
77c3f881d9 chore(deps): update .net dotnext
Signed-off-by: noreply@rainote.dev
2024-03-20 20:01:51 +00:00
22869ad78f Merge pull request 'chore(deps): update dependency dotnet-sdk to v8.0.203' (#15) from renovate/dotnet-sdk-8.x into main
Reviewed-on: #15
2024-03-15 07:00:03 +00:00
5daf90ca65 chore(deps): update dependency dotnet-sdk to v8.0.203
Signed-off-by: noreply@rainote.dev
2024-03-15 07:00:03 +00:00
6c32c74a27 Merge pull request 'chore(deps): update dependency meziantou.analyzer to v2.0.146' (#16) from renovate/meziantou.analyzer-2.x into main
Reviewed-on: #16
2024-03-15 06:59:57 +00:00
c0124d4d75 chore(deps): update dependency meziantou.analyzer to v2.0.146
Signed-off-by: noreply@rainote.dev
2024-03-15 02:01:46 +00:00
f3c896f13c chore(deps): update .net dotnext to v5.2.0
Signed-off-by: noreply@rainote.dev
2024-03-14 14:02:07 +00:00
2a2f484818 Merge pull request 'chore(deps): update catthehacker/ubuntu:act-latest docker digest to be66618' (#1) from renovate/catthehacker-ubuntu-act-latest into main
Reviewed-on: #1
2024-03-14 12:55:20 +00:00
db3eedc6f9 chore(deps): update catthehacker/ubuntu:act-latest docker digest to be66618
Signed-off-by: noreply@rainote.dev
2024-03-14 12:55:20 +00:00
705ee9d653 Merge pull request 'chore(deps): update dependency coverlet.collector to v6.0.2' (#12) from renovate/coverlet.collector-6.x into main
Reviewed-on: #12
2024-03-14 12:55:04 +00:00
0c4787bac9 chore(deps): update dependency coverlet.collector to v6.0.2
Signed-off-by: noreply@rainote.dev
2024-03-14 12:55:04 +00:00
7a7ee4388e Merge pull request 'chore(deps): update dependency dotnet-sdk to v8.0.202' (#11) from renovate/dotnet-sdk-8.x into main
Reviewed-on: #11
2024-03-14 12:54:48 +00:00
1ff099d035 chore(deps): update dependency dotnet-sdk to v8.0.202
Signed-off-by: noreply@rainote.dev
2024-03-12 18:01:52 +00:00
17 changed files with 193 additions and 149 deletions

View file

@ -1,11 +1,11 @@
name: Release Rai.PacketMediator
name: Release Rai.PacketMediator
run-name: ${{ gitea.actor }} is building the Server application
on:
push:
tags:
- 'v*.*.*'
- v*.*.*
paths-ignore:
- .run/**
- .run/**
jobs:
preprocess:
@ -13,72 +13,75 @@ jobs:
outputs:
sanitized_branch_name: ${{ steps.sanitize.outputs.sanitized_branch_name }}
steps:
- name: Sanitize branch name
id: sanitize
run: echo "::set-output name=sanitized_branch_name::$(echo ${{ github.ref_name }} | sed 's/\//-/g')"
- name: Sanitize branch name
id: sanitize
run: echo "::set-output name=sanitized_branch_name::$(echo ${{ github.ref_name }} | sed 's/\//-/g')"
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup dotnet
uses: https://github.com/actions/setup-dotnet@v3
with:
global-json-file: global.json
- name: Install dependencies
run: dotnet restore
- name: Build
run: |
dotnet build Rai.PacketMediator.csproj -c Release
- uses: actions/checkout@v4
- name: Setup dotnet
uses: https://github.com/actions/setup-dotnet@v3
with:
global-json-file: global.json
- name: Install dependencies
run: dotnet restore
- name: Build
run: |
cd RaiNote.PacketMediator
dotnet build RaiNote.PacketMediator.csproj -c Release
publish:
needs: [ build ]
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup dotnet
uses: https://github.com/actions/setup-dotnet@v3
with:
global-json-file: global.json
- name: Install dependencies
run: dotnet restore
- name: Extract Version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "Extracted version is $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
shell: bash
- name: Pack nugets
run: |
dotnet build Rai.PacketMediator.csproj -c Release -p:PackageVersion=${{env.VERSION}}
dotnet pack -c Release -p:PackageVersion=${{env.VERSION}} --output .
- name: Push to NuGet
run: |
dotnet nuget push "*.nupkg" --api-key ${{secrets.nuget_api_key}} --source https://forge.rainote.dev/api/packages/rainote/nuget/index.json
- uses: actions/checkout@v4
- name: Setup dotnet
uses: https://github.com/actions/setup-dotnet@v3
with:
global-json-file: global.json
- name: Install dependencies
run: dotnet restore
- name: Extract Version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "Extracted version is $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
shell: bash
- name: Pack nuget package
run: |
cd RaiNote.PacketMediator
dotnet build RaiNote.PacketMediator.csproj -c Release -p:PackageVersion=${{env.VERSION}}
dotnet pack -c Release -p:PackageVersion=${{env.VERSION}} --output .
- name: Push to NuGet
run: |
cd RaiNote.PacketMediator
dotnet nuget push "*.nupkg" --api-key ${{secrets.nuget_api_key}} --source https://forge.rainote.dev/api/packages/rainote/nuget/index.json
generate-licences:
needs: [ build, preprocess ]
needs: [build, preprocess]
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest@sha256:a96ff9118eb7ce9aa52c46eb6989d1c0227d31ec19de3ba0d8e0a484773ab4fb
container: catthehacker/ubuntu:act-latest@sha256:efe7d859ca6f98a21b3b0471ab48455af597a064d719f65332d0f105aadcad65
steps:
- uses: actions/checkout@v4
- name: Setup dotnet
uses: https://github.com/actions/setup-dotnet@v3
with:
dotnet-version: |
7.0
8.0
- name: Install dependencies
run: |
dotnet restore
echo "::add-path::$HOME/.dotnet/tools"
- name: Install nuget-license
run: dotnet tool install --global dotnet-project-licenses
- name: Export licenses
run: dotnet-project-licenses -i . -u --projects-filter projects_ignore_licenses.json -m -j -e -f licenses
- name: Upload licenses
uses: actions/upload-artifact@v3
with:
name: licenses
path: licenses
retention-days: 31
- uses: actions/checkout@v4
- name: Setup dotnet
uses: https://github.com/actions/setup-dotnet@v3
with:
dotnet-version: |
7.0
8.0
- name: Install dependencies
run: |
dotnet restore
echo "::add-path::$HOME/.dotnet/tools"
- name: Install nuget-license
run: dotnet tool install --global dotnet-project-licenses
- name: Export licenses
run: dotnet-project-licenses -i . -u --projects-filter projects_ignore_licenses.json -m -j -e -f licenses
- name: Upload licenses
uses: actions/upload-artifact@v3
with:
name: licenses
path: licenses
retention-days: 31

View file

@ -1,19 +1,19 @@
repos:
- repo: local
hooks:
- repo: local
hooks:
#Use dotnet format already installed on your machine
- id: dotnet-format
name: dotnet-format
language: system
entry: dotnet format --include
types_or: [ c#, vb ]
- repo: https://github.com/Mateusz-Grzelinski/actionlint-py
rev: v1.6.26.11
hooks:
- id: actionlint
additional_dependencies: [ pyflakes>=3.0.1, shellcheck-py>=0.9.0.5 ]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.12.0
hooks:
- id: pretty-format-yaml
args: [ --autofix, --indent, '2' ]
- id: dotnet-format
name: dotnet-format
language: system
entry: dotnet format --include
types_or: [c#, vb]
- repo: https://github.com/Mateusz-Grzelinski/actionlint-py
rev: v1.7.1.15
hooks:
- id: actionlint
additional_dependencies: [pyflakes>=3.0.1, shellcheck-py>=0.9.0.5]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.14.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '2']

View file

@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Rai.PacketMediator\Rai.PacketMediator.csproj" />
<ProjectReference Include="..\RaiNote.PacketMediator\RaiNote.PacketMediator.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,3 @@
// Licensed to Timothy Schenk under the Apache 2.0 License.
Console.WriteLine("Hello World!");

View file

@ -0,0 +1,8 @@
// Licensed to Timothy Schenk under the Apache 2.0 License.
namespace PacketMediator.Samples;
public class Sample
{
}

View file

@ -10,14 +10,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
@ -28,7 +28,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Rai.PacketMediator\Rai.PacketMediator.csproj" />
<ProjectReference Include="..\RaiNote.PacketMediator\RaiNote.PacketMediator.csproj" />
</ItemGroup>
</Project>

View file

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rai.PacketMediator", "Rai.PacketMediator\Rai.PacketMediator.csproj", "{13243A92-DC1E-4DBF-8E2C-13CE9ABFEAD3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RaiNote.PacketMediator", "RaiNote.PacketMediator\RaiNote.PacketMediator.csproj", "{13243A92-DC1E-4DBF-8E2C-13CE9ABFEAD3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PacketMediator.Samples", "PacketMediator.Samples\PacketMediator.Samples.csproj", "{C20254E6-0C15-43A4-9C4A-1D0B547F7983}"
EndProject

View file

@ -2,7 +2,7 @@
using JetBrains.Annotations;
namespace Rai.PacketMediator;
namespace RaiNote.PacketMediator;
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public interface IBidirectionalPacket : IOutgoingPacket, IIncomingPacket;

View file

@ -2,7 +2,7 @@
using JetBrains.Annotations;
namespace Rai.PacketMediator;
namespace RaiNote.PacketMediator;
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public interface IIncomingPacket : IPacket

View file

@ -2,7 +2,7 @@
using JetBrains.Annotations;
namespace Rai.PacketMediator;
namespace RaiNote.PacketMediator;
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public interface IOutgoingPacket : IPacket

View file

@ -1,5 +1,5 @@
// Licensed to Timothy Schenk under the Apache 2.0 License.
namespace Rai.PacketMediator;
namespace RaiNote.PacketMediator;
public interface IPacket;

View file

@ -3,7 +3,7 @@
using System.Diagnostics;
using JetBrains.Annotations;
namespace Rai.PacketMediator;
namespace RaiNote.PacketMediator;
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public interface IPacketHandler<in TIncomingPacket, in TSession> : IPacketHandler<TSession>

View file

@ -9,7 +9,7 @@ using DotNext.Linq.Expressions;
using DotNext.Metaprogramming;
using Microsoft.Extensions.DependencyInjection;
namespace Rai.PacketMediator;
namespace RaiNote.PacketMediator;
public class PacketDistributor<TPacketIdEnum, TSession> where TPacketIdEnum : Enum
{
@ -23,12 +23,14 @@ public class PacketDistributor<TPacketIdEnum, TSession> where TPacketIdEnum : En
public PacketDistributor(IServiceProvider serviceProvider,
IEnumerable<Assembly> sourcesContainingPackets, IEnumerable<Assembly> sourcesContainingPacketHandlers)
{
_channel = Channel.CreateUnbounded<ValueTuple<byte[], TPacketIdEnum, TSession>>(new UnboundedChannelOptions
{
AllowSynchronousContinuations = false,
SingleReader = false,
SingleWriter = false
});
_channel = Channel.CreateUnbounded<ValueTuple<byte[], TPacketIdEnum, TSession>>(
new UnboundedChannelOptions
{
AllowSynchronousContinuations = false,
SingleReader = false,
SingleWriter = false
}
);
var containingPackets = sourcesContainingPackets as Assembly[] ?? sourcesContainingPackets.ToArray();
var allIncomingPackets = GetAllPackets(containingPackets, typeof(IIncomingPacket));
var allOutgoingPackets = GetAllPackets(containingPackets, typeof(IOutgoingPacket));
@ -42,27 +44,32 @@ public class PacketDistributor<TPacketIdEnum, TSession> where TPacketIdEnum : En
new ConcurrentDictionary<TPacketIdEnum, Func<byte[], IIncomingPacket>>();
_packetHandlersInstantiation = new ConcurrentDictionary<TPacketIdEnum, IPacketHandler<TSession>?>();
packetHandlers.ForEach(packetHandlerPair =>
{
var packetHandler =
ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider,
packetHandlerPair.Value);
_packetHandlersInstantiation.TryAdd(packetHandlerPair.Key, packetHandler as IPacketHandler<TSession>);
});
allIncomingPackets.ForEach(packetsType =>
{
var lambda = CodeGenerator.Lambda<Func<byte[], IIncomingPacket>>(fun =>
{
var argPacketData = fun[0];
var newPacket = packetsType.Value.New();
var packetHandler =
ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider,
packetHandlerPair.Value
);
_packetHandlersInstantiation.TryAdd(packetHandlerPair.Key, packetHandler as IPacketHandler<TSession>);
}
);
allIncomingPackets.ForEach(packetsType =>
{
var lambda = CodeGenerator.Lambda<Func<byte[], IIncomingPacket>>(fun =>
{
var argPacketData = fun[0];
var newPacket = packetsType.Value.New();
var packetVariable = CodeGenerator.DeclareVariable(packetsType.Value, "packet");
CodeGenerator.Assign(packetVariable, newPacket);
CodeGenerator.Call(packetVariable, nameof(IIncomingPacket.Deserialize), argPacketData);
var packetVariable = CodeGenerator.DeclareVariable(packetsType.Value, "packet");
CodeGenerator.Assign(packetVariable, newPacket);
CodeGenerator.Call(packetVariable, nameof(IIncomingPacket.Deserialize), argPacketData);
CodeGenerator.Return(packetVariable);
}).Compile();
tempDeserializationMap.TryAdd(packetsType.Key, lambda);
});
CodeGenerator.Return(packetVariable);
}
)
.Compile();
tempDeserializationMap.TryAdd(packetsType.Key, lambda);
}
);
_deserializationMap = tempDeserializationMap.ToImmutableDictionary();
}
@ -74,11 +81,13 @@ public class PacketDistributor<TPacketIdEnum, TSession> where TPacketIdEnum : En
{
var packetsWithId = sourcesContainingPackets.SelectMany(a => a.GetTypes()
.Where(type => type is { IsInterface: false, IsAbstract: false } &&
type.GetInterfaces().Contains(packetType)
&& type.GetCustomAttributes<PacketIdAttribute<TPacketIdEnum>>().Any()
))
type.GetInterfaces().Contains(packetType) &&
type.GetCustomAttributes<PacketIdAttribute<TPacketIdEnum>>().Any()
)
)
.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));
return packetsWithId;
@ -89,20 +98,32 @@ public class PacketDistributor<TPacketIdEnum, TSession> where TPacketIdEnum : En
{
var packetHandlersWithId = sourcesContainingPacketHandlers.SelectMany(assembly => assembly.GetTypes()
.Where(t =>
t is { IsClass: true, IsAbstract: false } && Array.Exists(t
.GetInterfaces(), i =>
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPacketHandler<,>)))
t is { IsClass: true, IsAbstract: false } &&
Array.Exists(t
.GetInterfaces(),
i =>
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPacketHandler<,>)
)
)
.Select(packetHandlerType => new
{
Type = packetHandlerType,
PacketId = packetHandlerType
.GetInterfaces().First(t1 =>
t1 is { IsGenericType: true } &&
t1.GetGenericTypeDefinition() == typeof(IPacketHandler<,>)).GetGenericArguments()
.First(genericType => genericType.GetInterfaces().Any(packetType =>
packetType == typeof(IPacket)))
.GetCustomAttribute<PacketIdAttribute<TPacketIdEnum>>()
}))
.GetInterfaces()
.First(t1 =>
t1 is { IsGenericType: true } &&
t1.GetGenericTypeDefinition() == typeof(IPacketHandler<,>)
)
.GetGenericArguments()
.First(genericType => genericType.GetInterfaces()
.Any(packetType =>
packetType == typeof(IPacket)
)
)
.GetCustomAttribute<PacketIdAttribute<TPacketIdEnum>>()
}
)
)
.Where(x => x.PacketId != null)
.Select(x => new KeyValuePair<TPacketIdEnum, Type>(x.PacketId!.Code, x.Type));

View file

@ -3,7 +3,7 @@
using System.Reflection;
using Microsoft.Extensions.Hosting;
namespace Rai.PacketMediator;
namespace RaiNote.PacketMediator;
public class PacketDistributorService<TPacketIdEnum, TSession> : IHostedService
where TPacketIdEnum : Enum
@ -13,13 +13,15 @@ public class PacketDistributorService<TPacketIdEnum, TSession> : IHostedService
public PacketDistributorService(IServiceProvider serviceProvider,
IEnumerable<Assembly> sourcesContainingPackets, IEnumerable<Assembly> sourcesContainingPacketHandlers)
{
_packetDistributor = new PacketDistributor<TPacketIdEnum, TSession>(serviceProvider, sourcesContainingPackets,
sourcesContainingPacketHandlers);
_packetDistributor = new PacketDistributor<TPacketIdEnum, TSession>(serviceProvider,
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)
@ -32,15 +34,10 @@ public class PacketDistributorService<TPacketIdEnum, TSession> : IHostedService
return _packetDistributor.AddPacketAsync(packetData, operationCode, session);
}
public TPacketIdEnum GetOperationCodeByPacketType(IPacket packet)
public DotNext.Optional<TPacketIdEnum> GetOperationCodeByPacketType(IPacket packet)
{
var type = packet.GetType();
_packetDistributor.PacketIdMap.TryGetValue(type, out var value);
if (value is null)
{
throw new ArgumentOutOfRangeException(type.Name);
}
return value;
return value ?? DotNext.Optional<TPacketIdEnum>.None;
}
}

View file

@ -1,6 +1,6 @@
// Licensed to Timothy Schenk under the Apache 2.0 License.
namespace Rai.PacketMediator;
namespace RaiNote.PacketMediator;
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public abstract class PacketIdAttribute<TPacketIdEnum> : Attribute where TPacketIdEnum : Enum

View file

@ -6,23 +6,35 @@
<Nullable>enable</Nullable>
<PackageVersion>$(PackageVersion)</PackageVersion>
<PackageProjectUrl>https://forge.rainote.dev/rainote/PacketMediator</PackageProjectUrl>
<PackageLicenseUrl>https://forge.rainote.dev/rainote/PacketMediator/src/branch/main/LICENSE</PackageLicenseUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://forge.rainote.dev/rainote/PacketMediator</RepositoryUrl>
<RepositoryType>GIT</RepositoryType>
<Version>$(PackageVersion)</Version>
<Authors>Timothy (RaiNote) Schenk</Authors>
<AssemblyName>RaiNote.PacketMediator</AssemblyName>
<RootNamespace>RaiNote.PacketMediator</RootNamespace>
<PackageId>RaiNote.PacketMediator</PackageId>
<Title>Packet Mediator</Title>
<Description>A mediator specifically for packet handling when dispatching to respective packet handlers.</Description>
<Product>RaiNote.PacketMediator</Product>
<PackageReadmeFile>README.md</PackageReadmeFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<WarningsAsErrors>Nullable</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNext" Version="5.0.2"/>
<PackageReference Include="DotNext.Metaprogramming" Version="5.0.2"/>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0"/>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.145">
<None Include="../README.md" Pack="true" PackagePath="\"/>
<PackageReference Include="DotNext" Version="5.12.0"/>
<PackageReference Include="DotNext.Metaprogramming" Version="5.12.0"/>
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0"/>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.163">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0"/>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.9.28">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1"/>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View file

@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.201",
"version": "8.0.400",
"rollForward": "latestMinor",
"allowPrerelease": false
}