public override void OnException(MethodInvocationContext invocation, Exception e) { if (LoggingConfiguration.LoggingOutputOptions.LogErrors) { invocation.GetStateItem<ILogger>().Error(GetCallLogInfo(invocation), e); } }
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 !'=!^=!^)'+(^/) }
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()); }
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); }
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); }
private static string GetCallLogInfo(MethodInvocationContext invocationContext) { var logBuilder = new MethodCallLogBuilder(invocationContext); logBuilder.AddMethodCall(); if (LoggingConfiguration.LoggingOutputOptions.LogParameterValues) { logBuilder.AddParameters(); } return logBuilder.GetLogOutput(); }
private static string GetPostCallLog(MethodInvocationContext invocationContext) { var logBuilder = new MethodCallLogBuilder(invocationContext); logBuilder.AddMethodCall(); logBuilder.AddMethodExecutionTime(); if (LoggingConfiguration.LoggingOutputOptions.LogReturnValue) { logBuilder.AddReturnValue(); } return logBuilder.GetLogOutput(); }
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}..."); }
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); } }
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); }
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); }
public override bool HandleForMethodCall(MethodInvocationContext invocationContext) { var info = new ExtraMethodInfo(invocationContext.Invocation.Method); return info.IsGetterOrSetterFromProperty; }
private void OnException(MethodInvocationContext context, Exception exception) { foreach (var aspect in GetRelevantAspectsForInvocation(context)) { aspect.OnException(context, exception); } }
private IEnumerable<IAspect> GetRelevantAspectsForInvocation(MethodInvocationContext context) { return aspectInstances.Where(a => a.HandleForMethodCall(context)); }
private void PostCall(MethodInvocationContext context) { foreach (var aspect in GetRelevantAspectsForInvocation(context)) { aspect.PostCall(context); } }
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; }
public abstract void OnException(MethodInvocationContext invocation, Exception e);
public abstract void PostCall(MethodInvocationContext invocation);
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; }
public abstract MethodVoteOptions PreCall(MethodInvocationContext invocation);
public abstract bool HandleForMethodCall(MethodInvocationContext invocationContext);
public MethodCallLogBuilder(MethodInvocationContext invocationContext) { if (invocationContext == null) throw new ArgumentNullException("invocationContext"); this.invocationContext = invocationContext; sb = new StringBuilder(); }