private async Task <T> HandleAsyncWithResult <T>(Task <T> task, IInvocation invocation) { ServiceBase serviceBase = invocation.Request.Target as ServiceBase; try { T value = await task; LogAfter(invocation); serviceBase.CloseChannel(); indicator.IsServiceRunning = false; return(value); } catch (FaultException ex) { serviceBase.CloseChannel(); indicator.IsServiceRunning = false; if (ex.InnerException != null) { Log.Fatal("Falied to execute call ! ", ex.InnerException); throw ex.InnerException; } Log.Fatal("Falied to execute call ! ", ex); throw; } catch (Exception ex2) { serviceBase.CloseChannel(); indicator.IsServiceRunning = false; Log.Fatal("Falied to execute call ! ", ex2); throw; } }
public void Intercept(IInvocation invocation) { lock (lockThis) { LogBefore(invocation); indicator.IsServiceRunning = true; ServiceBase serviceBase = invocation.Request.Target as ServiceBase; serviceBase.OpenChannel(); try { var delegateType = GetDelegateType(invocation); if (delegateType == MethodType.Synchronous) { invocation.Proceed(); LogAfter(invocation); serviceBase.CloseChannel(); indicator.IsServiceRunning = false; } if (delegateType == MethodType.AsyncAction) { invocation.Proceed(); invocation.ReturnValue = HandleAsync((Task)invocation.ReturnValue, invocation); } if (delegateType == MethodType.AsyncFunction) { invocation.Proceed(); ExecuteHandleAsyncWithResultUsingReflection(invocation); } LogAfter(invocation); } catch (FaultException ex) { serviceBase.CloseChannel(); indicator.IsServiceRunning = false; if (ex.InnerException != null) { Log.Fatal("Falied to execute call ! ", ex.InnerException); throw ex.InnerException; } Log.Fatal("Falied to execute call ! ", ex); throw; } catch (EndpointNotFoundException ex2) { serviceBase.CloseChannel(); indicator.IsServiceRunning = false; Log.Fatal("Falied to execute call ! ", ex2); throw new TimeoutException(); } catch (Exception ex2) { serviceBase.CloseChannel(); indicator.IsServiceRunning = false; Log.Fatal("Falied to execute call ! ", ex2); throw; } } }
private async Task HandleAsync(Task task, IInvocation invocation) { ServiceBase serviceBase = invocation.Request.Target as ServiceBase; try { await task; LogAfter(invocation); serviceBase.CloseChannel(); indicator.IsServiceRunning = false; } catch (FaultException ex) { serviceBase.CloseChannel(); indicator.IsServiceRunning = false; if (ex.InnerException != null) { Log.Fatal("Falied to execute call ! ", ex.InnerException); throw ex.InnerException; } Log.Fatal("Falied to execute call ! ", ex); throw; } catch (EndpointNotFoundException ex2) { serviceBase.CloseChannel(); indicator.IsServiceRunning = false; Log.Fatal("Falied to execute call ! ", ex2); throw new TimeoutException(); } catch (Exception ex2) { serviceBase.CloseChannel(); indicator.IsServiceRunning = false; Log.Fatal("Falied to execute call ! ", ex2); throw; } }