public override IActionRequest ToRequest(Type payloadType, IActionRequestPayload payload) { var requestType = typeof(ContinuationActionRequest <>); var genericType = requestType.MakeGenericType(payloadType); return(ConstructRequest(genericType, ActionName, payload, Continuations.ToList()) as IActionRequest); }
public override IActionRequest ToRequest(Type payloadType, IActionRequestPayload payload) { var requestType = typeof(GatedActionRequest <>); var genericType = requestType.MakeGenericType(payloadType); return(Activator.CreateInstance(genericType, ActionName, payload, GateDescriptors) as IActionRequest); }
private IActionRequest ConstructRequest(Type requestType, string actionName, IActionRequestPayload payload, List <ActionRequestDescriptor> continuations) { foreach (var constructor in requestType.GetConstructors()) { var parameters = constructor.GetParameters(); switch (parameters.Length) { case 2: if (parameters[0].ParameterType.IsAssignableFrom(payload.GetType()) && parameters[1].ParameterType.IsAssignableFrom(continuations.GetType())) { return(Activator.CreateInstance(requestType, payload, continuations) as IActionRequest); } break; case 3: if (parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType.IsAssignableFrom(payload.GetType()) && parameters[2].ParameterType.IsAssignableFrom(continuations.GetType())) { return(Activator.CreateInstance(requestType, ActionName, payload, continuations) as IActionRequest); } break; } } return(base.ConstructRequest(requestType, payload)); }
protected IActionRequest ConstructRequest(Type requestType, IActionRequestPayload payload) { foreach (var constructor in requestType.GetConstructors()) { var parameters = constructor.GetParameters(); switch (parameters.Length) { case 1: if (parameters[0].ParameterType.IsAssignableFrom(payload.GetType())) { return(Activator.CreateInstance(requestType, payload) as IActionRequest); } break; case 2: if (parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType.IsAssignableFrom(payload.GetType())) { return(Activator.CreateInstance(requestType, ActionName, payload) as IActionRequest); } break; } } throw new ActionProcessorException($"Could not find a suitable constructor for type: {requestType.Name}"); }
public virtual IActionRequest ToRequest(Type payloadType, IActionRequestPayload payload) { if (RequestType.IsGenericType) { var genericType = RequestType.MakeGenericType(payloadType); return(ConstructRequest(genericType, payload)); } else { var payloadProperty = RequestType.GetProperty(nameof(IActionRequest.Payload), BindingFlags.Public | BindingFlags.Instance); if (payloadProperty.PropertyType.IsAssignableFrom(payloadType)) { return(ConstructRequest(RequestType, payload)); } throw new ActionProcessorException($"The request payload type is incompatible with the given action request descriptor '{RequestType.Name}'."); } }
public SuccessStateChange(IActionRequestPayload newPayload, IActionProcessingState newState) : base(newPayload, newState) { }
public SuccessStateChange(IActionRequestPayload newPayload, IActionProcessingState newState, string message = null) : base(newPayload, newState, message) { }
public FailureStateChange(IActionRequestPayload newPayload, IActionProcessingState newState, IEnumerable <string> messages = null) : base(newPayload, newState, messages) { }
public StateChangeResult(IActionRequestPayload newPayload, IActionProcessingState newState, string message) : this(newPayload, newState, Enumerable.Repeat(message, 1)) { }
public StateChangeResult(IActionRequestPayload newPayload, IActionProcessingState newState, IEnumerable <string> messages = null) { NewPayload = newPayload; NewState = newState; Messages = new List <string>(messages ?? Enumerable.Empty <string>()); }