Exemplo n.º 1
0
        public static IList<IAspect> AttributeBasedJoinPointDefinition(IAspectEnvironment aspectEnvironment, IList<IAspect> availableAspects)
        {
            object[] customAttributes = aspectEnvironment.ConcreteMethodInfo.GetCustomAttributes(typeof(InterceptedByAttribute), true);
            if (customAttributes.Length == 0)
                return new List<IAspect>();

            var takenAspects = new List<IAspect>();

            var attribute = customAttributes[0] as InterceptedByAttribute;
            if (attribute != null)
            {
                foreach (Type aspectTypes in attribute.Types) //Keeping order of Aspects
                {
                    foreach (IAspect aspect in availableAspects)
                    {
                        if(aspect.GetType() == aspectTypes) //return the Aspect if the Types Match
                        {
                            takenAspects.Add(aspect);
                            break;
                        }
                    }
                }
            }

            return takenAspects;
        }
Exemplo n.º 2
0
        public object Execute(Func<object[], object> proceedInvocation, object[] args, IAspectEnvironment method)
        {
            if(args.Length > 0)
            {
                if(args[0] is string)
                {
                    RaiseDoneSomething((string)args[0]);
                }
            }

            object result = proceedInvocation(args);

            if (result is string)
                RaiseDoneSomething((string) result);

            return "executed";
        }
Exemplo n.º 3
0
        public Func<object[], object> CreateNextLevel(IInvocation invocation, IEnumerable<IAspect> restOfAspects, IAspectEnvironment method)
        {
            return args =>
                       {
                           IAspect nextAspect = restOfAspects.FirstOrDefault();
                           if (nextAspect != null)
                           {
                               //Recursion
                               return nextAspect.Execute(
                                   CreateNextLevel(invocation, restOfAspects.Skip(1), method),
                                   args, method
                                   );
                           }

                           for (int i = 0; i < args.Length; i++)
                           {
                               invocation.SetArgumentValue(i, args[i]);
                           }
                           //Enter the body of the concrete Method
                           invocation.Proceed();
                           return invocation.ReturnValue;
                       };
        }
        /// <summary>
        /// TODO using the additional Dictionary/MethodInfo thing is not that good idea, refactor!
        /// </summary>
        /// <param name="type"></param>
        /// <param name="aspectEnvironment"></param>
        /// <param name="availableAspects"></param>
        /// <returns></returns>
        private IList<IAspect> Memoization(IAspectEnvironment aspectEnvironment, IList<IAspect> availableAspects)
        {
            const string dictionaryKey = "__MemoizeJointPointDefinition";

            IList<IAspect> methodAspect = null;

            aspectEnvironment.SyncronizedKeyValueStoreMutator((keyValueStore) =>
            {
                if (keyValueStore.ContainsKey(dictionaryKey))
                {
                    var methodInfoDict = keyValueStore.GetValue<Dictionary<MethodInfo, IList<IAspect>>>(dictionaryKey);

                    if (methodInfoDict != null && methodInfoDict.ContainsKey(aspectEnvironment.ConcreteMethodInfo))
                    {
                        methodAspect = methodInfoDict[aspectEnvironment.ConcreteMethodInfo];
                    }
                }
            });

            if (methodAspect != null)
                return methodAspect;

            aspectEnvironment.GetValueOrCreate(dictionaryKey, () => new Dictionary<MethodInfo, IList<IAspect>>());

            aspectEnvironment.SyncronizedKeyValueStoreMutator((keyValueStore) =>
            {
                var store = keyValueStore.GetValue<Dictionary<MethodInfo, IList<IAspect>>>(dictionaryKey);

                if (!store.ContainsKey(aspectEnvironment.ConcreteMethodInfo)) //second check
                {
                    methodAspect = _jointPointDefinitionToMemoize(aspectEnvironment, availableAspects);
                    store.Add(aspectEnvironment.ConcreteMethodInfo, methodAspect);
                }
            });

            return methodAspect;
        }
        public object Execute(Func<object[], object> proceedInvocation, object[] args, IAspectEnvironment method)
        {
            RaiseDoneSomething("SecondAspectBefore");

            object result = proceedInvocation(args);

            RaiseDoneSomething("SecondAspectAfter");
            return result;
        }
 private IList<IAspect> JointPointDefinition(IAspectEnvironment environMent, IList<IAspect> aspectList)
 {
     return aspectList;
 }
Exemplo n.º 7
0
 private IList<IAspect> VeryLongRunningAspectCalculation(IAspectEnvironment arg2, IList<IAspect> arg3)
 {
     Thread.Sleep(1000);
     return arg3;
 }
Exemplo n.º 8
0
 public object Execute(Func<object[], object> proceedInvocation, object[] methodArguments, IAspectEnvironment method)
 {
     Executed.Invoke(this, new TestEventArgs() { Message = "before" });
     return proceedInvocation(methodArguments);
 }