Пример #1
0
        /// <summary>
        /// Gets the list of
        /// <see langword="static"/> interceptors and dynamic interception
        /// advice that may apply to the supplied <paramref name="method"/>
        /// invocation.
        /// </summary>
        /// <param name="config">The proxy configuration.</param>
        /// <param name="proxy">The object proxy.</param>
        /// <param name="method">
        /// The method to evaluate interceptors for.
        /// </param>
        /// <param name="targetType">
        /// The <see cref="System.Type"/> of the target object.
        /// </param>
        /// <returns>
        /// A <see cref="System.Collections.IList"/> of
        /// <see cref="AopAlliance.Intercept.IMethodInterceptor"/> (if there's
        /// a dynamic method matcher that needs evaluation at runtime).
        /// </returns>
        public static IList <object> CalculateInterceptors(
            IAdvised config, object proxy, MethodInfo method, Type targetType)
        {
            IList <object> interceptors = new List <object>(config.Advisors.Count);

            foreach (IAdvisor advisor in config.Advisors)
            {
                if (advisor is IPointcutAdvisor)
                {
                    IPointcutAdvisor pointcutAdvisor = (IPointcutAdvisor)advisor;
                    if (pointcutAdvisor.Pointcut.TypeFilter.Matches(targetType))
                    {
                        IMethodInterceptor interceptor =
                            (IMethodInterceptor)GlobalAdvisorAdapterRegistry.Instance.GetInterceptor(advisor);
                        IMethodMatcher mm = pointcutAdvisor.Pointcut.MethodMatcher;
                        if (mm.Matches(method, targetType))
                        {
                            if (mm.IsRuntime)
                            {
                                // Creating a new object instance in the GetInterceptor() method
                                // isn't a problem as we normally cache created chains...
                                interceptors.Add(new InterceptorAndDynamicMethodMatcher(interceptor, mm));
                            }
                            else
                            {
                                interceptors.Add(interceptor);
                            }
                        }
                    }
                }
            }
            return(interceptors);
        }
Пример #2
0
 public static void RegisterMethodMatcher(IMethodMatcher methodMatcher)
 {
     if (methodMatcher == null)
     {
         throw new ArgumentNullException("methodMatcher");
     }
     InternalDependencies.MethodMatcher = methodMatcher;
 }
Пример #3
0
 public ActionConvention(IOptions <JsonRpcOptions> options, IEnumerable <IJsonRpcSerializer> serializers, IMethodMatcher methodMatcher, IJsonRpcRoutes jsonRpcRoutes, ILogger <ActionConvention> log)
 {
     this.serializers     = serializers;
     this.methodMatcher   = methodMatcher;
     this.jsonRpcRoutes   = jsonRpcRoutes;
     this.log             = log;
     defaultMethodOptions = options.Value.DefaultMethodOptions;
 }
        public void DynamicMethodMatchWithTypeAndMethodNameSpecifiedInCtorNoMatch()
        {
            ControlFlowPointcut cut    = new ControlFlowPointcut(GetType(), "KiloRiley");
            IMethodMatcher      filter = cut.MethodMatcher;

            Assert.IsFalse(filter.Matches(null, null, null),             // args are ingored in this impl...
                           "Must not match - under cflow of Type specified in ctor, but no match on method name.");
        }
        public void DynamicMethodMatchWithJustTypeSpecifiedInCtor()
        {
            ControlFlowPointcut cut    = new ControlFlowPointcut(GetType());
            IMethodMatcher      filter = cut.MethodMatcher;

            Assert.IsTrue(filter.Matches(null, null, null),             // args are ingored in this impl...
                          "Must match - under cflow of Type specified in ctor");
        }
Пример #6
0
        /// <summary>
        /// 构造方法。
        /// </summary>
        public Pointcut(ITypeFilter typeFilter, IMethodMatcher methodMatcher)
        {
            Check.MustNotNull(typeFilter, "typeFilter");
            Check.MustNotNull(methodMatcher, "methodMatcher");

            this.TypeFilter = typeFilter;
            this.MethodMatcher = methodMatcher;
        }
