- Timestamp:
- 03/16/11 13:32:39 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/TransactionManager.cs
r5055 r5708 1 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 2 using System.Transactions; 5 3 using HeuristicLab.Services.Hive.Common; 6 using System.Transactions;7 using HeuristicLab.Common;8 using HeuristicLab.Clients.Common;9 4 10 5 namespace HeuristicLab.Services.Hive.DataAccess { 11 6 public class TransactionManager { 12 public Disposable<TransactionScope> OpenTransaction() { 13 TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.IsolationLevelScope }); 14 var disposable = new Disposable<TransactionScope>(transaction); 15 disposable.OnDisposing += new EventHandler<EventArgs<object>>(disposable_OnDisposing); 16 return disposable; 7 public void UseTransaction(Action call) { 8 TransactionScope transaction = CreateTransaction(); 9 try { 10 call(); 11 transaction.Complete(); 12 } 13 finally { 14 transaction.Dispose(); 15 } 17 16 } 18 17 19 void disposable_OnDisposing(object sender, EventArgs<object> e) { 20 TransactionScope scope = (TransactionScope)e.Value; 21 scope.Complete(); 22 scope.Dispose(); 18 public T UseTransaction<T>(Func<T> call) { 19 TransactionScope transaction = CreateTransaction(); 20 try { 21 T result = call(); 22 transaction.Complete(); 23 return result; 24 } 25 finally { 26 transaction.Dispose(); 27 } 28 } 29 30 private static TransactionScope CreateTransaction() { 31 return new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.IsolationLevelScope }); 23 32 } 24 33 }
Note: See TracChangeset
for help on using the changeset viewer.