Skip to content

Commit 0a7c101

Browse files
committed
Merge branch 'workflow-generator'
2 parents c1cc8b6 + 2ff01c6 commit 0a7c101

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Parsers/Dot/WorkflowGenerator/WfGenerator.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,38 @@ public virtual async Task HandleReply(Reply reply)
378378
}
379379
}
380380

381+
var canProcessEventMethod = new StringBuilder();
382+
383+
canProcessEventMethod.AppendLine($$"""
384+
/// <summary>
385+
/// Checks if the specified event can be processed in the current state
386+
/// </summary>
387+
/// <param name="event">The event to check</param>
388+
/// <returns>True if the event can be processed in current state, false otherwise</returns>
389+
public bool CanProcessEvent(WfEvent @event)
390+
{
391+
switch (CurrentState, @event)
392+
{
393+
""");
394+
395+
foreach (var (from, to, e, _, _) in transitions)
396+
{
397+
var eventName = SanitizeName(e);
398+
var eventType = $"WfEvent.{eventName}";
399+
400+
canProcessEventMethod.AppendLine($$"""
401+
case (WfState.{{from}}, {{eventType}} _):
402+
return true;
403+
""");
404+
}
405+
406+
canProcessEventMethod.AppendLine($$"""
407+
default:
408+
return false;
409+
}
410+
}
411+
""");
412+
381413
var eventMethods = string.Join("\n", eventMethodMap.OrderBy(x => x.Key).Select(x => x.Value));
382414
var afterEventMethods = string.Join("\n", afterEventMethodMap.OrderBy(x => x.Key).Select(x => x.Value));
383415

@@ -394,6 +426,8 @@ public virtual async Task HandleReply(Reply reply)
394426
395427
{{schedulingMethod}}
396428
429+
{{canProcessEventMethod}}
430+
397431
{{handleReplyMethod}}
398432
399433
public async Task<bool> ProcessEvent(WfEvent @event)

0 commit comments

Comments
 (0)