public override R ExecuteWithResult <R>(Func <R> task, RollbackConfigurationType rollbackConfiguration) { if (Phase == Phase.NOT_STARTED) { Start(); } Assert.State(Phase == Phase.STARTED, () => $"The UnitOfWork has an incompatible phase: {Phase}"); R result; try { result = task(); } catch (Exception e) { if (rollbackConfiguration.RollBackOn(e)) { Rollback(e); } else { ExecutionResult = Task.FromException <object>(e); Commit(); } throw; } ExecutionResult = Task.FromResult((object)result); Commit(); return(result); }
public AbstractEventProcessor(string name, IEventHandlerInvoker eventHandlerInvoker, RollbackConfigurationType rollbackConfiguration, IErrorHandler errorHandler, IMessageMonitor messageMonitor) { EventHandlerInvoker = eventHandlerInvoker ?? throw new ArgumentNullException(nameof(name)); _rollbackConfiguration = rollbackConfiguration; _errorHandler = errorHandler ?? PropagatingErrorHandler.Instance; _messageMonitor = messageMonitor ?? NoOpMessageMonitor.Instance; Name = name ?? throw new ArgumentNullException(nameof(name)); }
public SubscribingEventProcessor(String name, IEventHandlerInvoker eventHandlerInvoker, RollbackConfigurationType rollbackConfiguration, ISubscribableMessageSource <IEventMessage> messageSource, IEventProcessingStrategy processingStrategy, IErrorHandler errorHandler, IMessageMonitor messageMonitor) : base(name, eventHandlerInvoker, rollbackConfiguration, errorHandler, messageMonitor) { _messageSource = messageSource; _processingStrategy = processingStrategy; }
public static bool RollBackOn(this RollbackConfigurationType value, Exception exception) { switch (value) { case RollbackConfigurationType.Never: return(false); case RollbackConfigurationType.AnyThrowable: return(true); case RollbackConfigurationType.UncheckedException: return(true); // TODO: confirm mapping of exceptions to .net types case RollbackConfigurationType.RuntimeExceptions: return(true); default: return(true); } }
public override R ExecuteWithResult <R>(Func <R> task, RollbackConfigurationType rollbackConfiguration) { if (Phase == Phase.NOT_STARTED) { Start(); } Assert.State(Phase == Phase.STARTED, () => $"The UnitOfWork has an incompatible phase: {Phase}"); R result = default(R); Exception exception = null; foreach (var processingContext in _processingContexts) { _processingContext = processingContext; try { result = task(); } catch (Exception e) { if (rollbackConfiguration.RollBackOn(e)) { Rollback(e); throw e; } ExecutionResult = Task.FromException <object>(e); exception = e; continue; } ExecutionResult = Task.FromResult <object>(result); } Commit(); if (exception != null) { throw exception; } return(result); }
public static void Execute(this IUnitOfWork unitOfWork, Action task, RollbackConfigurationType rollbackConfiguration) => unitOfWork.ExecuteWithResult(() => { task.Invoke(); return((object)null); }, rollbackConfiguration);