in Forge.TreeWalker/src/SubroutineAction.cs [48:78]
public override async Task<ActionResponse> RunAction(ActionContext actionContext)
{
SubroutineInput input = (SubroutineInput)actionContext.ActionInput;
// Rehydrate the subroutine's SessionId if previously persisted.
SubroutineIntermediates intermediates = await actionContext.GetIntermediates<SubroutineIntermediates>();
if (intermediates == null)
{
intermediates = new SubroutineIntermediates()
{
SessionId = Guid.NewGuid()
};
await actionContext.CommitIntermediates<SubroutineIntermediates>(intermediates);
}
// Initialize TreeWalkerSession for this subroutine.
TreeWalkerSession subroutineSession = this.parameters.InitializeSubroutineTree(input, intermediates.SessionId, this.parameters);
// Update KeyPrefix of ForgeState for state persistence separation.
subroutineSession.Parameters.ForgeState.UpdateKeyPrefix(subroutineSession.Parameters.RootSessionId, subroutineSession.Parameters.SessionId);
// Walk tree starting at CurrentTreeNode if persisted, otherwise RootTreeNodeKey if given, otherwise "Root" as default.
string currentTreeNode = await subroutineSession.GetCurrentTreeNode() ?? subroutineSession.Schema.RootTreeNodeKey;
// WalkTree may throw exceptions. We let this happen to allow for possible retry handling.
await subroutineSession.WalkTree(currentTreeNode);
// Return the subroutine's last action response if available, otherwise return tree walker Status.
return await subroutineSession.GetLastActionResponseAsync() ?? new ActionResponse() { Status = subroutineSession.Status };
}