Ejemplo n.º 1
0
        /// <summary>
        /// Handles method call interception.
        /// </summary>
        /// <param name="methodCallMessage">Remoting <see cref="IMethodCallMessage"/> that contains information about the method call.</param>
        /// <param name="allowInterception">Specifies whether call interception is allowed.</param>
        /// <returns><see cref="ReturnMessage"/>, if the call is intercepted, otherwise, false.</returns>
        private ReturnMessage HandleCallInterception(IMethodCallMessage methodCallMessage, bool allowInterception)
        {
            if (!allowInterception || CallInterceptor.IsPaused)
            {
                return(null);
            }

            var interceptor = _connection.CallInterceptors.FindMatchingInterceptor(_interfaceType, _uniqueName, methodCallMessage);

            if (interceptor != null && interceptor.OnInterception != null)
            {
                var interceptionData = new CallInterceptionData(methodCallMessage.Args, HandleRemoteInvocation, methodCallMessage);
                interceptor.OnInterception(interceptionData);

                if (interceptionData.Intercepted)
                {
                    return(new ReturnMessage(interceptionData.ReturnValue, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage));
                }
            }

            // Remote call is not intercepted or interceptor doesn't exist
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles method call interception.
        /// </summary>
        /// <param name="methodCallMessage">Remoting <see cref="IMethodCallMessage"/> that contains information about the method call.</param>
        /// <param name="allowInterception">Specifies whether call interception is allowed.</param>
        /// <returns><see cref="ReturnMessage"/>, if the call is intercepted, otherwise, false.</returns>
        private ReturnMessage HandleCallInterception(IMethodCallMessage methodCallMessage, bool allowInterception)
        {
            if (!allowInterception || CallInterceptor.IsPaused)
                return null;

            var interceptor = _connection.CallInterceptors.FindMatchingInterceptor(_interfaceType, _uniqueName, methodCallMessage);
            if (interceptor != null && interceptor.OnInterception != null)
            {
                var interceptionData = new CallInterceptionData(methodCallMessage.Args, InvokeRemoteMethod, methodCallMessage);
                interceptor.OnInterception(interceptionData);

                if (interceptionData.Intercepted)
                    return new ReturnMessage(interceptionData.ReturnValue, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage);
            }

            // Remote call is not intercepted or interceptor doesn't exist
            return null;
        }