Example #1
0
 public override void OnException(MethodInvocationContext invocation, Exception e)
 {
     if (LoggingConfiguration.LoggingOutputOptions.LogErrors)
     {
         invocation.GetStateItem<ILogger>().Error(GetCallLogInfo(invocation), e);
     }
 }
Example #2
0
        public void Intercept(IInvocation invocation)
        {
            DbAttributeBase attribute = AttributesHelper.GetAttribute<DbAttributeBase>(invocation);

            if (attribute == null)
            {
                new SelectOperator().Execute(invocation, null);
                return;
            }

            //for db operation aspects
            MethodInvocationContext context = new MethodInvocationContext(invocation);
            var atts = AttributesHelper.GetAttributes(invocation, typeof(DBAspectAttributeBase));
            foreach (DBAspectAttributeBase aspect in atts)
            {
                aspect.Process(context);
                if (context.Cancel == true)
                    return;
            }

            DbOperationBase operation = DbOperationFactory.GetOperator(attribute);
            operation.Execute(invocation, attribute);
            //TODO: add aspect for db interceptor. Cache is highly needed. or does caching needs to be solved over business classes.
            //      think about this you !'=!^=!^)'+(^/)
        }
Example #3
0
        public override MethodVoteOptions PreCall(MethodInvocationContext invocation)
        {
            var logger = CreateLogger(invocation);
            logger.Debug(GetCallLogInfo(invocation));

            return MethodVoteOptions.Continue;
        }
        public void RegisterMethod_TypeMethodRegistered()
        {
            MethodInfo info = typeof(TestClass).GetMethod("Method");
            Mock <IEngineConfigurationTypeMember> typeMemberMock = new Mock <IEngineConfigurationTypeMember>();

            MethodInvocationContext context = new MethodInvocationContext();

            context.AddArgumentValue(5);

            int count = 0;

            mTypeMock.Setup(x => x.GetRegisteredMember(It.IsAny <EngineTypeMember>()))
            .Returns(() =>
            {
                if (count == 0)
                {
                    count++; return(null);
                }
                else
                {
                    return(typeMemberMock.Object);
                }
            });
            mContext.RegisterMethod(info, context);
            mTypeMock.Verify(x => x.RegisterMember(It.Is <EngineTypeMember>(y => y.Name == info.Name)), Times.Once());
        }
Example #5
0
 private ILogger CreateLogger(MethodInvocationContext invocation)
 {
     //TODO implement the caching aspect so we can cache loggers...
     var logger = loggingFactory.Create(invocation.Invocation.TargetType);
     invocation.AddStateItem(logger);
     return logger;
 }
        public void AddArgumentSource_AddsArgument()
        {
            MethodInvocationContext context = new MethodInvocationContext();

            context.AddArgumentSource(typeof(RandomStringSource));

            DatasourceFactory factory = context.GetArguments().First();

            Assert.NotNull(factory);
        }
        public void AddArgumentValue_AddsArgument()
        {
            MethodInvocationContext context = new MethodInvocationContext();

            context.AddArgumentValue(5);

            DatasourceFactory factory = context.GetArguments().First();

            Assert.NotNull(factory);
        }
Example #8
0
        public void NonGeneric_SetupMethodWithParameters_ReturnsConfiguration()
        {
            EngineConfigurationTypeBuilder configuration = new EngineConfigurationTypeBuilder(typeof(SimpleMethodClass));
            var context = new MethodInvocationContext();

            context.AddArgumentValue("Hello");
            IEngineConfigurationTypeBuilder returnValue = configuration.SetupMethod("SetSomething", context);

            Assert.AreEqual(configuration, returnValue);
        }
Example #9
0
 private static string GetCallLogInfo(MethodInvocationContext invocationContext)
 {
     var logBuilder = new MethodCallLogBuilder(invocationContext);
     logBuilder.AddMethodCall();
     if (LoggingConfiguration.LoggingOutputOptions.LogParameterValues)
     {
         logBuilder.AddParameters();
     }
     return logBuilder.GetLogOutput();
 }
Example #10
0
        private static string GetPostCallLog(MethodInvocationContext invocationContext)
        {
            var logBuilder = new MethodCallLogBuilder(invocationContext);
            logBuilder.AddMethodCall();
            logBuilder.AddMethodExecutionTime();
            if (LoggingConfiguration.LoggingOutputOptions.LogReturnValue)
            {
                logBuilder.AddReturnValue();
            }

            return logBuilder.GetLogOutput();
        }
