- Timestamp:
- 03/25/10 19:57:44 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Server/3.2/ServiceCallInterception.cs
r3203 r3220 9 9 10 10 namespace HeuristicLab.Hive.Server { 11 class ServiceCallInterception: IMethodInterceptor { 12 #region IMethodInterceptor Members 11 internal class ServiceCallInterception : IMethodInterceptor { 12 13 private bool useTransactions = false; 13 14 14 15 public object Invoke(IMethodInvocation invocation) { 15 Console.WriteLine(DateTime.Now + " - " + Thread.CurrentThread.ManagedThreadId + " - Entering Method " + invocation.Method.Name); 16 Console.WriteLine(DateTime.Now + " - " + Thread.CurrentThread.ManagedThreadId + " - Entering Method " + 17 invocation.Method.Name); 16 18 17 Object obj; 18 19 using (TransactionScope scope = new TransactionScope()) { 19 if(ContextFactory.Context != null) { 20 Console.WriteLine("Error - Not null context found - why wasn't this disposed?"); 21 ContextFactory.Context = null; 22 } 23 24 Object obj = null; 25 26 if (invocation.Method.Name.Equals("SendStreamedJob") || invocation.Method.Name.Equals("StoreFinishedJobResultStreamed")) { 27 ContextFactory.Context.Connection.Open(); 28 if(useTransactions) 29 ContextFactory.Context.Transaction = ContextFactory.Context.Connection.BeginTransaction(); 20 30 try { 21 31 obj = invocation.Proceed(); 22 scope.Complete(); 23 } finally { 32 Console.WriteLine("leaving context open for Streaming"); 33 } 34 catch (Exception e) { 35 Console.WriteLine(e); 24 36 ContextFactory.Context.Dispose(); 25 Console.WriteLine("setting old context null");26 37 ContextFactory.Context = null; 27 Console.WriteLine("Disposing old Context"); 38 } 39 } else { 40 if(useTransactions) { 41 using (TransactionScope scope = new TransactionScope()) { 42 try { 43 obj = invocation.Proceed(); 44 scope.Complete(); 45 } 46 catch (Exception e) { 47 Console.WriteLine("Exception Occured"); 48 Console.WriteLine(e); 49 } 50 finally { 51 ContextFactory.Context.Dispose(); 52 Console.WriteLine("setting old context null"); 53 ContextFactory.Context = null; 54 Console.WriteLine("Disposing old Context"); 55 } 56 } 57 } else { 58 try { 59 obj = invocation.Proceed(); 60 } 61 catch (Exception e) { 62 Console.WriteLine("Exception Occured"); 63 Console.WriteLine(e); 64 } 65 finally { 66 ContextFactory.Context.Dispose(); 67 Console.WriteLine("setting old context null"); 68 ContextFactory.Context = null; 69 Console.WriteLine("Disposing old Context"); 70 } 28 71 } 29 } 30 Console.WriteLine(DateTime.Now + " - " + Thread.CurrentThread.ManagedThreadId + " - Leaving Method " + invocation.Method.Name); 72 } 73 Console.WriteLine(DateTime.Now + " - " + Thread.CurrentThread.ManagedThreadId + " - Leaving Method " + 74 invocation.Method.Name); 75 31 76 return obj; 32 77 } 33 34 #endregion35 78 } 36 79 } 80 81
Note: See TracChangeset
for help on using the changeset viewer.