public void Intercept(IInvocation invocation)
        {
            MethodInfo methodInfo = invocation.MethodInvocationTarget;
            if (methodInfo == null)
            {
                methodInfo = invocation.Method;
            }

            List<MethodBoundaryAttribute> attributes = GetAttributes(methodInfo);

            if (attributes.Count == 0)
            {
                invocation.Proceed();
            }
            else
            {
                MethodExecutionArgs args = new MethodExecutionArgs(
                    invocation.InvocationTarget, invocation.Method, invocation.Arguments);

                InvokeEntry(attributes, args);

                try
                {
                    if (args.FlowBehavior == FlowBehavior.Return)
                        invocation.ReturnValue = args.ReturnValue;
                    else
                        invocation.Proceed();

                    args.ReturnValue = invocation.ReturnValue;

                    InvokeSuccess(attributes, args);
                }
                catch (System.Exception err)
                {
                    args.Exception = err;

                    InvokeException(attributes, args);

                    if (args.FlowBehavior == FlowBehavior.Return)
                    {
                        invocation.ReturnValue = args.ReturnValue;
                        return;
                    }

                    if (args.FlowBehavior != FlowBehavior.Continue)
                        throw err;
                }
                finally
                {
                    InvokeExit(attributes, args);
                }
            }
        }
예제 #2
0
 public virtual void OnEntry(MethodExecutionArgs args)
 {
 }
예제 #3
0
 public virtual void OnSuccess(MethodExecutionArgs args)
 {
 }
예제 #4
0
 public virtual void OnExit(MethodExecutionArgs args)
 {
 }
예제 #5
0
 public virtual void OnException(MethodExecutionArgs args)
 {
 }
 private void InvokeEntry(List<MethodBoundaryAttribute> attributes, MethodExecutionArgs args)
 {
     foreach (MethodBoundaryAttribute attr in attributes)
     {
         attr.OnEntry(args);
     }
 }