~ruther/NosSmooth

ref: 58d8743477820408507f19d1c1ce75b73e23615f NosSmooth/Samples/FileClient/Responders/PacketNotFoundResponder.cs -rw-r--r-- 1.5 KiB
58d87434 — Rutherther chore: bump versions 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
//  PacketNotFoundResponder.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Extensions.Logging;
using NosSmooth.Core.Extensions;
using NosSmooth.Core.Packets;
using NosSmooth.Packets;
using Remora.Results;

namespace FileClient.Responders;

/// <summary>
/// Responds to packets that were not found.
/// </summary>
public class PacketNotFoundResponder : IPacketResponder<UnresolvedPacket>, IPacketResponder<ParsingFailedPacket>
{
    private readonly ILogger<PacketNotFoundResponder> _logger;

    /// <summary>
    /// Initializes a new instance of the <see cref="PacketNotFoundResponder"/> class.
    /// </summary>
    /// <param name="logger">The logger.</param>
    public PacketNotFoundResponder(ILogger<PacketNotFoundResponder> logger)
    {
        _logger = logger;
    }

    /// <inheritdoc />
    public Task<Result> Respond(PacketEventArgs<UnresolvedPacket> packetArgs, CancellationToken ct = default)
    {
        _logger.LogWarning($"Could not find packet {packetArgs.PacketString}");
        return Task.FromResult(Result.FromSuccess());
    }

    /// <inheritdoc />
    public Task<Result> Respond(PacketEventArgs<ParsingFailedPacket> packetArgs, CancellationToken ct = default)
    {
        _logger.LogWarning($"Could not parse packet {packetArgs.PacketString}");
        _logger.LogResultError(packetArgs.Packet.SerializerResult);
        return Task.FromResult(Result.FromSuccess());
    }
}
Do not follow this link