forked from temporalio/samples-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkflowUpdate.workflow.cs
65 lines (54 loc) · 1.56 KB
/
WorkflowUpdate.workflow.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
62
63
64
65
namespace TemporalioSamples.WorkflowUpdate;
using Temporalio.Workflows;
[Workflow]
public class WorkflowUpdate
{
private bool updateInProgress;
private ScreenId currentScreen = ScreenId.Screen1;
[WorkflowRun]
public async Task RunAsync() => await Workflow.WaitConditionAsync(() => currentScreen == ScreenId.End);
[WorkflowUpdateValidator(nameof(SubmitScreenAsync))]
public void ValidatorSubmitScreen(UiRequest request)
{
if (request == null)
{
throw new ArgumentException("Input can not be null");
}
}
[WorkflowUpdate]
public async Task<ScreenId> SubmitScreenAsync(UiRequest request)
{
// Ensure we process the requests one by one
await Workflow.WaitConditionAsync(() => !updateInProgress);
updateInProgress = true;
// Activities can be scheduled here
SetNextScreen(request);
updateInProgress = false;
return currentScreen;
}
private void SetNextScreen(UiRequest currentRequest)
{
currentScreen = currentRequest.ScreenId switch
{
ScreenId.Screen1 => ScreenId.Screen2,
ScreenId.Screen2 => ScreenId.End,
_ => currentScreen,
};
}
public enum ScreenId
{
/// <summary>
/// Screen1.
/// </summary>
Screen1,
/// <summary>
/// Screen2.
/// </summary>
Screen2,
/// <summary>
/// End.
/// </summary>
End,
}
public record UiRequest(string RequestId, ScreenId ScreenId);
}