Beispiel #1
0
 private async Task Compensate(SagaExecutionContext <TContext> result, SagaStepContainer <TContext> step)
 {
     try
     {
         await step.Compensate(Context);
     }
     catch (Exception e2)
     {
         result.AddError(e2);
     }
 }
Beispiel #2
0
 private async Task Invoke_Error_Handling(SagaExecutionContext <TContext> result)
 {
     if (_errorAction != null)
     {
         _errorAction.Invoke(result.Errors);
     }
     else if (_errorFunc != null)
     {
         await _errorFunc.Invoke(result.Errors);
     }
 }
Beispiel #3
0
        public async Task <SagaExecutionContext <TContext> > Run()
        {
            var result = new SagaExecutionContext <TContext>();

            foreach (var step in Steps)
            {
                try
                {
                    Context = await step.Run(Context);

                    if (Context.HasErrors())
                    {
                        result.AddError(Context.Errors);
                        await Compensate(result, step);

                        if (Terminate_On_Error(step))
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    Log_Execution_Error(result, e);
                    await Compensate(result, step);

                    if (Terminate_On_Error(step))
                    {
                        break;
                    }
                }
            }

            if (result.HasErrors())
            {
                await Invoke_Error_Handling(result);

                return(result);
            }

            await Invoke_Success_Handling();

            return(result);
        }
Beispiel #4
0
 private static void Log_Execution_Error(SagaExecutionContext <TContext> result, Exception e)
 {
     result.AddError(e);
 }