Example #11
0
 public override void Invoke(MethodInvocationContext methodInvocationContext, Action next)
 {
     Console.WriteLine($"begin invoke method {methodInvocationContext.ProxyMethod.Name} in {GetType().Name}...");
     try
     {
         next();
     }
     catch (Exception e)
     {
         Console.WriteLine($"Invoke {methodInvocationContext.ProxyMethod.DeclaringType?.FullName}.{methodInvocationContext.ProxyMethod.Name} exception");
         Console.WriteLine(e);
     }
     Console.WriteLine($"end invoke method {methodInvocationContext.ProxyMethod.Name} in {GetType().Name}...");
 }
Example #12
0
 protected virtual void OnMethodExecuting(IInvocation invocation)
 {
     var attributes = AttributesHelper.GetAttributes(invocation, typeof(AspectAttributeBase)).Cast<AspectAttributeBase>().OrderBy(i => i.Order);
     IMethodInvocationContext context = new MethodInvocationContext(invocation);
     try
     {
         bool cancelExecution = IterateAttributesAndReturnTrueIfCancel(context, attributes, ExecutionOrder.Before);
         if (!cancelExecution)
         {
             invocation.Proceed();
         }
         IterateAttributesAndReturnTrueIfCancel(context, attributes, ExecutionOrder.After);
     }
     catch (Exception ex)
     {
         IterateAttributesAndReturnTrueIfCancel(context, attributes, ExecutionOrder.Exception, ex);
     }
 }
Example #13
0
    public MethodInvocationContext methodInvocation()
    {
        MethodInvocationContext _localctx = new MethodInvocationContext(Context, State);

        EnterRule(_localctx, 4, RULE_methodInvocation);
        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 54; methodName();
                State = 55; methodParameterPart();
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
Example #14
0
        public void Intercept(IInvocation invocation)
        {
            var context = new MethodInvocationContext(serviceType, invocation);
            CreateAspects();

            var resp = PreCall(context);

            if (resp == MethodVoteOptions.Halt)
                return;

            try
            {
                context.MethodInvokeStartTime = DateTime.Now;
                invocation.Proceed();
            }
            catch (Exception ex)
            {
                OnException(context, ex);
                throw;
            }

            PostCall(context);
        }
Example #15
0
 public override bool HandleForMethodCall(MethodInvocationContext invocationContext)
 {
     var info = new ExtraMethodInfo(invocationContext.Invocation.Method);
     return info.IsGetterOrSetterFromProperty;
 }
Example #16
0
 private void OnException(MethodInvocationContext context, Exception exception)
 {
     foreach (var aspect in GetRelevantAspectsForInvocation(context))
     {
         aspect.OnException(context, exception);
     }
 }
Example #17
0
 private IEnumerable<IAspect> GetRelevantAspectsForInvocation(MethodInvocationContext context)
 {
     return aspectInstances.Where(a => a.HandleForMethodCall(context));
 }
Example #18
0
 private void PostCall(MethodInvocationContext context)
 {
     foreach (var aspect in GetRelevantAspectsForInvocation(context))
     {
         aspect.PostCall(context);
     }
 }
Example #19
0
 public override void PostCall(MethodInvocationContext invocation)
 {
     invocation.GetStateItem<ILogger>().Debug(GetPostCallLog(invocation));
 }
 public override void PostCall(MethodInvocationContext invocation)
 {
     PostCallCalled = true;
 }
 public override void OnException(MethodInvocationContext invocation, Exception e)
 {
     Exception = e;
 }
 public override MethodVoteOptions PreCall(MethodInvocationContext invocation)
 {
     PreCallCalled = true;
     return MethodVoteOptions;
 }
Example #23
0
 public abstract void OnException(MethodInvocationContext invocation, Exception e);
Example #24
0
 public abstract void PostCall(MethodInvocationContext invocation);
Example #25
0
        private MethodVoteOptions PreCall(MethodInvocationContext context)
        {
            var resp = MethodVoteOptions.Continue;
            var relevantAspects = GetRelevantAspectsForInvocation(context);
            foreach (var aspect in relevantAspects)
            {
                resp = aspect.PreCall(context);
                if (resp == MethodVoteOptions.Halt)
                    break;
            }

            return resp;
        }
Example #26
0
 public abstract MethodVoteOptions PreCall(MethodInvocationContext invocation);
Example #27
0
 public abstract bool HandleForMethodCall(MethodInvocationContext invocationContext);
Example #28
0
 public MethodCallLogBuilder(MethodInvocationContext invocationContext)
 {
     if (invocationContext == null) throw new ArgumentNullException("invocationContext");
     this.invocationContext = invocationContext;
     sb = new StringBuilder();
 }