-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseStopDeviceCommand.cs
61 lines (53 loc) · 2.33 KB
/
BaseStopDeviceCommand.cs
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
52
53
54
55
56
57
58
59
60
61
using CK.Core;
using System;
using System.Collections.Generic;
using System.Text;
namespace CK.DeviceModel;
/// <summary>
/// Non generic abstract base for <see cref="StopDeviceCommand{THost}"/> command that
/// stops a device.
/// </summary>
/// <remarks>
/// This class cannot be specialized. The only concrete type of this command is <see cref="StopDeviceCommand{THost}"/>.
/// </remarks>
public abstract class BaseStopDeviceCommand : DeviceCommandWithResult<bool>
{
private protected BaseStopDeviceCommand()
{
ImmediateSending = true;
ShouldCallDeviceOnCommandCompleted = false;
}
/// <summary>
/// Transforms any error into true result: a stop command always succeeds.
/// </summary>
/// <param name="ex">The exception.</param>
/// <param name="result">The result setter.</param>
protected override sealed void OnError( Exception ex, ref CompletionSource<bool>.OnError result )
{
result.SetResult( true );
}
/// <summary>
/// Transforms any error into !<see cref="IDevice.IsRunning"/> result:
/// a stop command normally always succeeds but if it has been canceled before its handling,
/// then the Stop may "fail".
/// </summary>
/// <param name="result">The result setter.</param>
protected override sealed void OnCanceled( ref CompletionSource<bool>.OnCanceled result )
{
result.SetResult( !Device.IsRunning );
}
/// <summary>
/// Gets or sets whether the <see cref="DeviceConfigurationStatus.AlwaysRunning"/> should be ignored.
/// </summary>
public bool IgnoreAlwaysRunning { get; set; }
/// <summary>
/// Returns <see cref="DeviceCommandStoppedBehavior.RunAnyway"/> (will be a no-op) since it must obviously not be deferred until the next start.
/// Note that this is not used: basic commands are always run by design.
/// </summary>
protected internal override sealed DeviceCommandStoppedBehavior StoppedBehavior => DeviceCommandStoppedBehavior.RunAnyway;
/// <summary>
/// Returns <see cref="DeviceImmediateCommandStoppedBehavior.RunAnyway"/> (will be a no-op).
/// Note that this is not used: basic commands are always run by design.
/// </summary>
protected internal override sealed DeviceImmediateCommandStoppedBehavior ImmediateStoppedBehavior => DeviceImmediateCommandStoppedBehavior.RunAnyway;
}