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 (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);
                }
            }
        }
 private void InvokeEntry(List<MethodBoundaryAttribute> attributes, MethodExecutionArgs args)
 {
     foreach (MethodBoundaryAttribute attr in attributes)
     {
         attr.OnEntry(args);
     }
 }
Example #3
0
 public override void OnException(MethodExecutionArgs args)
 {
     Console.WriteLine("Exception");
 }
Example #4
0
 public override void OnSuccess(MethodExecutionArgs args)
 {
     Console.WriteLine("Success");
 }
Example #5
0
 public override void OnEntry(MethodExecutionArgs args)
 {
     Console.WriteLine("Entry");
 }
 public virtual void OnEntry(MethodExecutionArgs args) { }
 public virtual void OnException(MethodExecutionArgs args) { }
 public virtual void OnExit(MethodExecutionArgs args) { }
 public virtual void OnSuccess(MethodExecutionArgs args) { }