- Timestamp:
- 05/01/10 13:58:24 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Server/3.2/ServiceCallInterception.cs
r3220 r3578 7 7 using HeuristicLab.Hive.Server.LINQDataAccess; 8 8 using System.Transactions; 9 using HeuristicLab.Hive.Contracts; 10 using HeuristicLab.Tracing; 9 11 10 12 namespace HeuristicLab.Hive.Server { 11 13 internal class ServiceCallInterception : IMethodInterceptor { 12 14 13 private bool useTransactions = false;15 private const bool UseTransactions = true; 14 16 15 17 public object Invoke(IMethodInvocation invocation) { 16 Console.WriteLine(DateTime.Now + " - " + Thread.CurrentThread.ManagedThreadId + " - Entering Method " + 17 invocation.Method.Name); 18 Logger.Info("Entering Method: " + invocation.Method.Name); 18 19 19 20 if(ContextFactory.Context != null) { 20 Console.WriteLine("Error - Not null context found - why wasn't this disposed?"); 21 Logger.Info("Not null context found - why wasn't this disposed?"); 22 try { 23 Logger.Info("Trying to dispose"); 24 ContextFactory.Context.Dispose(); 25 } catch (Exception e) { 26 Logger.Error(e); 27 } 21 28 ContextFactory.Context = null; 22 29 } … … 26 33 if (invocation.Method.Name.Equals("SendStreamedJob") || invocation.Method.Name.Equals("StoreFinishedJobResultStreamed")) { 27 34 ContextFactory.Context.Connection.Open(); 28 if(useTransactions) 29 ContextFactory.Context.Transaction = ContextFactory.Context.Connection.BeginTransaction(); 35 if(UseTransactions) { 36 Logger.Debug("Opening Transaction"); 37 ContextFactory.Context.Transaction = ContextFactory.Context.Connection.BeginTransaction(ApplicationConstants.ISOLATION_LEVEL); 38 } else { 39 Logger.Debug("Not using a Transaction"); 40 } 30 41 try { 31 42 obj = invocation.Proceed(); 32 Console.WriteLine("leaving context open for Streaming");43 Logger.Info("leaving context open for streaming"); 33 44 } 34 catch (Exception e) { 35 Console.WriteLine(e);45 catch (Exception e) { 46 Logger.Error("Exception occured during method invocation", e); 36 47 ContextFactory.Context.Dispose(); 37 48 ContextFactory.Context = null; 38 49 } 39 50 } else { 40 if( useTransactions) {41 using (TransactionScope scope = new TransactionScope( )) {51 if(UseTransactions) { 52 using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE })) { 42 53 try { 54 Logger.Debug("Current Transaction Isolation level is: " + Transaction.Current.IsolationLevel); 43 55 obj = invocation.Proceed(); 44 56 scope.Complete(); 45 57 } 46 58 catch (Exception e) { 47 Console.WriteLine("Exception Occured"); 48 Console.WriteLine(e); 59 Logger.Error("Exception occured during method invocation", e); 49 60 } 50 61 finally { 51 62 ContextFactory.Context.Dispose(); 52 Console.WriteLine("setting old context null");63 Logger.Debug("Disposed Context"); 53 64 ContextFactory.Context = null; 54 Console.WriteLine("Disposing old Context");65 Logger.Debug("Set Context Null"); 55 66 } 56 67 } … … 60 71 } 61 72 catch (Exception e) { 62 Console.WriteLine("Exception Occured"); 63 Console.WriteLine(e); 73 Logger.Error("Exception occured during method invocation", e); 64 74 } 65 75 finally { 66 76 ContextFactory.Context.Dispose(); 67 Console.WriteLine("setting old context null");77 Logger.Debug("Disposed Context"); 68 78 ContextFactory.Context = null; 69 Console.WriteLine("Disposing old Context");79 Logger.Debug("Set Context Null"); 70 80 } 71 81 } 72 82 } 73 Console.WriteLine(DateTime.Now + " - " + Thread.CurrentThread.ManagedThreadId + " - Leaving Method " + 74 invocation.Method.Name); 83 Logger.Info("Leaving Method: " + invocation.Method.Name); 75 84 76 85 return obj;
Note: See TracChangeset
for help on using the changeset viewer.