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);
     }
 }
Пример #3
0
 public override void OnException(MethodExecutionArgs args)
 {
     Console.WriteLine("Exception");
 }
Пример #4
0
 public override void OnSuccess(MethodExecutionArgs args)
 {
     Console.WriteLine("Success");
 }
Пример #5
0
 public override void OnEntry(MethodExecutionArgs args)
 {
     Console.WriteLine("Entry");
 }
Пример #6
0
 public virtual void OnEntry(MethodExecutionArgs args) { }
Пример #7
0
 public virtual void OnException(MethodExecutionArgs args) { }
Пример #8
0
 public virtual void OnExit(MethodExecutionArgs args) { }
Пример #9
0
 public virtual void OnSuccess(MethodExecutionArgs args) { }