コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: FormFlowInstance.cs プロジェクト: timabell/formflow
 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;
 }
コード例 #4
0
ファイル: InstanceResolver.cs プロジェクト: timabell/formflow
        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);
        }
コード例 #5
0
ファイル: FormFlowInstance.cs プロジェクト: timabell/formflow
        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));
        }