public static async Task MoveForward <TStepId, TData>(MoveToStepContext <TStepId, TData> context) #endif { IStepEnumerator <TStepId, TData> stepEnumerator = context.Session.StepEnumerator; IMoveInfo <TStepId> moveInfo = context.Session.MoveInfo; int moveCount = 0; do { stepEnumerator.MoveNext(); ++moveCount; }while (stepEnumerator.CurrentStep != null && !moveInfo.Comparer.Equals(stepEnumerator.CurrentStep.Id, moveInfo.Id)); context.Session.MoveInfo = null; if (stepEnumerator.CurrentStep == null) { for (int i = 0; i < moveCount; ++i) { stepEnumerator.MovePrevious(); } #if NET35 || NOASYNC RunUndoOperation.RunUndo(new RunUndoContext <TStepId, TData>() #else await RunUndoOperation.RunUndo(new RunUndoContext <TStepId, TData>() #endif { Result = ResultType.Failed, CaughtException = new InvalidOperationException(string.Format("Could not move forward to a step with id '{0}' as the step does not exist.", moveInfo.Id)), Session = context.Session }); return; } #if NET35 || NOASYNC context.MoveToStepFinishAction(); #else await context.MoveToStepFinishAction(); #endif }
public static async Task PrepareStep <TStepId, TData>(this ITransactionSession <TStepId, TData> session) #endif { try { #if NET35 || NOASYNC session.TransactionContext.SessionStorage.StepPrepared(session); #else await session.TransactionContext.SessionStorage.StepPrepared(session); #endif } catch (Exception e) { string info = string.Format("Transaction '{0}': an error occurred during notifying ste prepared.", session.TransactionContext.Info.Name); session.TransactionContext.Logger.ErrorFormat(e, info); session.StepEnumerator.MovePrevious(); #if NET35 || NOASYNC RunUndoOperation.RunUndo(new RunUndoContext <TStepId, TData>() #else await RunUndoOperation.RunUndo(new RunUndoContext <TStepId, TData>() #endif { Session = session, CaughtException = e, Result = ResultType.Failed }); #if NET35 || NOASYNC SessionEndPreparationOperation.PrepareEndSession(new SessionEndContext <TStepId, TData>() #else await SessionEndPreparationOperation.PrepareEndSession(new SessionEndContext <TStepId, TData>() #endif { Session = session, RunPostActions = false, Result = ResultType.Failed } .AddError(e)); } }
public static async Task ProcessStep <TStepId, TData>(this ITransactionSession <TStepId, TData> session) #endif { ITransactionStep <TStepId, TData> currentStep = session.StepEnumerator.CurrentStep; Stopwatch watch = new Stopwatch(); try { watch.Start(); #if NET35 || NOASYNC currentStep.StepAction(session.StepEnumerator.Data, session); #else if (currentStep.StepAction != null) { currentStep.StepAction(session.StepEnumerator.Data, session); } else { await currentStep.AsyncStepAction(session.StepEnumerator.Data, session); } #endif watch.Stop(); if (session.ShouldLogStepExecution()) { session.TransactionContext .Logger .LogExecutionTime( watch.Elapsed, "Transaction '{0}': execution time for step '{1}' with id '{2}'.", session.TransactionContext.Info.Name, session.StepEnumerator.CurrentStepIndex, currentStep.Id); } if (session.Cancelled) { session.TransactionContext .Logger .InfoFormat("Transaction '{0}' cancelled.", session.TransactionContext.Info.Name); #if NET35 || NOASYNC RunUndoOperation.RunUndo(new RunUndoContext <TStepId, TData>() #else await RunUndoOperation.RunUndo(new RunUndoContext <TStepId, TData>() #endif { Session = session, Result = ResultType.Cancelled }); } } catch (Exception e) { watch.Stop(); string info = string.Format("Transaction '{0}': an error occurred during processing step '{1}' with id '{2}', execution time '{3}'.", session.TransactionContext.Info.Name, session.StepEnumerator.CurrentStepIndex, currentStep.Id, watch.Elapsed); session.TransactionContext.Logger.ErrorFormat(e, info); #if NET35 || NOASYNC RunUndoOperation.RunUndo(new RunUndoContext <TStepId, TData>() #else await RunUndoOperation.RunUndo(new RunUndoContext <TStepId, TData>() #endif { Session = session, CaughtException = e, Result = ResultType.Failed }); #if NET35 || NOASYNC SessionEndPreparationOperation.PrepareEndSession(new SessionEndContext <TStepId, TData>() #else await SessionEndPreparationOperation.PrepareEndSession(new SessionEndContext <TStepId, TData>() #endif { Session = session, RunPostActions = false, Result = ResultType.Failed } .AddError(e)); } }