public override LeafStep AdvanceStep(DateTime now) { var leafStep = SubSteps[_currentSubStepIndex].AdvanceStep(now); if (!Active && !Completed) { Active = true; } else if (Active && !Completed) { if (SubSteps[_currentSubStepIndex].Completed) { ExecutionTime.Increment(SubSteps[_currentSubStepIndex].ExecutionTime); if (IsLastSubStep()) { Active = false; Completed = true; CurrentSubStep = null; return(null); } else { _currentSubStepIndex++; CurrentSubStep = SubSteps[_currentSubStepIndex]; leafStep = CurrentSubStep.AdvanceStep(now); } } } else { throw new InvalidOperationException(message: "This step has already been completed. Can't perform it again."); } return(leafStep); }