public override Task SafeExecute(QueryContext <IProcessor> args) { // Get needed properties. var element = args.GetPropertyValueOrNull <XElement>(GetProcessorProperties.XElement); var attribute = args.GetPropertyValueOrNull <string>(GetProcessorProperties.ProcessorTypeAttribute); // Check attribute presence. XAttribute typeAttribute = element.Attribute(attribute); if (typeAttribute == null) { args.AddWarning($"Attribute that should contain processor type [{attribute}] was not found. Try reviewing the XML element."); return(Done); } // Get processor type name and assembly. var processorType = typeAttribute.Value; // Add property to the dictionary. if (!string.IsNullOrWhiteSpace(processorType)) { args.AddOrSkipPropertyIfExists(GetProcessorProperties.ProcessorTypeString, processorType); } else { args.AddWarning("The processor type contains an empty string."); } return(Done); }
public override Task SafeExecute(QueryContext <IProcessor> args) { var typeObject = args.GetPropertyValueOrNull <Type>(GetProcessorProperties.ProcessorType); var childValues = args.GetPropertyValueOrDefault( GetProcessorProperties.ChildrenValues, Enumerable.Empty <KeyValuePair <string, string> >()); var constructors = typeObject.GetConstructors(); foreach (var constructor in constructors.OrderByDescending(x => x.GetParameters().Length)) { var parameters = constructor.GetParameters(); if (parameters.Length > childValues.Count()) { continue; } if (parameters.Select(x => x.Name).Intersect(childValues.Select(x => x.Key)).Count() != parameters.Length) { continue; } args.AddOrSkipPropertyIfExists(GetProcessorProperties.Constructor, constructor); break; } return(Done); }
public override Task SafeExecute(QueryContext <IProcessor> args) { var children = args.GetPropertyValueOrNull <IEnumerable <XElement> >(GetProcessorProperties.Children); var childrenValues = children.ToDictionary(child => child.Name.LocalName, child => child.Value); args.AddOrSkipPropertyIfExists(GetProcessorProperties.ChildrenValues, childrenValues); return(Done); }
public override Task SafeExecute(QueryContext <IProcessor> args) { var element = args.GetPropertyValueOrNull <XElement>(GetProcessorProperties.XElement); if (!element.HasElements) { return(Done); } args.AddOrSkipPropertyIfExists(GetProcessorProperties.Children, element.Elements()); return(Done); }
public override Task SafeExecute(QueryContext <IProcessor> args) { var constructor = args.GetPropertyValueOrNull <ConstructorInfo>(GetProcessorProperties.Constructor); var childValues = args.GetPropertyValueOrDefault( GetProcessorProperties.ChildrenValues, Enumerable.Empty <KeyValuePair <string, string> >()); var parameters = constructor.GetParameters().Select(x => x.Name).Join(childValues, x => x, x => x.Key, (x, y) => y.Value).Cast <object>().ToArray(); var instance = constructor.Invoke(parameters); args.AddOrSkipPropertyIfExists(GetProcessorProperties.Instance, instance); return(Done); }
public override Task SafeExecute(QueryContext <IProcessor> args) { var type = args.GetPropertyValueOrNull <string>(GetProcessorProperties.ProcessorTypeString); var typeObject = Type.GetType(type); if (typeObject == null) { args.AddWarning($"Cannot obtain a type of the processor [{type}]."); return(Done); } args.AddOrSkipPropertyIfExists(GetProcessorProperties.ProcessorType, typeObject); return(Done); }