/// <summary>
        /// Method invoked <i>instead</i> of the method to which the aspect has been applied.
        /// </summary>
        /// <param name="args">Advice arguments.</param>
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            IExecuteActionStrategy strategy = null;

            if (CustomStrategy != null)
            {
                strategy = ExecuteActionStrategy.GetSingleton(CustomStrategy);
            }
            else if (_strategy != null)
            {
                switch (_strategy.Value)
                {
                case StandardExecutionStrategy.HandleReprocessableException:
                    strategy = ExecuteActionStrategy.HandleReprocessableException;
                    break;

                case StandardExecutionStrategy.NoReprocess:
                    strategy = ExecuteActionStrategy.NoReprocess;
                    break;

                case StandardExecutionStrategy.HandleUniqueConstraintViolation:
                    strategy = ExecuteActionStrategy.HandleUniqueConstraintViolation;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            GetDomain().ExecuteInternal(IsolationLevel, _transactionOpenMode, strategy, session => args.Proceed());
        }
예제 #2
0
 public void Parent(
     bool first,
     IsolationLevel?isolationLevel,
     TransactionOpenMode?transactionOpenMode,
     IExecuteActionStrategy strategy,
     Action <bool, IsolationLevel?, TransactionOpenMode?> action)
 {
     domain.WithStrategy(strategy).WithIsolationLevel(isolationLevel.GetValueOrDefault(IsolationLevel.RepeatableRead)).WithTransactionOpenMode(transactionOpenMode.GetValueOrDefault(TransactionOpenMode.New)).Execute(
         session => {
         session.EnsureTransactionIsStarted();
         new Bar2(session, DateTime.Now, Guid.NewGuid())
         {
             Name = Guid.NewGuid().ToString()
         };
         if (first)
         {
             if (wait1 != null && wait2 != null)
             {
                 wait1.Set();
                 wait2.WaitOne();
             }
         }
         else if (wait1 != null && wait2 != null)
         {
             wait2.Set();
             wait1.WaitOne();
         }
         action(first, isolationLevel, transactionOpenMode);
     });
 }
예제 #3
0
 /// <summary>
 /// Executes a reprocessable task.
 /// </summary>
 /// <param name="domain">The domain of the task.</param>
 /// <param name="isolationLevel">Isolation level of the task.</param>
 /// <param name="transactionOpenMode">Transaction open mode of the task.</param>
 /// <param name="strategy">Execute strategy of the task.</param>
 /// <param name="func">Task with T result.</param>
 /// <typeparam name="T">Return type of the task.</typeparam>
 /// <returns>The task result.</returns>
 public static T Execute <T>(
     this Domain domain,
     Func <Session, T> func,
     IExecuteActionStrategy strategy         = null,
     IsolationLevel isolationLevel           = IsolationLevel.Unspecified,
     TransactionOpenMode?transactionOpenMode = null)
 {
     return(ExecuteInternal(domain, isolationLevel, transactionOpenMode, strategy, func));
 }
예제 #4
0
 /// <summary>
 /// Executes a reprocessable task.
 /// </summary>
 /// <param name="domain">The domain of the task.</param>
 /// <param name="isolationLevel">Isolation level of the task.</param>
 /// <param name="transactionOpenMode">Transaction open mode of the task.</param>
 /// <param name="strategy">Execute strategy of the task.</param>
 /// <param name="action">Task with <see cref="Void"/> result.</param>
 public static void Execute(
     this Domain domain,
     Action <Session> action,
     IExecuteActionStrategy strategy         = null,
     IsolationLevel isolationLevel           = IsolationLevel.Unspecified,
     TransactionOpenMode?transactionOpenMode = null)
 {
     ExecuteInternal(domain, isolationLevel, transactionOpenMode, strategy, action);
 }
예제 #5
0
 internal static void ExecuteInternal(
     this Domain domain,
     IsolationLevel isolationLevel,
     TransactionOpenMode?transactionOpenMode,
     IExecuteActionStrategy strategy,
     Action <Session> action)
 {
     ExecuteInternal <object>(
         domain,
         isolationLevel,
         transactionOpenMode,
         strategy,
         a => {
         action(a);
         return(null);
     });
 }
예제 #6
0
        internal static T ExecuteInternal <T>(
            this Domain domain,
            IsolationLevel isolationLevel,
            TransactionOpenMode?transactionOpenMode,
            IExecuteActionStrategy strategy,
            Func <Session, T> func)
        {
            ReprocessingConfiguration config = domain.GetReprocessingConfiguration();

            if (strategy == null)
            {
                strategy = ExecuteActionStrategy.GetSingleton(config.DefaultExecuteStrategy);
            }
            if (transactionOpenMode == null)
            {
                transactionOpenMode = config.DefaultTransactionOpenMode;
            }
            return(strategy.Execute(new ExecutionContext <T>(domain, isolationLevel, transactionOpenMode.Value, func)));
        }
예제 #7
0
 public IExecuteConfiguration WithStrategy(IExecuteActionStrategy strategy)
 {
     Strategy = strategy;
     return(this);
 }
예제 #8
0
 /// <summary>
 /// Starts <see cref="IExecuteConfiguration"/> flow
 /// and provides <see cref="IExecuteActionStrategy"/> to use.
 /// </summary>
 /// <param name="domain">The domain.</param>
 /// <param name="strategy">Strategy to use.</param>
 /// <returns>Created <see cref="IExecuteConfiguration"/>.</returns>
 public static IExecuteConfiguration WithStrategy(this Domain domain, IExecuteActionStrategy strategy)
 {
     return(new ExecuteConfiguration(domain).WithStrategy(strategy));
 }