Пример #7
0
        public void Deserialization()
        {
            IMethodMatcher deserializedVersion
                = (IMethodMatcher)SerializationTestUtils.SerializeAndDeserialize(
                      TrueMethodMatcher.True);

            Assert.IsTrue(Object.ReferenceEquals(TrueMethodMatcher.True, deserializedVersion),
                          "Singleton instance not being deserialized correctly");
        }
Пример #8
0
        public void Setup()
        {
            tunnel               = Substitute.For <ITunnel>();
            methodMatcher        = Substitute.For <IMethodMatcher>();
            RabbitTunnel.Factory = Substitute.For <TunnelFactory>();
            RabbitTunnel.Factory.Create(Arg.Any <string>()).Returns(tunnel);
            Global.DefaultWatcher = Substitute.For <IRabbitWatcher>();

            InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>();
            InternalDependencies.MethodMatcher  = methodMatcher;
        }
Пример #9
0
        public void Setup()
        {
            tunnel = Substitute.For<ITunnel>();
            methodMatcher = Substitute.For<IMethodMatcher>();
            RabbitTunnel.Factory = Substitute.For<TunnelFactory>();
            RabbitTunnel.Factory.Create(Arg.Any<string>()).Returns(tunnel);
            Global.DefaultWatcher = Substitute.For<IRabbitWatcher>();

            InternalDependencies.RpcQueueHelper = Substitute.For<IRpcQueueHelper>();
            InternalDependencies.MethodMatcher = methodMatcher;
        }
        public void StaticMethodMatchImplAlwaysMatchesRegardless()
        {
            Type oneType               = typeof(One);
            ControlFlowPointcut cut    = new ControlFlowPointcut(oneType);
            IMethodMatcher      filter = cut.MethodMatcher;
            MethodInfo          method = oneType.GetMethod("GetAge");

            Assert.IsTrue(filter.Matches(method, oneType),
                          "Must always match regardless of the supplied arguments.");
            Assert.IsTrue(filter.Matches(method, GetType()),
                          "Must always match even if the supplied argument method and Type are not " +
                          "a match for the name and Type supplied in the ctor.");
            Assert.IsTrue(filter.Matches(null, null),             // args are ingored in this impl...
                          "Must always match even if the supplied arguments are null");
        }
