~ruther/NosSmooth

ref: db8b2f15fc108a6907f0b5d4769dbe4218a081e7 NosSmooth/Core/NosSmooth.Core/Stateful/StatefulPreExecutionEvent.cs -rw-r--r-- 1.6 KiB
db8b2f15 — Rutherther fix(packets): finfo contains just one update 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
46
47
48
49
50
51
//
//  StatefulPreExecutionEvent.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 System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using NosSmooth.Core.Client;
using NosSmooth.Core.Commands;
using NosSmooth.Core.Packets;
using NosSmooth.Packets;
using Remora.Results;

namespace NosSmooth.Core.Stateful;

/// <summary>
/// Event that injects stateful entities into the scope.
/// </summary>
internal class StatefulPreExecutionEvent : IPreExecutionEvent, IPreCommandExecutionEvent
{
    private readonly StatefulInjector _injector;

    /// <summary>
    /// Initializes a new instance of the <see cref="StatefulPreExecutionEvent"/> class.
    /// </summary>
    /// <param name="injector">The injector.</param>
    public StatefulPreExecutionEvent(StatefulInjector injector)
    {
        _injector = injector;
    }

    /// <inheritdoc />
    public Task<Result> ExecuteBeforeExecutionAsync<TPacket>
        (INostaleClient client, PacketEventArgs<TPacket> packetArgs, CancellationToken ct = default)
        where TPacket : IPacket
    {
        _injector.Client = client;
        return Task.FromResult(Result.FromSuccess());
    }

    /// <inheritdoc />
    public Task<Result> ExecuteBeforeCommandAsync<TCommand>(INostaleClient client, TCommand command, CancellationToken ct = default)
        where TCommand : ICommand
    {
        _injector.Client = client;
        return Task.FromResult(Result.FromSuccess());
    }
}
Do not follow this link