using System; using System.Transactions; using HeuristicLab.Services.Hive.Common; namespace HeuristicLab.Services.Hive.DataAccess { public class TransactionManager { public void UseTransaction(Action call) { TransactionScope transaction = CreateTransaction(); try { call(); transaction.Complete(); } finally { transaction.Dispose(); } } public T UseTransaction(Func call) { TransactionScope transaction = CreateTransaction(); try { T result = call(); transaction.Complete(); return result; } finally { transaction.Dispose(); } } private static TransactionScope CreateTransaction() { return new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.IsolationLevelScope }); } } }