private static object?GetInstance( InvocationStep invocationStep, InvocationStep?parentStep, CommandContext commandContext) { var command = invocationStep.Command; var commandDef = command.GetCommandDef(); if (commandDef == null) { return(null); } var classType = commandDef.CommandHostClassType; if (classType == null) { return(null); } var instance = commandContext.AppConfig.ResolverService.ResolveCommandClass(classType, commandContext); if (instance != null) { SetInstanceOnParent(parentStep, classType, instance); } return(instance); }
static Task <int> Invoke(InvocationStep step, CommandContext context, ExecutionDelegate next, bool isCommand) { var result = step.Invocation.Invoke(context, step.Instance !, next); return(isCommand ? result.GetResultCodeAsync() : (Task <int>)result); }
private static IEnumerable <string> ValidateStep(InvocationStep step) { var propertyArgumentErrors = step.Invocation.Arguments .Select(GetParameterArgumentErrors); var argumentModelErrors = step.Invocation.FlattenedArgumentModels .Select(m => GetArgumentModelErrors(m, step.Invocation.Arguments)); return(propertyArgumentErrors .Concat(argumentModelErrors) .SelectMany(e => e)); }
private static IEnumerable <string> ValidateStep(InvocationStep step) { var phrasesToReplace = Resources.A .Error_DataAnnotation_phrases_to_replace_with_argument_name() .Split('|'); var propertyArgumentErrors = step.Invocation.Arguments .Select(argument => GetParameterArgumentErrors(argument, phrasesToReplace)); var argumentModelErrors = step.Invocation.FlattenedArgumentModels .Select(m => GetArgumentModelErrors(m, step.Invocation.Arguments, phrasesToReplace)); return(propertyArgumentErrors .Concat(argumentModelErrors) .SelectMany(e => e)); }
private static void SetInstanceOnParent(InvocationStep parentStep, Type classType, object instance) { if (parentStep == null) { return; } var parent = parentStep.Instance; parent.GetType().GetProperties() .Where(p => p.CanWrite && p.PropertyType == classType && p.HasAttribute <SubCommandAttribute>() && p.GetValue(parent) == null) .ForEach(p => p.SetValue(parent, instance)); }
internal static Task <int> ResolveCommandClassInstances(CommandContext commandContext, ExecutionDelegate next) { var pipeline = commandContext.InvocationPipeline; InvocationStep parentStep = null; foreach (var ic in pipeline.All) { if (parentStep != null && parentStep.Invocation.MethodInfo.DeclaringType == ic.Invocation.MethodInfo.DeclaringType) { // this is true when the interceptor method is in the same class as the command method ic.Instance = parentStep.Instance; continue; } ic.Instance = GetInstance(ic, parentStep, commandContext); parentStep = ic; } return(next(commandContext)); }
public InvocationInfo(CommandContext commandContext, InvocationStep invocationStep) : base(commandContext, invocationStep) { }