Esempio n. 1
0
        public override string Reverse <TItem>(TItem obj)
        {
            HandlerPipeline         pipeline = ((IInterceptingProxy)this).GetPipeline(reverse);
            VirtualMethodInvocation inputs   = new VirtualMethodInvocation(this, reverse, obj);
            IMethodReturn           result   = pipeline.Invoke(inputs, Reverse_DelegateImpl <TItem>);

            if (result.Exception != null)
            {
                throw result.Exception;
            }
            return((string)result.ReturnValue);
        }
Esempio n. 2
0
        public override int MethodWithRefParameters(int x, ref string y, float f)
        {
            HandlerPipeline         pipeline = ((IInterceptingProxy)this).GetPipeline(methodWithRefParameters);
            VirtualMethodInvocation inputs   = new VirtualMethodInvocation(this, methodWithRefParameters, x, y, f);
            IMethodReturn           result   = pipeline.Invoke(inputs, MethodWithRefParameters_Delegate);

            if (result.Exception != null)
            {
                throw result.Exception;
            }
            y = (string)result.Outputs[0];
            return((int)result.ReturnValue);
        }
Esempio n. 3
0
        public override void OutParams(int x, out int plusOne, out int timesTwo)
        {
            HandlerPipeline         pipeline = ((IInterceptingProxy)this).GetPipeline(outParams);
            VirtualMethodInvocation inputs   = new VirtualMethodInvocation(this, outParams, x, default(int), default(int));
            IMethodReturn           result   = pipeline.Invoke(inputs, OutParams_Delegate);

            if (result.Exception != null)
            {
                throw result.Exception;
            }
            plusOne  = (int)result.Outputs[0];
            timesTwo = (int)result.Outputs[1];
        }
Esempio n. 4
0
        public void ShouldBeInvokable()
        {
            PolicySet       policies = GetPolicies();
            HandlerPipeline pipeline =
                new HandlerPipeline(policies.GetHandlersFor(GetTargetMemberInfo()));

            IMethodReturn result = pipeline.Invoke(
                MakeCallMessage(),
                delegate(IMethodInvocation message, GetNextHandlerDelegate getNext)
            {
                return(MakeReturnMessage(message));
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(1, callCountHandler.CallCount);
            Assert.AreEqual(returnHandler.ValueToRewriteTo, (string)result.ReturnValue);
        }
Esempio n. 5
0
        public void ShouldBeInvokable()
        {
            IUnityContainer container = GetContainer();
            PolicySet policies = GetPolicies(container);
            HandlerPipeline pipeline 
                = new HandlerPipeline(policies.GetHandlersFor(GetTargetMemberInfo(), container));

            IMethodReturn result = pipeline.Invoke(
                MakeCallMessage(),
                delegate(IMethodInvocation message,
                         GetNextHandlerDelegate getNext)
                {
                    return MakeReturnMessage(message);
                });
            Assert.IsNotNull(result);
            Assert.AreEqual(1, callCountHandler.CallCount);
            Assert.AreEqual(returnHandler.ValueToRewriteTo, (string)result.ReturnValue);
        }
Esempio n. 6
0
        public override string AddUp(int x, int y)
        {
            HandlerPipeline         pipeline = ((IInterceptingProxy)this).GetPipeline(addUp);
            VirtualMethodInvocation inputs   = new VirtualMethodInvocation(this, addUp, x, y);
            IMethodReturn           result   = pipeline.Invoke(inputs, delegate(IMethodInvocation input, GetNextHandlerDelegate getNext)
            {
                try
                {
                    string returnValue = BaseAddUp((int)input.Inputs[0], (int)input.Inputs[1]);
                    return(input.CreateMethodReturn(returnValue, input.Inputs[0], input.Inputs[1]));
                }
                catch (Exception ex)
                {
                    return(input.CreateExceptionMethodReturn(ex));
                }
            });

            if (result.Exception != null)
            {
                throw result.Exception;
            }
            return((string)result.ReturnValue);
        }
Esempio n. 7
0
        public override void MethodOne()
        {
            HandlerPipeline pipeline = ((IInterceptingProxy)this).GetPipeline(methodOne);

            VirtualMethodInvocation inputs = new VirtualMethodInvocation(this, methodOne);
            IMethodReturn           result = pipeline.Invoke(inputs, delegate(IMethodInvocation input, GetNextHandlerDelegate getNext)
            {
                try
                {
                    BaseMethodOne();
                    return(input.CreateMethodReturn(null, input.Arguments));
                }
                catch (Exception ex)
                {
                    return(input.CreateExceptionMethodReturn(ex));
                }
            });

            if (result.Exception != null)
            {
                throw result.Exception;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Applies the policy injection handlers configured for the invoked method.
        /// </summary>
        /// <param name="input">Inputs to the current call to the target.</param>
        /// <param name="getNext">Delegate to execute to get the next delegate in the handler
        /// chain.</param>
        /// <returns>Return value from the target.</returns>
        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            Guard.ArgumentNotNull(input, "input");
            Guard.ArgumentNotNull(getNext, "getNext");

            HandlerPipeline pipeline = GetPipeline(input.MethodBase);

            return(pipeline.Invoke(
                       input,
                       delegate(IMethodInvocation policyInjectionInput, GetNextHandlerDelegate policyInjectionInputGetNext)
            {
                try
                {
                    return getNext()(policyInjectionInput, getNext);
                }
                catch (TargetInvocationException ex)
                {
                    // The outer exception will always be a reflection exception; we want the inner, which is
                    // the underlying exception.
                    return policyInjectionInput.CreateExceptionMethodReturn(ex.InnerException);
                }
            }));
        }
Esempio n. 9
0
        public override int CalculateAnswer()
        {
            HandlerPipeline         pipeline = ((IInterceptingProxy)this).GetPipeline(calculateAnswer);
            VirtualMethodInvocation inputs   = new VirtualMethodInvocation(this, calculateAnswer);
            IMethodReturn           result   = pipeline.Invoke(inputs, delegate(IMethodInvocation input, GetNextHandlerDelegate getNext)
            {
                try
                {
                    int returnValue = BaseCalculateAnswer();
                    return(input.CreateMethodReturn(returnValue, input.Arguments));
                }
                catch (Exception ex)
                {
                    return(input.CreateExceptionMethodReturn(ex));
                }
            });

            if (result.Exception != null)
            {
                throw result.Exception;
            }

            return((int)result.ReturnValue);
        }
Esempio n. 10
0
            public void TargetMethod()
            {
                MethodInfo targetMethod = typeof(IInterfaceOne).GetMethod("TargetMethod");

                VirtualMethodInvocation input         = new VirtualMethodInvocation(target, targetMethod);
                HandlerPipeline         pipeline      = ((IInterceptingProxy)this).GetPipeline(targetMethod);
                IMethodReturn           returnMessage = pipeline.Invoke(input, delegate(IMethodInvocation inputs, GetNextHandlerDelegate getNext)
                {
                    try
                    {
                        target.TargetMethod();
                        return(inputs.CreateMethodReturn(null));
                    }
                    catch (Exception ex)
                    {
                        return(inputs.CreateExceptionMethodReturn(ex));
                    }
                });

                if (returnMessage.Exception != null)
                {
                    throw returnMessage.Exception;
                }
            }