public override bool MoveNext() { var statefulTaskWithRollback = _realEnumerator.Current; if (statefulTaskWithRollback is null) { throw GetStatefulTaskIsNullException(); } try { // Execute current task. bool canMoveNext = _realEnumerator.MoveNext(); // "Current" property can change -> add to scope the previous one. _rollbackScope.Add(statefulTaskWithRollback); // On final task clear rollback scope. if (!canMoveNext) { _rollbackScope.CommitAndClear(); } return(canMoveNext); } catch (Exception ex) { Logger.Exception( ex, "Failed to execute state machine. Trying to rollback completed tasks." ); _rollbackScope.TryRollbackSafe(); // Rethrow original exception to signalize callers that state machine execution is failed. throw; } }
public override bool MoveNext() { var statefulTask = _realEnumerator.Current; if (statefulTask is null) { throw GetStatefulTaskIsNullException(); } bool isFinal = statefulTask.IsFinal; try { return(_realEnumerator.MoveNext()); } catch (Exception ex) { _handler(ex); // If task is final, interrupt state machine execution. if (isFinal) { return(false); } // Otherwise, continue execution if flag is set. return(_continueExecutionOnFailed); } }