Working with Masstransit I prepared a simple StateMachine and trying to visualize it as mermaid diagram, but facing with strange behavior
Here is my state machine code
public class TestState : SagaStateMachineInstance
{
public Guid CorrelationId { get; set; }
public string CurrentState { get; set; }
public int ReadyEventStatus { get; set; }
public int ReadyEventStatus2 { get; set; }
}
public class TestStateMachine : MassTransitStateMachine<TestState>
{
public State Ready { get; private set; } = null!;
public State DataPrepared { get; private set; } = null!;
public Event<SourceUploaded> UploadedEvent { get; private set; }
public Event<CreateNewApplication> CreatedEvent { get; private set; }
public Event CompositeReadyEvent { get; private set; }
public Event<ApplicationSourceMoved> FilesMovedEvent { get; private set; }
public Event<ApplicationPrerequisitesPrepared> RecsPreparedEvent { get; private set; }
public Event CpmpositeDataPreparedEvent { get; private set; }
public Event<PreparebackgroundPackagingJob> PrepareBackgroundJobEvent { get; private set; }
public TestStateMachine()
{
Event(() => UploadedEvent, e => e.CorrelateById(context => context.Message.CorrelationId));
Event(() => CreatedEvent, e => e.CorrelateById(context => context.Message.CorrelationId));
Event(() => PrepareBackgroundJobEvent, e => e.CorrelateById(context => context.Message.CorrelationId));
InstanceState(x => x.CurrentState);
Initially(
When(UploadedEvent)
.Then(context => {
Console.WriteLine("Uploaded 1 : {0}", context.Saga.CorrelationId);
}),
When(CreatedEvent)
.Then(context => Console.WriteLine("Created 1 : {0}", context.Saga.CorrelationId))
);
CompositeEvent(() => CompositeReadyEvent, x => x.ReadyEventStatus, CompositeEventOptions.IncludeInitial, UploadedEvent, CreatedEvent);
During(Initial,
When(CompositeReadyEvent)
.Then(context => Console.WriteLine("Ready: {0}", context.Saga.CorrelationId))
.TransitionTo(Ready)
);
CompositeEvent(() => CpmpositeDataPreparedEvent, x => x.ReadyEventStatus2, CompositeEventOptions.IncludeInitial, FilesMovedEvent, RecsPreparedEvent);
During(Ready,
When(CpmpositeDataPreparedEvent)
.Then(context => Console.WriteLine("Data prepared: {0}", context.Saga.CorrelationId))
.TransitionTo(DataPrepared)
);
During(DataPrepared,
When(PrepareBackgroundJobEvent)
.Then(context => Console.WriteLine("Creation completed: {0}", context.Saga.CorrelationId))
);
SetCompletedWhenFinalized();
}
}
For visualization I'm using MassTransit.StateMachineVisualizer
var machine = new TestStateMachine();
var graph = machine.GetGraph();
var generator = new StateMachineMermaidGenerator(graph);
string mermaid = generator.CreateMermaidFile();
And I'm getting the following results
flowchart TB;
0(["Initial"]) --> 3["UploadedEvent<SourceUploaded>"];
0(["Initial"]) --> 5["CreatedEvent<CreateNewApplication>"];
0(["Initial"]) --> 6["FilesMovedEvent<ApplicationSourceMoved>"];
0(["Initial"]) --> 8["RecsPreparedEvent<ApplicationPrerequisitesPrepared>"];
3["UploadedEvent<SourceUploaded>"] --> 4[\"CompositeReadyEvent"/];
4[\"CompositeReadyEvent"/] --> 1(["Ready"]);
5["CreatedEvent<CreateNewApplication>"] --> 4[\"CompositeReadyEvent"/];
6["FilesMovedEvent<ApplicationSourceMoved>"] --> 7[\"CpmpositeDataPreparedEvent"/];
7[\"CpmpositeDataPreparedEvent"/] --> 2(["DataPrepared"]);
8["RecsPreparedEvent<ApplicationPrerequisitesPrepared>"] --> 7[\"CpmpositeDataPreparedEvent"/];
Is it correct that "FilesMovedEvent" and "RecsPreparedEvent" goes from Initial event, considering that I performed TransitionTo(Ready) and TransitionTo(DataPrepared) I'm expecting that state "Ready" should be parent for "FilesMovedEvent" and "RecsPreparedEvent" events did I missconfigurate State Machine or did I just missunderstood schema?
Thanks!