From 2b31505a9be9c68b95a16782bcaacf2096315591 Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Wed, 7 Aug 2024 21:57:19 +0200 Subject: [PATCH] chore: formatting --- .gitea/workflows/release.yaml | 124 ++++++++++---------- PacketMediator.Samples/Program.cs | 2 +- PacketMediator.Samples/Sample.cs | 4 +- RaiNote.PacketMediator/PacketDistributor.cs | 97 +++++++++------ 4 files changed, 124 insertions(+), 103 deletions(-) diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index 5d82c23..0918884 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -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,75 +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: | - cd RaiNote.PacketMediator - dotnet build RaiNote.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 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 + - 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: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 diff --git a/PacketMediator.Samples/Program.cs b/PacketMediator.Samples/Program.cs index f5c4b28..771d25c 100644 --- a/PacketMediator.Samples/Program.cs +++ b/PacketMediator.Samples/Program.cs @@ -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!"); diff --git a/PacketMediator.Samples/Sample.cs b/PacketMediator.Samples/Sample.cs index 44d21ff..5d9da0b 100644 --- a/PacketMediator.Samples/Sample.cs +++ b/PacketMediator.Samples/Sample.cs @@ -1,8 +1,8 @@ -// Licensed to Timothy Schenk under the Apache 2.0 License. +// Licensed to Timothy Schenk under the Apache 2.0 License. namespace PacketMediator.Samples; public class Sample { - + } diff --git a/RaiNote.PacketMediator/PacketDistributor.cs b/RaiNote.PacketMediator/PacketDistributor.cs index 9c3dd17..53e6f57 100644 --- a/RaiNote.PacketMediator/PacketDistributor.cs +++ b/RaiNote.PacketMediator/PacketDistributor.cs @@ -23,12 +23,14 @@ public class PacketDistributor where TPacketIdEnum : En public PacketDistributor(IServiceProvider serviceProvider, IEnumerable sourcesContainingPackets, IEnumerable sourcesContainingPacketHandlers) { - _channel = Channel.CreateUnbounded>(new UnboundedChannelOptions - { - AllowSynchronousContinuations = false, - SingleReader = false, - SingleWriter = false - }); + _channel = Channel.CreateUnbounded>( + 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 where TPacketIdEnum : En new ConcurrentDictionary>(); _packetHandlersInstantiation = new ConcurrentDictionary?>(); packetHandlers.ForEach(packetHandlerPair => - { - var packetHandler = - ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, - packetHandlerPair.Value); - _packetHandlersInstantiation.TryAdd(packetHandlerPair.Key, packetHandler as IPacketHandler); - }); - allIncomingPackets.ForEach(packetsType => - { - var lambda = CodeGenerator.Lambda>(fun => { - var argPacketData = fun[0]; - var newPacket = packetsType.Value.New(); + var packetHandler = + ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, + packetHandlerPair.Value + ); + _packetHandlersInstantiation.TryAdd(packetHandlerPair.Key, packetHandler as IPacketHandler); + } + ); + allIncomingPackets.ForEach(packetsType => + { + var lambda = CodeGenerator.Lambda>(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 where TPacketIdEnum : En { var packetsWithId = sourcesContainingPackets.SelectMany(a => a.GetTypes() .Where(type => type is { IsInterface: false, IsAbstract: false } && - type.GetInterfaces().Contains(packetType) - && type.GetCustomAttributes>().Any() - )) + type.GetInterfaces().Contains(packetType) && + type.GetCustomAttributes>().Any() + ) + ) .Select(type => - new { Type = type, Attribute = type.GetCustomAttribute>() }) + new { Type = type, Attribute = type.GetCustomAttribute>() } + ) .Select(x => new KeyValuePair(x.Attribute!.Code, x.Type)); return packetsWithId; @@ -89,20 +98,32 @@ public class PacketDistributor 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>() - })) + .GetInterfaces() + .First(t1 => + t1 is { IsGenericType: true } && + t1.GetGenericTypeDefinition() == typeof(IPacketHandler<,>) + ) + .GetGenericArguments() + .First(genericType => genericType.GetInterfaces() + .Any(packetType => + packetType == typeof(IPacket) + ) + ) + .GetCustomAttribute>() + } + ) + ) .Where(x => x.PacketId != null) .Select(x => new KeyValuePair(x.PacketId!.Code, x.Type));