~ruther/NosSmooth

ref: 1c72fa321b5e1dec1e3f9b8bf1d9c85c7f7ec983 NosSmooth/Core/NosSmooth.Core/Extensions/TakeControlCommandExtensions.cs -rw-r--r-- 1.7 KiB
1c72fa32 — Rutherther Merge pull request #55 from Rutherther/feat/contracts 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
//
//  TakeControlCommandExtensions.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 NosSmooth.Core.Commands.Control;
using Remora.Results;

namespace NosSmooth.Core.Extensions;

/// <summary>
/// Extension methods for <see cref="ITakeControlCommand"/>.
/// </summary>
public static class TakeControlCommandExtensions
{
    /// <summary>
    /// Create a take control command base on a command that supports taking control over.
    /// </summary>
    /// <param name="takeControlCommand">The command implementing take control to copy.</param>
    /// <param name="group">The group of the new take control.</param>
    /// <param name="handleCallback">The callback to be called when control is granted.</param>
    /// <param name="cancellationCallback">The callback to be called if the operation was cancelled and the control was revoked.</param>
    /// <returns>The copied take control command.</returns>
    public static TakeControlCommand CreateTakeControl
    (
        this ITakeControlCommand takeControlCommand,
        string group,
        Func<CancellationToken, Task<Result>> handleCallback,
        Func<ControlCancelReason, Task<Result>> cancellationCallback
    )
    {
        return new TakeControlCommand
        (
            handleCallback,
            cancellationCallback,
            group,
            takeControlCommand.CanBeCancelledByAnother,
            takeControlCommand.WaitForCancellation,
            takeControlCommand.AllowUserCancel,
            takeControlCommand.CancelOnMapChange
        );
    }
}
Do not follow this link