private void OnErrorIntercept(object[] aspects, ExceptionInterceptArgs e) { if (aspects == null) { return; } foreach (IInterception loopAttribute in aspects) { if (loopAttribute is IExceptionInterception) { ((IExceptionInterception)loopAttribute).OnException(e); } } }
//Attribute olarak eklenen metot çağırıldığında çalışacak olan metotdur. public override IMessage Invoke(IMessage msg) { var methodCallMessage = msg as IMethodCallMessage; ReturnMessage returnMessage = null; object[] interceptions = null; InterceptArgs e = CreateEventArgs(methodCallMessage); try { interceptions = GetInterceptions(methodCallMessage); // PreInterceptionlarımız çalıştırıyoruz, cache tarzı geriye donen attribute varsa bunlardan donen sonucu alıyoruz PreInterceptArgs preArg = new PreInterceptArgs(e); object result = OnPreIntercept(interceptions, preArg); // OverrideReturnValue true ise esas metodu çalıştırmamıza gerek yok if (preArg.OverrideReturnValue) { returnMessage = new ReturnMessage(result, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage); } else { // boş resultımız olduğuna göre ilgili metodu çalıştırabiliriz result = methodCallMessage.MethodBase.Invoke(new T(), methodCallMessage.InArgs); returnMessage = new ReturnMessage(result, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage); } OnPostIntercept(interceptions, new PostInterceptArgs(e, result)); // PostInterceptionlarımız çalıştırdıktan sonra artık geriye çıktıyı dönebiliriz. return(returnMessage); } catch (Exception ex) { var exArg = new ExceptionInterceptArgs(e, ex); OnErrorIntercept(interceptions, exArg); return(new ReturnMessage(exArg.Ex, methodCallMessage)); } }
public void OnException(ExceptionInterceptArgs e) { handler.Handle(e.Ex); e.Ex = new ApplicationException("Şuan işleminizi gerçekleştiremiyoruz."); }
public void Handle(ExceptionInterceptArgs arg) { logger.Error(new ExceptionLog(arg.Ex)); }
public void Handle(ExceptionInterceptArgs arg) { logger.Log("BasicExceptionHandler => " + arg.ToString()); }