-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathAmountReachedState.cs
More file actions
114 lines (90 loc) · 3.3 KB
/
AmountReachedState.cs
File metadata and controls
114 lines (90 loc) · 3.3 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (c) 2025, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0
using Microsoft.Extensions.Logging;
using Moryx.ControlSystem.Jobs;
using Moryx.Logging;
using System.ComponentModel.DataAnnotations;
using Moryx.Orders.Management.Properties;
using Moryx.Users;
namespace Moryx.Orders.Management
{
[Display(Name = nameof(Strings.OperationState_AmountReachedState), ResourceType = typeof(Strings))]
internal sealed class AmountReachedState : OperationDataStateBase
{
public override bool CanAssign => true;
public override bool CanBegin => true;
public override bool CanPartialReport => true;
public override bool CanFinalReport => true;
public override bool CanInterrupt => true;
public override bool CanAdvice => true;
public override bool IsAmountReached => true;
public AmountReachedState(OperationData context, StateMap stateMap)
: base(context, stateMap, OperationClassification.Running)
{
}
public override void OnEnter()
{
base.OnEnter();
Context.ShowAmountReachedNotification();
}
public override void OnExit()
{
Context.AcknowledgeAmountReachedNotification();
base.OnExit();
}
public override void IncreaseTargetBy(int amount, User user)
{
if (Context.ReachableAmount < Context.TargetAmount + amount)
{
NextState(StateRunning);
}
Context.HandleIncreaseTargetBy(amount);
}
public override void Interrupt(User user)
{
NextState(StateInterrupted);
Context.HandleManualInterrupted();
}
public override ReportContext GetReportContext()
{
return Context.HandleReportContext();
}
public override void Report(OperationReport report)
{
switch (report.ConfirmationType)
{
case ConfirmationType.Final:
NextState(StateCompleted);
Context.HandleCompleted(report);
break;
case ConfirmationType.Partial:
Context.HandlePartialReport(report);
break;
default:
throw new ArgumentOutOfRangeException(nameof(report.ConfirmationType), report.ConfirmationType, null);
}
}
public override AdviceContext GetAdviceContext()
{
return Context.HandleAdviceContext();
}
public override void Advice(OperationAdvice advice)
{
Context.HandleAdvice(advice);
}
public override void Assign()
{
NextState(StateAmountReachedAssign);
Context.HandleReassign();
}
public override void Resume()
{
}
public override void JobsUpdated(JobStateChangedEventArgs args)
{
var debug = $"Recieved a job update after switching to the '{nameof(AmountReachedState)}'. " +
$"The update is ignored, as the operation has already recieved the latest values when switching states.";
(Context as ILoggingComponent)?.Logger.Log(LogLevel.Debug, debug);
}
}
}