/// <summary> /// Initializes a new instance of the <see cref="TransactionRetryScope"/> class with the specified time-out value, and sets the specified transaction as the ambient transaction, /// so that transactional work performed inside the scope uses this transaction. Uses the specified retry policy. /// </summary> /// <param name="tx">The transaction to be set as the ambient transaction, so that transactional work performed inside the scope uses this transaction.</param> /// <param name="scopeTimeout">The TimeSpan after which the transaction scope times out and aborts the transaction.</param> /// <param name="retryPolicy">The retry policy that determines whether to retry the execution of the entire scope if a transient fault is encountered.</param> /// <param name="unitOfWork">A delegate that represents the executable unit of work that will be retried upon failure.</param> public TransactionRetryScope(Transaction tx, TimeSpan scopeTimeout, RetryPolicy retryPolicy, Action unitOfWork) { this.transactionScopeInit = () => new TransactionScope(tx, scopeTimeout); this.transactionScope = this.transactionScopeInit(); this.retryPolicy = retryPolicy; this.unitOfWork = unitOfWork; // Set up the callback method for the specified retry policy. this.InitializeRetryPolicy(); }
/// <summary> /// Initializes a new instance of the <see cref="TransactionRetryScope"/> class with the specified requirements and retry policy. /// </summary> /// <param name="scopeOption">One of the enumeration values that specifies the transaction requirements associated with this transaction scope.</param> /// <param name="transactionOptions">A <see cref="System.Transactions.TransactionOptions"/> structure that describes the transaction options to use if a new transaction is created. If an existing transaction is used, the time-out value in this parameter applies to the transaction scope. If that time expires before the scope is disposed, the transaction is aborted.</param> /// <param name="retryPolicy">The retry policy that determines whether to retry the execution of the entire scope if a transient fault is encountered.</param> /// <param name="unitOfWork">A delegate that represents the executable unit of work that will be retried upon failure.</param> public TransactionRetryScope(TransactionScopeOption scopeOption, TransactionOptions transactionOptions, RetryPolicy retryPolicy, Action unitOfWork) { this.transactionScopeInit = () => new TransactionScope(scopeOption, transactionOptions); this.transactionScope = this.transactionScopeInit(); this.retryPolicy = retryPolicy; this.unitOfWork = unitOfWork; // Set up the callback method for the specified retry policy. this.InitializeRetryPolicy(); }
/// <summary> /// Initializes a new instance of the <see cref="TransactionRetryScope"/> class with the specified retry policy and sets the specified transaction as the ambient transaction, /// so that transactional work done inside the scope uses this transaction. /// </summary> /// <param name="tx">The transaction to be set as the ambient transaction, so that transactional work done inside the scope uses this transaction.</param> /// <param name="retryPolicy">The retry policy defining whether to retry the execution of the entire scope should a transient fault be encountered.</param> /// <param name="unitOfWork">A delegate representing the executable unit of work which will be retried if fails.</param> public TransactionRetryScope(Transaction tx, RetryPolicy retryPolicy, Action unitOfWork) { this.transactionScopeInit = () => { return(new TransactionScope(tx)); }; this.transactionScope = this.transactionScopeInit(); this.retryPolicy = retryPolicy; this.unitOfWork = unitOfWork; // Set up the callback method for the specified retry policy. InitializeRetryPolicy(); }
/// <summary> /// Initializes a new instance of the <see cref="TransactionRetryScope"/> class with the specified time-out value, transaction scope options, and retry policy. /// Uses the ReadCommitted isolation level by default. /// </summary> /// <param name="scopeOption">One of the enumeration values that specifies the transaction requirements associated with this transaction scope.</param> /// <param name="scopeTimeout">The TimeSpan after which the transaction scope times out and aborts the transaction.</param> /// <param name="retryPolicy">The retry policy that determines whether to retry the execution of the entire scope if a transient fault is encountered.</param> /// <param name="unitOfWork">A delegate that represents the executable unit of work that will be retried upon failure.</param> public TransactionRetryScope(TransactionScopeOption scopeOption, TimeSpan scopeTimeout, RetryPolicy retryPolicy, Action unitOfWork) { this.transactionScopeInit = () => new TransactionScope( scopeOption, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = scopeTimeout }); this.transactionScope = this.transactionScopeInit(); this.RetryPolicy = retryPolicy; this.unitOfWork = unitOfWork; // Set up the callback method for the specified retry policy. this.InitializeRetryPolicy(); }
/// <summary> /// Initializes a new instance of the <see cref="TransactionRetryScope"/> class with the specified time-out value, transaction scope options, and retry policy. /// Uses the ReadCommitted isolation level by default. /// </summary> /// <param name="scopeOption">One of the enumeration values that specifies the transaction requirements associated with this transaction scope.</param> /// <param name="scopeTimeout">The TimeSpan after which the transaction scope times out and aborts the transaction.</param> /// <param name="retryPolicy">The retry policy that determines whether to retry the execution of the entire scope if a transient fault is encountered.</param> /// <param name="unitOfWork">A delegate that represents the executable unit of work that will be retried upon failure.</param> public TransactionRetryScope(TransactionScopeOption scopeOption, TimeSpan scopeTimeout, RetryPolicy retryPolicy, Action unitOfWork) { this.transactionScopeInit = () => { var txOptions = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = scopeTimeout }; return new TransactionScope(scopeOption, txOptions); }; this.transactionScope = this.transactionScopeInit(); this.retryPolicy = retryPolicy; this.unitOfWork = unitOfWork; // Set up the callback method for the specified retry policy. this.InitializeRetryPolicy(); }