public Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { if (!invocation.GetValue <bool>("security_checked")) { throw new Exception("Security advice not invoked."); } return(Task.FromResult(default(TAdvice))); }
public Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { var key = invocation.SolidProxyInvocationConfiguration.MethodInfo.Name; key = key.Substring(3); key = key.Substring(0, key.Length - 5); return(Task.FromResult(invocation.SolidProxyInvocationConfiguration.GetValue <TAdvice>(key, true))); }
public async Task <int> Handle(Func <Task <int> > next, ISolidProxyInvocation <TObject, TReturnType, int> invocation) { if (invocation.IsLastStep) { return(-1); } else { return((await next()) + 1); } }
public async Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { // increase the step count. invocation.SetValue(StepCountKey, invocation.GetValue <int>(StepCountKey) + 1); if (invocation.IsLastStep) { return((TAdvice)(object)invocation.GetValue <int>(StepCountKey)); } else { return(await next()); } }
public async Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { var methodInfo = invocation.SolidProxyInvocationConfiguration.MethodInfo; try { Logger.LogTrace($"Entering - {methodInfo.Name}"); return(await next()); } finally { Logger.LogTrace($"Exiting - {methodInfo.Name}"); } }
/// <summary> /// Handles the invocation /// </summary> /// <param name="next"></param> /// <param name="invocation"></param> /// <returns></returns> public Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { var confScope = (ISolidConfigurationScope)invocation.ServiceProvider.GetService(typeof(ISolidConfigurationScope)); if (confScope == null) { throw new Exception("Cannot find configuration scope."); } var methodInfo = invocation.SolidProxyInvocationConfiguration.MethodInfo; var scope = typeof(TObject).FullName; var methodName = methodInfo.Name; if (methodInfo.DeclaringType == typeof(ISolidProxyInvocationAdviceConfig)) { if (methodName == $"get_{nameof(ISolidProxyInvocationAdviceConfig.InvocationConfiguration)}") { scope = typeof(ISolidProxyInvocationAdviceConfig).FullName; } if (methodName == nameof(ISolidProxyInvocationAdviceConfig.GetAdviceConfig)) { return(Task.FromResult((TAdvice)s_ConfigureAdviceMethod.GetOrAdd(typeof(TAdvice), _ => { var configureAdviceMethod = typeof(ISolidConfigurationScope).GetMethod(nameof(ISolidConfigurationScope.ConfigureAdvice)); return configureAdviceMethod.MakeGenericMethod(_); }).Invoke(confScope, null))); } } if (methodName.StartsWith("get_")) { var key = $"{scope}.{methodName.Substring(4)}"; var value = confScope.GetValue <TAdvice>(key, true); return(Task.FromResult(value)); } else if (methodName.StartsWith("set_")) { var key = $"{scope}.{methodName.Substring(4)}"; confScope.SetValue(key, invocation.Arguments[0]); return(Task.FromResult(default(TAdvice))); } else { throw new NotImplementedException($"Cannot handle method:{methodName}"); } }
public Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { throw new NotImplementedException(); }
public Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { return(Task.FromResult((TAdvice)(object)11)); }
public async Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { invocation.SetValue("security_checked", true); return(await next()); }
public Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { return(next()); }
public Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { invocation.ReplaceArgument <int>((name, i) => i + 1); return(next()); }
public async Task <bool> Handle(Func <Task <bool> > next, ISolidProxyInvocation <TObject, TReturnType, bool> invocation) { return(invocation.SolidProxyInvocationConfiguration.HasImplementation); }
public Task <IList <string> > Handle(Func <Task <IList <string> > > next, ISolidProxyInvocation <TObject, IList <string>, IList <string> > invocation) { var handlers = invocation.GetValue <IList <string> >("handlers"); if (handlers == null) { invocation.SetValue("handlers", handlers = new List <string>()); } handlers.Add(GetType().Name); if (invocation.IsLastStep) { return(Task.FromResult(handlers)); } else { return(next()); } }
public Task <TAdvice> Handle(Func <Task <TAdvice> > next, ISolidProxyInvocation <TObject, TMethod, TAdvice> invocation) { return(Task.FromResult(invocation.GetValue <TAdvice>("result"))); }