/// <summary> /// Injects the introduced field. /// </summary> /// <param name="advice">The advice.</param> /// <param name="adviceMemberInfo">The member information.</param> /// <param name="advisedType">Type of the advised.</param> /// <exception cref="System.InvalidOperationException">Internal error, can not find matching introduced field</exception> private static void InjectIntroducedField(IAdvice advice, MemberInfo adviceMemberInfo, Type advisedType) { adviceMemberInfo.SetValue(advice, Activator.CreateInstance(adviceMemberInfo.GetMemberType(), advice, adviceMemberInfo)); }
public AppliedAdvice(IAdvice advice, IPointcut pointcut) { Guard.ArgumentIsNotNull(() => advice, () => pointcut); Advice = advice; _pointcut = pointcut; }
/// <summary> /// Returns an <see cref="Oragon.Spring.Aop.IAdvisor"/> wrapping the supplied /// <paramref name="advice"/>. /// </summary> /// <param name="advice"> /// The object that should be an advice, such as /// <see cref="Oragon.Spring.Aop.IBeforeAdvice"/> or /// <see cref="Oragon.Spring.Aop.IThrowsAdvice"/>. /// </param> /// <returns> /// An <see cref="Oragon.Spring.Aop.IAdvisor"/> wrapping the supplied /// <paramref name="advice"/>. Never returns <cref lang="null"/>. If /// the <paramref name="advice"/> parameter is an /// <see cref="Oragon.Spring.Aop.IAdvisor"/>, it will simply be returned. /// </returns> /// <exception cref="UnknownAdviceTypeException"> /// If no registered /// <see cref="Oragon.Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> can wrap /// the supplied <paramref name="advice"/>. /// </exception> public virtual IAdvisor Wrap(object advice) { if (advice is IAdvisor) { return((IAdvisor)advice); } if (!(advice is IAdvice)) { throw new UnknownAdviceTypeException(advice); } IAdvice adviceObject = (IAdvice)advice; if (adviceObject is IInterceptor) { // so well-known it doesn't even need an adapter... return(new DefaultPointcutAdvisor(adviceObject)); } foreach (IAdvisorAdapter adapter in this.adapters) { // check that it is supported... if (adapter.SupportsAdvice(adviceObject)) { return(new DefaultPointcutAdvisor(adviceObject)); } } throw new UnknownAdviceTypeException(advice); }
public async Task HandleUseAbilityAdvice(Unit unit, IAdvice advice) { var targetAndAbility = advice.ContextAccessor.GetContext() as AbilityWithTarget; if (targetAndAbility == null) { return; } var ability = unit.GetAbility(targetAndAbility.AbilityId); if (ability == null) { return; } var target = Level.GetUnitById(targetAndAbility.TargetUnitId); if (target == null) { return; } await UseAbilityOnTargetHandler.ExecutePhase(unit, target, ability); }
/// <summary> /// Gets priority level from the specified advice. /// </summary> /// <param name="advice">The advice.</param> /// <returns></returns> public static int GetLevel(IAdvice advice) { var priorityAttribute = advice.GetType().GetCustomAttributes(typeof (Priority), true).Cast<Priority>().SingleOrDefault(); if (priorityAttribute != null) return priorityAttribute.Level; return DefaultLevel; }
public async Task HandleMovementFirstAdvice(Unit unit, IAdvice movementAdvice, IAdvice[] allAdvice) { await HandleMovementAdvice(unit, movementAdvice); var attackOrHealAdvice = allAdvice.FirstOrDefault(x => x.AdviceId == AdviceVariableTypes.HealSelf || x.AdviceId == AdviceVariableTypes.HealOther || x.AdviceId == AdviceVariableTypes.UseAbility); if (attackOrHealAdvice == null) { return; } if (attackOrHealAdvice.AdviceId == AdviceVariableTypes.HealSelf) { await HandleUseAbilityAdvice(unit, attackOrHealAdvice); } else if (attackOrHealAdvice.AdviceId == AdviceVariableTypes.HealOther) { var healTarget = attackOrHealAdvice.ContextAccessor.GetContext() as Unit; var healAbility = unit.ActiveAbilities.First(x => x.DamageType == DamageTypes.LightDamage); await UseAbilityOnTargetHandler.ExecuteIfInRange(unit, healTarget, healAbility); } else { var targetAndAbility = attackOrHealAdvice.ContextAccessor.GetContext() as AbilityWithTarget; var targetUnit = Level.GetUnitById(targetAndAbility.TargetUnitId); var ability = unit.GetAbility(targetAndAbility.AbilityId); await UseAbilityOnTargetHandler.ExecuteIfInRange(unit, targetUnit, ability); } }
/*----------------------------------------------------------------------------------------*/ /// <summary> /// Begins a static interception definition. /// </summary> /// <param name="method">The method to intercept.</param> /// <returns>An advice builder.</returns> protected virtual TAdviceBuilder DoIntercept(MethodInfo method) { IAdvice advice = Kernel.Components.AdviceFactory.Create(method); Kernel.Components.AdviceRegistry.Register(advice); return(CreateAdviceBuilder(advice)); }
/*----------------------------------------------------------------------------------------*/ /// <summary> /// Begins a dynamic interception definition. /// </summary> /// <param name="condition">The condition to evaluate to determine if a request should be intercepted.</param> /// <returns>An advice builder.</returns> protected virtual TAdviceBuilder DoIntercept(ICondition <IRequest> condition) { IAdvice advice = Kernel.Components.AdviceFactory.Create(condition); Kernel.Components.AdviceRegistry.Register(advice); return(CreateAdviceBuilder(advice)); }
/// <summary> /// Begins a dynamic interception definition. /// </summary> /// <param name="kernel"></param> /// <param name="condition">The condition to evaluate to determine if a request should be intercepted.</param> /// <returns>An advice builder.</returns> private static IAdviceTargetSyntax DoIntercept(IKernel kernel, Predicate <IContext> condition) { IAdvice advice = kernel.Components.Get <IAdviceFactory>().Create(condition); kernel.Components.Get <IAdviceRegistry>().Register(advice); return(CreateAdviceBuilder(advice)); }
/// <summary> /// Creates a proxy around the given interface, and injects the given advice at all levels. /// </summary> /// <param name="advice">The advice.</param> /// <param name="interfaceType">Type of the interface.</param> /// <param name="referenceAssembly">The reference assembly.</param> /// <param name="referenceType">Type of the reference.</param> /// <returns>An object implementing the requested interface</returns> public static object Handle(this IAdvice advice, Type interfaceType, Assembly referenceAssembly = null, Type referenceType = null) { var implementationType = GetImplementationType(interfaceType, referenceAssembly, referenceType); var implementation = (AdvisedInterface)Activator.CreateInstance(implementationType); implementation.Advice = advice; return(implementation); }
/// <summary> /// Begins a dynamic interception definition. /// </summary> /// <param name="kernel">The kernel.</param> /// <param name="condition">The condition to evaluate to determine if a request should be intercepted.</param> /// <param name="methodPredicate">The condition to evaluate if a method call should be intercepted.</param> /// <returns>An advice builder.</returns> public static IAdviceTargetSyntax Intercept(this IKernel kernel, Predicate <IContext> condition, Predicate <MethodInfo> methodPredicate) { IAdvice advice = kernel.Components.Get <IAdviceFactory>().Create(condition, methodPredicate); kernel.Components.Get <IAdviceRegistry>().Register(advice); return(CreateAdviceBuilder(advice)); }
/// <summary> /// Creates a proxy around the given interface, and injects the given advice at all levels. /// </summary> /// <param name="advice">The advice.</param> /// <param name="interfaceType">Type of the interface.</param> /// <returns></returns> private static object Handle(this IAdvice advice, Type interfaceType) { var implementationType = GetImplementationType(interfaceType); var implementation = (AdvisedInterface)Activator.CreateInstance(implementationType); implementation.Advice = advice; return(implementation); }
/// <summary> /// Injects the introduced fields to advice. /// Allows null advices (and does nothing) /// </summary> /// <param name="advice">The advice.</param> /// <param name="advisedType">Type of the advised.</param> private static void SafeInjectIntroducedFields(IAdvice advice, Type advisedType) { // shame, but easy here if (advice is null) { return; } InjectIntroducedFields(advice, advisedType, null); }
/// <summary> /// Constructs the interception advice to trigger according to the binding used. /// </summary> /// <param name="binding">The binding.</param> /// <returns> /// An <see cref="IAdviceTargetSyntax"/> instance which allows the attachment of an <see cref="IInterceptor"/>. /// </returns> private static IAdviceTargetSyntax DoIntercept(IBindingSyntax binding) { IKernel kernel = binding.Kernel; IAdvice advice = kernel.Components.Get <IAdviceFactory>() .Create(context => ReferenceEquals(binding.BindingConfiguration, context.Binding.BindingConfiguration)); kernel.Components.Get <IAdviceRegistry>().Register(advice); return(new AdviceBuilder(advice)); }
private Type GetNonLazyType(IAdvice advice) { var type = advice.GetType(); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(LazyAdvice <>)) { return(type.GetGenericArguments()[0]); } return(type); }
/*----------------------------------------------------------------------------------------*/ #region Public Methods /// <summary> /// Registers the specified advice. /// </summary> /// <param name="advice">The advice to register.</param> public void Register(IAdvice advice) { if (advice.IsDynamic) { HasDynamicAdvice = true; _cache.Clear(); } _advice.Add(advice); }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Transaction.Interceptor.DefaultTransactionAttributeSourceAdvisor"/> class. /// </summary> public DefaultTransactionAttributeSourceAdvisor(ITransactionAttributeSource transactionAttributeSource, IAdvice advice) : base( advice ) { if (transactionAttributeSource == null) { throw new AopConfigException("Cannot construct a DefaultTransactionAttributeSourceAdvisor if " + "TransactionAttributeSource is null."); } _transactionAttributeSource = transactionAttributeSource; }
/// <summary> /// Gets priority level from the specified advice. /// </summary> /// <param name="advice">The advice.</param> /// <returns></returns> public static int GetLevel(IAdvice advice) { var priorityAttribute = advice.GetType().GetCustomAttributes(typeof(PriorityAttribute), true).Cast <PriorityAttribute>().SingleOrDefault(); if (priorityAttribute != null) { return(priorityAttribute.Level); } return(DefaultLevel); }
private ITestObject CreateProxy(object target, IAdvice interceptor, bool exposeProxy) { ProxyFactory pf = new ProxyFactory(target); pf.ExposeProxy = exposeProxy; // pf.Target = target; pf.AddAdvice(interceptor); return(pf.GetProxy() as ITestObject); }
public IAdvice Create() { var _sequence = this.Sequence; var _array = new IAdvice[_sequence.Length]; for (var _index = 0; _index < _sequence.Length; _index++) { _array[_index] = _sequence[_index](); } return(new Advisor.Sequence(_array)); }
public async Task HandleMovementAdvice(Unit unit, IAdvice advice) { var bestLocation = (Vector2)advice.ContextAccessor.GetContext(); var newDirection = unit.Position - bestLocation; var directionType = newDirection.GetDirection(); var oldPosition = unit.Position; var oldDirection = unit.FacingDirection; unit.Position = bestLocation; unit.FacingDirection = directionType; EventSystem.Publish(new UnitMovingEvent(unit, oldPosition, oldDirection)); }
private ITestObject CreateProxyChain(IAdvice interceptor, bool exposeProxy) { ITestObject first = new ChainableTestObject(null); ITestObject firstProxy = CreateProxy(first, interceptor, exposeProxy); Assert.IsNotNull(firstProxy); ITestObject second = new ChainableTestObject(firstProxy); ITestObject secondProxy = CreateProxy(second, interceptor, exposeProxy); Assert.IsNotNull(secondProxy); return(secondProxy); }
/// <summary> /// Registers static interceptors defined by attributes on the specified method. /// </summary> /// <param name="type">The type whose activation plan is being manipulated.</param> /// <param name="method">The method that may be intercepted.</param> /// <param name="attributes">The interception attributes that apply.</param> protected virtual void RegisterMethodInterceptors(Type type, MethodInfo method, ICollection <InterceptAttributeBase> attributes) { foreach (InterceptAttributeBase attribute in attributes) { IAdvice advice = AdviceFactory.Create(method); advice.Callback = attribute.CreateInterceptor; advice.Order = attribute.Order; AdviceRegistry.Register(advice); } }
/// <summary> /// Creates a new instance of the /// <see cref="Oragon.Spring.Aop.Support.DefaultIntroductionAdvisor"/> class using /// the supplied <paramref name="introduction"/> /// </summary> /// <param name="introduction">The introduction to use.</param> /// <param name="interfaces"> /// The interfaces to introduce. /// </param> /// <exception cref="System.ArgumentNullException"> /// If the supplied <paramref name="introduction"/> is <see langword="null"/>. /// </exception> public DefaultIntroductionAdvisor(IAdvice introduction, Type[] interfaces) { if (introduction == null) { throw new ArgumentNullException("introduction", "Introduction cannot be null"); } _introduction = introduction; foreach (Type intf in interfaces) { if (intf != typeof(IAdvice)) { AddInterface(intf); } } }
/// <summary> /// Finds the introduced field. /// </summary> /// <param name="advice">The advice.</param> /// <param name="adviceMemberInfo">The advice member information.</param> /// <param name="advisedType">Type of the advised.</param> /// <returns></returns> /// <exception cref="System.InvalidOperationException">Internal error, can not find matching introduced field</exception> internal static FieldInfo FindIntroducedField(IAdvice advice, MemberInfo adviceMemberInfo, Type advisedType) { var introducedFieldType = GetIntroducedType(adviceMemberInfo); var adviceType = advice.GetType(); var introducedFieldName = IntroductionRules.GetName(adviceType.Namespace, adviceType.Name, adviceMemberInfo.Name); var linkID = string.Format("{0}:{1}", adviceType.AssemblyQualifiedName, adviceMemberInfo.Name); const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; var introducedField = FindIntroducedFieldByName(advisedType, introducedFieldName, linkID, bindingFlags) ?? FindIntroducedFieldByTypeAndAvailability(advisedType, introducedFieldType, adviceMemberInfo.IsStatic(), null, bindingFlags) ?? FindIntroducedFieldByTypeAndAvailability(advisedType, introducedFieldType, adviceMemberInfo.IsStatic(), linkID, bindingFlags); if (introducedField == null) throw new InvalidOperationException("Internal error, can not find matching introduced field"); var introducedFieldAttribute = introducedField.GetCustomAttribute<IntroducedFieldAttribute>(); introducedFieldAttribute.LinkID = linkID; return introducedField; }
/*----------------------------------------------------------------------------------------*/ /// <summary> /// Registers static interceptors defined by attributes on the specified method. /// </summary> /// <param name="binding">The binding that points at the type whose activation plan is being released.</param> /// <param name="type">The type whose activation plan is being manipulated.</param> /// <param name="plan">The activation plan that is being manipulated.</param> /// <param name="method">The method that may be intercepted.</param> /// <param name="attributes">The interception attributes that apply.</param> protected virtual void RegisterMethodInterceptors(IBinding binding, Type type, IActivationPlan plan, MethodInfo method, ICollection <InterceptAttribute> attributes) { var factory = binding.Components.AdviceFactory; var registry = binding.Components.AdviceRegistry; foreach (InterceptAttribute attribute in attributes) { IAdvice advice = factory.Create(method); advice.Callback = attribute.CreateInterceptor; advice.Order = attribute.Order; registry.Register(advice); } }
/// <summary> /// Indicates that instances associated with this binding will be proxied. /// Only methods that match the specified predicate will be intercepted. /// </summary> /// <typeparam name="T">The type associated with this binding.</typeparam> /// <param name="bindingSyntax">The binding syntax target.</param> /// <param name="methodPredicate">The method predicate that defines if a method shall be intercepted.</param> /// <param name="additionalInterfaces">The additional interfaces for the proxy.</param> /// <returns>An <see cref="IAdviceTargetSyntax" /> instance which allows the attachment of an <see cref="IInterceptor" />.</returns> public static IAdviceTargetSyntax Intercept <T>(this IBindingOnSyntax <T> bindingSyntax, Predicate <MethodInfo> methodPredicate, params Type[] additionalInterfaces) { IKernel kernel = bindingSyntax.Kernel; foreach (var additionalInterface in additionalInterfaces) { bindingSyntax.BindingConfiguration.Parameters.Add(new AdditionalInterfaceParameter(additionalInterface)); } IAdvice advice = kernel.Components.Get <IAdviceFactory>() .Create(context => ReferenceEquals(bindingSyntax.BindingConfiguration, context.Binding.BindingConfiguration), methodPredicate); kernel.Components.Get <IAdviceRegistry>().Register(advice); return(new AdviceBuilder(advice)); }
/// <summary> /// Returns an <see cref="AopAlliance.Intercept.IInterceptor"/> to /// allow the use of the supplied <paramref name="advisor"/> in an /// interception-based framework. /// </summary> /// <param name="advisor">The advisor to find an interceptor for.</param> /// <returns> /// An interceptor to expose this advisor's behaviour. /// </returns> /// <exception cref="UnknownAdviceTypeException"> /// If the advisor type is not understood by any registered /// <see cref="Oragon.Spring.Aop.Framework.Adapter.IAdvisorAdapter"/>. /// </exception> public virtual IInterceptor GetInterceptor(IAdvisor advisor) { IAdvice advice = advisor.Advice; if (advice is IInterceptor) { return((IInterceptor)advice); } foreach (IAdvisorAdapter adapter in this.adapters) { if (adapter.SupportsAdvice(advice)) { return(adapter.GetInterceptor(advisor)); } } throw new UnknownAdviceTypeException(advice); }
private AopProxyFactory() { Config = AopProxyConfig.Load(); if (Config == null) { Config = new AopProxyConfig(); } TypeMap = new Dictionary <Type, IAdvice>(); foreach (var advConfig in Config.Advisors) { Type pointCutType = AopProxyFactory.LoadType(advConfig.PointCutType); Type adviceType = AopProxyFactory.LoadType(advConfig.AdviseType); IAdvice advice = Activator.CreateInstance(adviceType) as IAdvice; TypeMap[pointCutType] = advice; } }
public async Task HandleHealOtherAdvice(Unit unit, IAdvice advice) { var target = advice.ContextAccessor.GetContext() as Unit; if (target == null) { return; } var ability = unit.ActiveAbilities.FirstOrDefault(x => x.DamageType == DamageTypes.LightDamage); if (ability == null) { return; } await UseAbilityOnTargetHandler.ExecutePhase(unit, target, ability); }
/// <summary> /// Injects the introduced fields to advice. /// </summary> /// <param name="advice">The advice.</param> /// <param name="advisedType">Type of the advised.</param> private static void InjectIntroducedFields(IAdvice advice, Type advisedType) { // shame, but easy here if (advice == null) { return; } const BindingFlags adviceMembersBindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; foreach (var memberInfo in advice.GetType().GetFieldsAndProperties(adviceMembersBindingFlags).Where(IsIntroduction)) { var memberValue = memberInfo.GetValue(advice); if (memberValue == null) { InjectIntroducedField(advice, memberInfo, advisedType); } } }
/// <summary> /// Injects the introduced fields to advice. /// </summary> /// <param name="advice">The advice.</param> /// <param name="advisedType">Type of the advised.</param> /// <param name="introducedFields">The introduced fields.</param> private static void InjectIntroducedFields(IAdvice advice, Type advisedType, IList <MemberInfo> introducedFields) { if (introducedFields is null) { introducedFields = AdviceInfo.GetIntroducedFields(advice); } if (introducedFields.Count == 0) { return; } foreach (var memberInfo in introducedFields) { var memberValue = memberInfo.GetValue(advice); if (memberValue == null) { InjectIntroducedField(advice, memberInfo, advisedType); } } }
/// <summary> /// Finds the introduced field. /// </summary> /// <param name="advice">The advice.</param> /// <param name="adviceMemberInfo">The advice member information.</param> /// <param name="advisedType">Type of the advised.</param> /// <param name="advisedMemberName">Name of the advised member.</param> /// <returns></returns> /// <exception cref="InvalidOperationException">Internal error, can not find matching introduced field</exception> /// <exception cref="System.InvalidOperationException">Internal error, can not find matching introduced field</exception> internal static FieldInfo FindIntroducedField(IAdvice advice, MemberInfo adviceMemberInfo, Type advisedType, string advisedMemberName) { var introducedFieldType = GetIntroducedType(adviceMemberInfo); var adviceType = advice.GetType(); var introducedFieldName = IntroductionRules.GetName(adviceType.Namespace, adviceType.Name, advisedMemberName, adviceMemberInfo.Name); const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; var introducedField = FindIntroducedFieldByName(advisedType, introducedFieldName, introducedFieldName, bindingFlags) ?? FindIntroducedFieldByTypeAndAvailability(advisedType, introducedFieldType, adviceMemberInfo.IsStatic(), null, bindingFlags) ?? FindIntroducedFieldByTypeAndAvailability(advisedType, introducedFieldType, adviceMemberInfo.IsStatic(), introducedFieldName, bindingFlags); if (introducedField is null) { throw new InvalidOperationException("Internal error, can not find matching introduced field"); } var introducedFieldAttribute = introducedField.GetAttributes <IntroducedFieldAttribute>().Single(); introducedFieldAttribute.LinkID = introducedFieldName; return(introducedField); }
public void InterceptorsAreReturnedInAscendingOrder() { var module = new InlineModule(m => m.Bind <ObjectWithMethodInterceptor>().ToSelf()); using (var kernel = new StandardKernel(module)) { kernel.Components.Connect <IProxyFactory>(new DummyProxyFactory()); var factory = kernel.Components.AdviceFactory; var registry = kernel.Components.AdviceRegistry; IAdvice advice = factory.Create(new PredicateCondition <IRequest>(r => r.Method.Name.Equals("Foo"))); advice.Callback = r => r.Kernel.Get <FlagInterceptor>(); advice.Order = -1; registry.Register(advice); var obj = kernel.Get <ObjectWithMethodInterceptor>(); IContext context = kernel.Components.ContextFactory.Create(typeof(ObjectWithMethodInterceptor)); IRequest request = new StandardRequest( context, obj, typeof(ObjectWithMethodInterceptor).GetMethod("Foo"), new object[0], Type.EmptyTypes ); ICollection <IInterceptor> interceptors = registry.GetInterceptors(request); Assert.That(interceptors.Count, Is.EqualTo(2)); IEnumerator <IInterceptor> enumerator = interceptors.GetEnumerator(); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(FlagInterceptor))); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor))); } }
/// <summary> /// Injects the introduced fields to advice. /// </summary> /// <param name="advice">The advice.</param> /// <param name="advisedType">Type of the advised.</param> private static void InjectIntroducedFields(IAdvice advice, Type advisedType) { // shame, but easy here if (advice == null) return; const BindingFlags adviceMembersBindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; foreach (var memberInfo in advice.GetType().GetFieldsAndProperties(adviceMembersBindingFlags).Where(IsIntroduction)) { var memberValue = memberInfo.GetValue(advice); if (memberValue == null) InjectIntroducedField(advice, memberInfo, advisedType); } }
/// <summary> /// Adds the supplied <paramref name="advice"/> to the end (or tail) /// of the advice (interceptor) chain. /// </summary> /// <param name="advice"> /// The <see cref="AopAlliance.Aop.IAdvice"/> to be added. /// </param> /// <seealso cref="Spring.Aop.Support.DefaultPointcutAdvisor"/> /// <seealso cref="Spring.Aop.Framework.IAdvised.AddAdvice(int,IAdvice)"/> public void AddAdvice(IAdvice advice) { //int position = this._advisors != null ? this._advisors.Count : 0; AddAdvice(-1, advice); }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Aop.Support.DefaultPointcutAdvisor"/> /// class for the supplied <paramref name="advice"/> and /// <paramref name="pointcut"/>. /// </summary> /// <param name="advice"> /// The advice to use. /// </param> /// <param name="pointcut"> /// The pointcut to use. /// </param> public DefaultPointcutAdvisor(IPointcut pointcut, IAdvice advice) { this.pointcut = pointcut; Advice = advice; }
private ITestObject CreateProxy(object target, IAdvice interceptor, bool exposeProxy) { ProxyFactory pf = new ProxyFactory(target); pf.ExposeProxy = exposeProxy; // pf.Target = target; pf.AddAdvice(interceptor); return pf.GetProxy() as ITestObject; }
/// <summary> /// Returns <see langword="true"/> if the supplied /// <paramref name="advice"/> is an instance of the /// <see cref="Spring.Aop.IThrowsAdvice"/> interface. /// </summary> /// <param name="advice">The advice to check.</param> /// <returns> /// <see langword="true"/> if the supplied <paramref name="advice"/> is /// an instance of the <see cref="Spring.Aop.IThrowsAdvice"/> interface; /// <see langword="false"/> if not or if the supplied /// <paramref name="advice"/> is <cref lang="null"/>. /// </returns> public virtual bool SupportsAdvice(IAdvice advice) { return advice is IThrowsAdvice; }
/// <summary> /// Creates a new instance of the /// <see cref="AttributeMatchMethodPointcutAdvisor"/> class /// for the supplied <paramref name="advice"/>. /// </summary> /// <param name="advice">the advice to apply if the pointcut matches</param> public AttributeMatchMethodPointcutAdvisor(IAdvice advice) { this._advice = advice; }
/// <summary> /// Returns <see langword="true"/> if the supplied /// <paramref name="advice"/> is an instance of the /// <see cref="Spring.Aop.IAfterReturningAdvice"/> interface. /// </summary> /// <param name="advice">The advice to check.</param> /// <returns> /// <see langword="true"/> if the supplied <paramref name="advice"/> is /// an instance of the <see cref="Spring.Aop.IAfterReturningAdvice"/> interface; /// <see langword="false"/> if not or if the supplied /// <paramref name="advice"/> is <cref lang="null"/>. /// </returns> public virtual bool SupportsAdvice(IAdvice advice) { return advice is IAfterReturningAdvice; }
/// <summary> /// Return the index (0 based) of the supplied /// <see cref="AopAlliance.Aop.IAdvice"/> in the interceptor /// (advice) chain for this proxy. /// </summary> /// <remarks> /// <p> /// The return value of this method can be used to index into /// the <see cref="Spring.Aop.Framework.AdvisedSupport.Advisors"/> /// list. /// </p> /// </remarks> /// <param name="advice"> /// The <see cref="AopAlliance.Aop.IAdvice"/> to search for. /// </param> /// <returns> /// The zero (0) based index of this interceptor, or -1 if the /// supplied <paramref name="advice"/> is not an advice for this /// proxy. /// </returns> public virtual int IndexOf(IAdvice advice) { lock (this.SyncRoot) { return IndexOfInternal(advice); } }
/// <summary> /// Return the index (0 based) of the supplied /// <see cref="AopAlliance.Aop.IAdvice"/> in the interceptor /// (advice) chain for this proxy. /// </summary> /// <remarks> /// <p>Acces is not synchronized</p> /// <p> /// The return value of this method can be used to index into /// the <see cref="Spring.Aop.Framework.AdvisedSupport.Advisors"/> /// list. /// </p> /// </remarks> /// <param name="advice"> /// The <see cref="AopAlliance.Aop.IAdvice"/> to search for. /// </param> /// <returns> /// The zero (0) based index of this interceptor, or -1 if the /// supplied <paramref name="advice"/> is not an advice for this /// proxy. /// </returns> private int IndexOfInternal(IAdvice advice) { if (this._advisors != null) { for (int i = 0; i < this._advisors.Count; ++i) { IAdvisor advisor = (IAdvisor)this._advisors[i]; if (advisor.Advice == advice) { return i; } } } return -1; }
/// <summary> /// Removes the supplied <paramref name="advice"/> from the list /// of <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>. /// </summary> /// <param name="advice"> /// The <see cref="AopAlliance.Aop.IAdvice"/> to remove. /// </param> /// <returns> /// <see langword="true"/> if the supplied <paramref name="advice"/> was /// found in the list of <see cref="Spring.Aop.Framework.IAdvised.Advisors"/> /// and successfully removed. /// </returns> /// <exception cref="AopConfigException"> /// If this proxy configuration is frozen and the /// <see cref="AopAlliance.Aop.IAdvice"/> cannot be removed. /// </exception> public bool RemoveAdvice(IAdvice advice) { lock (this.SyncRoot) { int index = IndexOf(advice); if (index == -1) { return false; } RemoveAdvisorInternal(index); return true; } }
/// <summary> /// Adds the supplied <paramref name="advice"/> to the supplied /// <paramref name="position"/> in the advice (interceptor) chain. /// </summary> /// <param name="position"> /// The zero (0) indexed position (from the head) at which the /// supplied <paramref name="advice"/> is to be inserted into the /// advice (interceptor) chain. /// </param> /// <param name="advice"> /// The <see cref="AopAlliance.Aop.IAdvice"/> to be added. /// </param> /// <exception cref="Spring.Aop.Framework.AopConfigException"> /// If the supplied <paramref name="advice"/> is <cref lang="null"/>; /// or is not an <see cref="AopAlliance.Intercept.IMethodInterceptor"/> /// reference; or if the supplied <paramref name="advice"/> is a /// <see cref="Spring.Aop.IIntroductionInterceptor"/>. /// </exception> /// <seealso cref="Spring.Aop.Support.DefaultPointcutAdvisor"/> /// <seealso cref="IAdvised.AddAdvice(IAdvice)"/> public void AddAdvice(int position, IAdvice advice) { if (advice is IInterceptor && !(advice is IMethodInterceptor)) { throw new AopConfigException( GetType().FullName + " can only handle AOP Alliance IMethodInterceptor advice."); } if (advice is IIntroductionInterceptor) { throw new AopConfigException( "IIntroductionInterceptors may only be added as part of IIntroductionAdvisor."); } AddAdvisor(position, new DefaultPointcutAdvisor(advice)); }
/// <summary> /// Injects the introduced fields to advice. /// Allows null advices (and does nothing) /// </summary> /// <param name="advice">The advice.</param> /// <param name="advisedType">Type of the advised.</param> private static void SafeInjectIntroducedFields(IAdvice advice, Type advisedType) { // shame, but easy here if (advice == null) return; InjectIntroducedFields(advice, advisedType); }
/// <summary> /// Creates a new instance of the <see cref="RegularExpressionMethodPointcutAdvisor"/> /// class for the supplied <paramref name="advice"/>. /// </summary><param name="advice"> /// The target advice. /// </param> public RegularExpressionMethodPointcutAdvisor(IAdvice advice) { Advice = advice; InitPointcut(); }
/// <summary> /// Creates a new instance of the /// <see cref="AttributeMatchMethodPointcutAdvisor"/> class /// for the supplied <paramref name="advice"/>. /// </summary> /// <param name="attribute"> /// The <see cref="System.Attribute"/> to match. /// </param> /// <param name="inherit"> /// Flag that controls whether or not the inheritance tree of the /// method to be included in the search for the <see cref="Attribute"/>? /// </param> /// <param name="advice">the advice to apply if the pointcut matches</param> public AttributeMatchMethodPointcutAdvisor(Type attribute, bool inherit, IAdvice advice) :base(attribute, inherit) { this._advice = advice; }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Aop.Support.DefaultIntroductionAdvisor"/> class using /// the supplied <paramref name="introduction"/> /// </summary> /// <remarks> /// <p> /// This constructor adds all interfaces implemented by the supplied /// <paramref name="introduction"/> (except the /// <see cref="AopAlliance.Aop.IAdvice"/> interface) to the list of /// interfaces to introduce. /// </p> /// </remarks> /// <param name="introduction">The introduction to use.</param> public DefaultIntroductionAdvisor(IAdvice introduction) : this(introduction, introduction.GetType().GetInterfaces()) { }
public MethodRewriter(IAdvice advice, BasePointCut pointCut) { this._advice = advice; this._pointCut = pointCut; }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Aop.Support.DefaultIntroductionAdvisor"/> class using /// the supplied <paramref name="introduction"/> /// </summary> /// <param name="introduction">The introduction to use.</param> /// <param name="intf"> /// The interface to introduce. /// </param> public DefaultIntroductionAdvisor(IAdvice introduction, Type intf) : this(introduction, new Type[] {intf}) { }
private ITestObject CreateProxyChain(IAdvice interceptor, bool exposeProxy) { ITestObject first = new ChainableTestObject(null); ITestObject firstProxy = CreateProxy(first, interceptor, exposeProxy); Assert.IsNotNull(firstProxy); ITestObject second = new ChainableTestObject(firstProxy); ITestObject secondProxy = CreateProxy(second, interceptor, exposeProxy); Assert.IsNotNull(secondProxy); return secondProxy; }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Aop.Support.DefaultIntroductionAdvisor"/> class using /// the supplied <paramref name="introduction"/> /// </summary> /// <param name="introduction">The introduction to use.</param> /// <param name="interfaces"> /// The interfaces to introduce. /// </param> /// <exception cref="System.ArgumentNullException"> /// If the supplied <paramref name="introduction"/> is <see langword="null"/>. /// </exception> public DefaultIntroductionAdvisor(IAdvice introduction, Type[] interfaces) { if (introduction == null) { throw new ArgumentNullException("introduction", "Introduction cannot be null"); } _introduction = introduction; foreach (Type intf in interfaces) { if (intf != typeof (IAdvice)) { AddInterface(intf); } } }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Aop.Support.DefaultPointcutAdvisor"/> /// class for the supplied <paramref name="advice"/>, /// </summary> /// <param name="advice"> /// The advice to use. /// </param> public DefaultPointcutAdvisor(IAdvice advice) : this(TruePointcut.True, advice) { }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Aop.Support.AbstractRegularExpressionMethodPointcut"/> /// class for the supplied <paramref name="advice"/> /// </summary> /// <remarks> /// <p> /// This is an abstract class, and as such has no publicly /// visible constructors. /// </p> /// </remarks> /// <param name="advice"> /// The advice to use. /// </param> public StaticMethodMatcherPointcutAdvisor(IAdvice advice) { this._advice = advice; }
public bool SupportsAdvice(IAdvice advice) { return advice is ISimpleBeforeAdvice; }
/// <summary> /// Is the supplied <paramref name="advice"/> included in any /// advisor? /// </summary> /// <param name="advice"> /// The <see cref="AopAlliance.Aop.IAdvice"/> to check for the /// inclusion of. /// </param> /// <returns> /// <see langword="true"/> if the supplied <paramref name="advice"/> /// could be run in an invocation (this does not imply that said /// <paramref name="advice"/> will be run). /// </returns> public bool AdviceIncluded(IAdvice advice) { return (IndexOf(advice) != -1); }
/// <summary> /// Creates a new instance of the /// <see cref="NameMatchMethodPointcutAdvisor"/> class /// for the supplied <paramref name="advice"/>. /// </summary> /// <param name="advice"></param> public NameMatchMethodPointcutAdvisor(IAdvice advice) { Advice = advice; }
bool IAdvised.RemoveAdvice(IAdvice advice) { return m_advised.RemoveAdvice(advice); }