public FormFlowInstance <TState> CreateInstance <TState>( TState state, IReadOnlyDictionary <object, object> properties = null) { if (state == null) { throw new ArgumentNullException(nameof(state)); } if (typeof(TState) != _flowDescriptor.StateType) { throw new InvalidOperationException( $"{typeof(TState).Name} is not compatible with {_flowDescriptor.StateType.Name}."); } var instanceId = FormFlowInstanceId.Generate( _flowDescriptor, _actionContext.HttpContext.Request, _actionContext.RouteData); var instance = (FormFlowInstance <TState>)_stateProvider.CreateInstance( _flowDescriptor.Key, instanceId, _flowDescriptor.StateType, state, properties); _actionContext.HttpContext.Features.Set(new FormFlowInstanceFeature(instance)); return(instance); }
public static RedirectToActionResult WithFormFlowInstanceId( this RedirectToActionResult result, FormFlowInstanceId instanceId) { result.RouteValues ??= new RouteValueDictionary(); foreach (var kvp in instanceId.RouteValues) { result.RouteValues[kvp.Key] = kvp.Value; } return(result); }
private protected FormFlowInstance( IUserInstanceStateProvider stateProvider, string key, FormFlowInstanceId instanceId, Type stateType, object state, IReadOnlyDictionary <object, object> properties, bool completed = false) { _stateProvider = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider)); Key = key ?? throw new ArgumentNullException(nameof(key)); StateType = stateType ?? throw new ArgumentNullException(nameof(stateType)); InstanceId = instanceId; Properties = properties ?? throw new ArgumentNullException(nameof(properties)); State = state ?? throw new ArgumentNullException(nameof(state)); Completed = completed; }
public FormFlowInstance Resolve(ActionContext actionContext) { if (actionContext == null) { throw new ArgumentNullException(nameof(actionContext)); } var flowDescriptor = actionContext.ActionDescriptor.GetProperty <FormFlowDescriptor>(); if (flowDescriptor == null) { return(null); } if (!FormFlowInstanceId.TryResolve( flowDescriptor, actionContext.HttpContext.Request, actionContext.RouteData, out var instanceId)) { return(null); } var instance = _stateProvider.GetInstance(instanceId); if (instance == null) { return(null); } if (instance.Key != flowDescriptor.Key) { return(null); } if (instance.StateType != flowDescriptor.StateType) { return(null); } return(instance); }
public static FormFlowInstance Create( IUserInstanceStateProvider stateProvider, string key, FormFlowInstanceId instanceId, Type stateType, object state, IReadOnlyDictionary <object, object> properties, bool completed = false) { var genericType = typeof(FormFlowInstance <>).MakeGenericType(stateType); return((FormFlowInstance)Activator.CreateInstance( genericType, stateProvider, key, instanceId, state, properties, completed)); }