Пример #11
0
 /// <summary>
 /// Performs the least expensive check for a match.
 /// </summary>
 /// <param name="pointcut">
 /// The <see cref="Spring.Aop.IPointcut"/> to be evaluated.
 /// </param>
 /// <param name="method">The candidate method.</param>
 /// <param name="targetType">
 /// The target <see cref="System.Type"/>.
 /// </param>
 /// <param name="args">The arguments to the method</param>
 /// <returns><see langword="true"/> if there is a runtime match.</returns>
 /// <seealso cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
 public static bool Matches(
     IPointcut pointcut, MethodInfo method, Type targetType, object[] args)
 {
     if (pointcut != null)
     {
         if (pointcut == TruePointcut.True)
         {
             return(true);
         }
         if (pointcut.TypeFilter.Matches(targetType))
         {
             IMethodMatcher mm = pointcut.MethodMatcher;
             if (mm.Matches(method, targetType))
             {
                 return(mm.IsRuntime ? mm.Matches(method, targetType, args) : true);
             }
         }
     }
     return(false);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AttributeMatchingPointcut"/> class for the given
        /// attribute type
        /// </summary>
        /// <param name="classAttributeType">The attribute type to look for at the class level.</param>
        /// <param name="methodAttributeType">The attribute type to look for at the method attribute.</param>
        public AttributeMatchingPointcut(Type classAttributeType, Type methodAttributeType)
        {
            AssertUtils.IsTrue(classAttributeType != null || methodAttributeType != null,
                               "Either Type attribute type or Method attribute type needs to be specified (or both)");

            if (classAttributeType != null)
            {
                this.typeFilter = new AttributeTypeFilter(classAttributeType);
            } else
            {
                this.typeFilter = TrueTypeFilter.True;
            }

            if (methodAttributeType != null)
            {
                this.methodMatcher = new AttributeMethodMatcher(methodAttributeType);
            } else
            {
                this.methodMatcher = TrueMethodMatcher.True;
            }
        }
Пример #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AttributeMatchingPointcut"/> class for the given
        /// attribute type
        /// </summary>
        /// <param name="classAttributeType">The attribute type to look for at the class level.</param>
        /// <param name="methodAttributeType">The attribute type to look for at the method attribute.</param>
        public AttributeMatchingPointcut(Type classAttributeType, Type methodAttributeType)
        {
            AssertUtils.IsTrue(classAttributeType != null || methodAttributeType != null,
                               "Either Type attribute type or Method attribute type needs to be specified (or both)");

            if (classAttributeType != null)
            {
                this.typeFilter = new AttributeTypeFilter(classAttributeType);
            }
            else
            {
                this.typeFilter = TrueTypeFilter.True;
            }

            if (methodAttributeType != null)
            {
                this.methodMatcher = new AttributeMethodMatcher(methodAttributeType);
            }
            else
            {
                this.methodMatcher = TrueMethodMatcher.True;
            }
        }
Пример #14
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Oragon.Spring.Aop.Support.ComposablePointcut"/> class
 /// that uses the supplied <paramref name="typeFilter"/> and
 /// <paramref name="methodMatcher"/>.
 /// </summary>
 /// <param name="typeFilter">
 /// The type filter to use.
 /// </param>
 /// <param name="methodMatcher">
 /// The method matcher to use.
 /// </param>
 public ComposablePointcut(ITypeFilter typeFilter, IMethodMatcher methodMatcher)
 {
     _typeFilter    = typeFilter;
     _methodMatcher = methodMatcher;
 }
Пример #15
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Oragon.Spring.Aop.Support.ComposablePointcut"/> class
 /// that matches all the methods on all <see cref="System.Type"/>s.
 /// </summary>
 public ComposablePointcut()
 {
     _typeFilter    = TrueTypeFilter.True;
     _methodMatcher = TrueMethodMatcher.True;
 }
Пример #16
0
 /// <summary>
 /// Changes current pointcut to intersection of the current and supplied pointcut
 /// </summary>
 /// <param name="other">pointcut to diff against</param>
 /// <returns>updated pointcut</returns>
 public virtual ComposablePointcut Intersection(IPointcut other)
 {
     _typeFilter    = TypeFilters.Intersection(_typeFilter, other.TypeFilter);
     _methodMatcher = MethodMatchers.Intersection(_methodMatcher, other.MethodMatcher);
     return(this);
 }
Пример #17
0
 public GenericInvokerFilter(IMethodMatcher methodMatcher, IInvoker masterInvoker)
 {
     this.methodMatcher = methodMatcher;
     this.masterInvoker = masterInvoker;
 }
 public static bool IsMatchToFlowControlled(this IMethodMatcher methodMatcher, (Type, string)[] parameterTypeAndNames,
Пример #19
0
 public IntersectionMethodMatcher(IMethodMatcher a, IMethodMatcher b)
 {
     this.a = a;
     this.b = b;
 }
 public JsonRpcDescriptionProvider(IMethodMatcher methodMatcher, ITypeEmitter typeEmitter, IOptions <JsonRpcOptions> options)
 {
     this.methodMatcher = methodMatcher;
     this.typeEmitter   = typeEmitter;
     this.options       = options.Value;
 }
 public FieldMappedMethod(MethodInfo methodInfo, string fieldName)
 {
     this.fieldName = fieldName;
     methodMatcher  = new MatchMethodInfoExact(methodInfo);
 }
		public InterceptorAndDynamicMethodMatcher(IMethodInterceptor interceptor, IMethodMatcher methodMatcher)
		{
			this.Interceptor = interceptor;
			this.MethodMatcher = methodMatcher;
		}
Пример #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AttributeMatchingPointcut"/> class for the
 /// given attribute type
 /// </summary>
 /// <param name="attributeType">Type of the attribute.</param>
 /// <param name="checkInherited">if set to <c>true</c> [check inherited].</param>
 public AttributeMatchingPointcut(Type attributeType, bool checkInherited)
 {
     ValidateAttributeTypeArgument(attributeType);
     this.typeFilter    = new AttributeTypeFilter(attributeType, checkInherited);
     this.methodMatcher = TrueMethodMatcher.True;
 }
 protected MethodDefinition(string name, IMethodMatcher methodMatcher)
 {
     Name          = name;
     MethodMatcher = methodMatcher ?? new MatchNothing();
 }
 public InterceptorAndDynamicMethodMatcher(IMethodInterceptor interceptor, IMethodMatcher methodMatcher)
 {
     this.Interceptor   = interceptor;
     this.MethodMatcher = methodMatcher;
 }
Пример #26
0
 public UnionMethodMatcher(IMethodMatcher a, IMethodMatcher b)
 {
     this.a = a;
     this.b = b;
 }
Пример #27
0
		/// <summary>
		/// Creates a new instance of the
		/// <see cref="Spring.Aop.Support.UnionPointcut"/> class.
		/// </summary>
		/// <param name="firstPointcut">The first pointcut.</param>
		/// <param name="secondPointcut">The second pointcut.</param>
		public UnionPointcut(IPointcut firstPointcut, IPointcut secondPointcut)
		{
			this.a = firstPointcut;
			this.b = secondPointcut;
			this.mm = new PointcutUnionMethodMatcher(this);
		}
Пример #28
0
		/// <summary>
		/// Creates a new <see cref="Spring.Aop.IMethodMatcher"/> that is the
		/// intersection of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s.
		/// </summary>
		/// <remarks>
		/// <p>
		/// The newly created matcher will match only those methods that both
		/// of the supplied matchers would match.
		/// </p>
		/// </remarks>
		/// <param name="firstMatcher">The first method matcher.</param>
		/// <param name="secondMatcher">The second method matcher.</param>
		/// <returns>
		/// A new <see cref="Spring.Aop.IMethodMatcher"/> that is the
		/// intersection of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s
		/// </returns>
		public static IMethodMatcher Intersection(
			IMethodMatcher firstMatcher, IMethodMatcher secondMatcher)
		{
			return new IntersectionMethodMatcher(firstMatcher, secondMatcher);
		}
Пример #29
0
			public IntersectionMethodMatcher(IMethodMatcher a, IMethodMatcher b)
			{
				this.a = a;
				this.b = b;
			}
Пример #30
0
		/// <summary>
		/// Changes the current method matcher to be the intersection of the existing matcher
		/// and the supplied <paramref name="matcher"/>.
		/// </summary>
		/// <param name="matcher">The matcher to diff against.</param>
		/// <returns>
		/// The intersection of the existing matcher and the supplied <paramref name="matcher"/>.
		/// </returns>
		public virtual ComposablePointcut Intersection(IMethodMatcher matcher)
		{
			_methodMatcher = MethodMatchers.Intersection(_methodMatcher, matcher);
			return this;
		}
Пример #31
0
			public UnionMethodMatcher(IMethodMatcher a, IMethodMatcher b)
			{
				this.a = a;
				this.b = b;
			}
Пример #32
0
		/// <summary>
		/// Changes current pointcut to intersection of the current and supplied pointcut
		/// </summary>
		/// <param name="other">pointcut to diff against</param>
		/// <returns>updated pointcut</returns>
		public virtual ComposablePointcut Intersection(IPointcut other)
		{
			_typeFilter = TypeFilters.Intersection(_typeFilter, other.TypeFilter);
			_methodMatcher = MethodMatchers.Intersection(_methodMatcher, other.MethodMatcher);
			return this;
		}
Пример #33
0
 /// <summary>
 /// Creates a new <see cref="Spring.Aop.IMethodMatcher"/> that is the
 /// intersection of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s.
 /// </summary>
 /// <remarks>
 /// <p>
 /// The newly created matcher will match only those methods that both
 /// of the supplied matchers would match.
 /// </p>
 /// </remarks>
 /// <param name="firstMatcher">The first method matcher.</param>
 /// <param name="secondMatcher">The second method matcher.</param>
 /// <returns>
 /// A new <see cref="Spring.Aop.IMethodMatcher"/> that is the
 /// intersection of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s
 /// </returns>
 public static IMethodMatcher Intersection(
     IMethodMatcher firstMatcher, IMethodMatcher secondMatcher)
 {
     return(new IntersectionMethodMatcher(firstMatcher, secondMatcher));
 }
Пример #34
0
		/// <summary>
		/// Creates a new instance of the 
		/// <see cref="Spring.Aop.Support.ComposablePointcut"/> class
		/// that matches all the methods on all <see cref="System.Type"/>s.
		/// </summary>
		public ComposablePointcut()
		{
			_typeFilter = TrueTypeFilter.True;
			_methodMatcher = TrueMethodMatcher.True;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="AttributeMatchingPointcut"/> class for the
 /// given attribute type
 /// </summary>
 /// <param name="attributeType">Type of the attribute.</param>
 /// <param name="checkInherited">if set to <c>true</c> [check inherited].</param>
 public AttributeMatchingPointcut(Type attributeType, bool checkInherited)
 {
     ValidateAttributeTypeArgument(attributeType);
     this.typeFilter = new AttributeTypeFilter(attributeType, checkInherited);
     this.methodMatcher = TrueMethodMatcher.True;
 }
Пример #36
0
		/// <summary>
		/// Creates a new instance of the 
		/// <see cref="Spring.Aop.Support.ComposablePointcut"/> class
		/// that uses the supplied <paramref name="typeFilter"/> and
		/// <paramref name="methodMatcher"/>.
		/// </summary>
		/// <param name="typeFilter">
		/// The type filter to use.
		/// </param>
		/// <param name="methodMatcher">
		/// The method matcher to use.
		/// </param>
		public ComposablePointcut(ITypeFilter typeFilter, IMethodMatcher methodMatcher)
		{
			_typeFilter = typeFilter;
			_methodMatcher = methodMatcher;
		}
Пример #37
0
 /// <summary>
 /// 构造方法。
 /// </summary>
 public Pointcut(IMethodMatcher methodMatcher)
     : this(TrueTypeFilter.True, methodMatcher)
 {
 }
Пример #38
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Aop.Support.UnionPointcut"/> class.
 /// </summary>
 /// <param name="firstPointcut">The first pointcut.</param>
 /// <param name="secondPointcut">The second pointcut.</param>
 public UnionPointcut(IPointcut firstPointcut, IPointcut secondPointcut)
 {
     this.a  = firstPointcut;
     this.b  = secondPointcut;
     this.mm = new PointcutUnionMethodMatcher(this);
 }
Пример #39
0
 /// <summary>
 /// Changes the current method matcher to be the intersection of the existing matcher
 /// and the supplied <paramref name="matcher"/>.
 /// </summary>
 /// <param name="matcher">The matcher to diff against.</param>
 /// <returns>
 /// The intersection of the existing matcher and the supplied <paramref name="matcher"/>.
 /// </returns>
 public virtual ComposablePointcut Intersection(IMethodMatcher matcher)
 {
     _methodMatcher = MethodMatchers.Intersection(_methodMatcher, matcher);
     return(this);
 }
Пример #40
0
 protected Method(string name, IMethodMatcher methodMatcher, IParameter parameter = null)
 {
     Name           = name;
     MethodMatcher  = methodMatcher ?? new MatchNothing();
     this.parameter = parameter;
 }