Пример #1
0
 public FlowContextTrace(string scopeId, IEnumerable <Difference> diff, UiFlowContextData initial, UiFlowContextData final)
 {
     ScopeId = scopeId;
     Diff    = diff;
     Initial = initial;
     Final   = final;
 }
Пример #2
0
        public UiFlowContextData CreateNew()
        {
            var result = new UiFlowContextData();

            result.CurrentScreenStep = ScreenName.PreStart;
            Attach(result);
            return(result);
        }
Пример #3
0
        public ScreenName RunNavigation(ScreenEvent eventToTrigger, UiFlowContextData contextData = null)
        {
            var navigations = new TestFlowCreateStepDataConfigurator(_target);

            _target.OnDefiningAdditionalInitialStateTransitions(navigations, contextData ?? _uiFlowContextData ?? new UiFlowContextData());

            return(navigations.Execute(eventToTrigger));
        }
Пример #4
0
        public async Task <UiFlowContextData> Save(UiFlowContextData contextData)
        {
            var jsonData = contextData.ToJson(true);
            await _store.SetAsync(contextData.FlowHandler, jsonData);

            Logger.Debug(() => $"Added {contextData.FlowHandler}");
            return(contextData);
        }
Пример #5
0
        public async Task <UiFlowContextData> CreateSnapshotOfContext(UiFlowContextData source)
        {
            if (!Store.ContainsKey(source.FlowHandler))
            {
                throw new ArgumentException("the context must be attached before creating an snapshot");
            }

            var ctx = source.CloneAsNew(this);

            Attach(ctx);


            UpdateClonedSteps();

            await UpdateContainer();

            UpdateFollowingSnapshot();

            return(ctx);

            void UpdateClonedSteps()
            {
                foreach (var stepData in ctx.ViewModels.Values)
                {
                    stepData.FlowHandler = ctx.FlowHandler;
                }
            }

            async Task UpdateContainer()
            {
                if (ctx.IsInContainer())
                {
                    var container = await Get(ctx.ContainerFlowHandler);

                    container = await CreateSnapshotOfContext(container);

                    var currentStepData = container.GetCurrentStepData <UiFlowScreenModel>().Metadata;
                    if (currentStepData != null)
                    {
                        currentStepData.ContainedFlowHandler = ctx.FlowHandler;
                    }


                    ctx.ContainerFlowHandler = container.FlowHandler;
                }
            }

            void UpdateFollowingSnapshot()
            {
                if (!string.IsNullOrWhiteSpace(source.NextFlowHandler))
                {
                    Store.TryRemove(source.NextFlowHandler, out var deleted);
                    _removed.Add(source.NextFlowHandler);
                }

                source.NextFlowHandler = ctx.FlowHandler;
            }
        }
Пример #6
0
 protected override Task <StartScreenModel> OnBuildStartData(UiFlowContextData newContext, StartScreenModel preloadedInputData)
 {
     if (nameof(FlowInitializer).Equals(preloadedInputData.FailOnStep, StringComparison.InvariantCultureIgnoreCase) &&
         preloadedInputData.FailOnEvent == ScreenLifecycleStage.FlowInitialization)
     {
         throw new Exception($"Triggering failure on {GetType().Name}");
     }
     return(base.OnBuildStartData(newContext, preloadedInputData));
 }
Пример #7
0
        private async Task <TFlowInputData> BuildStartData(UiFlowContextData newContext,
                                                           IDictionary <string, object> flowInputData)
        {
            var expandoObject = flowInputData.ToExpandoObject();

            var result = await OnBuildStartData(newContext, expandoObject.ToObjectOfType <TFlowInputData>(false));

            return(result);
        }
Пример #8
0
        public async Task <UiFlowContextData> GetRootContainerContext(UiFlowContextData ctx)
        {
            if (ctx.IsInContainer())
            {
                var containerContext = await Get(ctx.ContainerFlowHandler);

                return(await GetRootContainerContext(containerContext));
            }

            return(ctx);
        }
Пример #9
0
        public static UiFlowScreenModel AddStepData(this UiFlowContextData ctx, string flowScreenName, bool setCurrentStepData = false)
        {
            var userData = new UiFlowScreenModel();

            userData.Metadata.FlowHandler    = ctx.FlowHandler;
            userData.Metadata.FlowScreenName = flowScreenName;
            ctx.SetStepData(flowScreenName, userData);
            if (setCurrentStepData)
            {
                ctx.CurrentScreenStep = flowScreenName;
            }
            return(userData);
        }
Пример #10
0
        public async Task <ScreenEvent> InitializeContext(UiFlowContextData newContext,
                                                          IDictionary <string, object> flowInputData,
                                                          ScreenEvent defaultEventToTrigger)
        {
            var data = await BuildStartData(newContext, flowInputData);

            data.Metadata.FlowHandler    = newContext.FlowHandler;
            data.Metadata.FlowType       = newContext.FlowType;
            data.Metadata.FlowScreenName = typeof(EmptyScreenModel).FullName;
            newContext.SetCurrentStepData(data);

            return(await ResolveInitializationEventToTrigger(defaultEventToTrigger, data));
        }
Пример #11
0
        public void CanDeserialize()
        {
            var ctx = new UiFlowContextData();

            ctx.CurrentScreenStep = ScreenName.PreStart;
            var flowScreenName = "stepDataA";
            var expected       = ctx.AddStepData(flowScreenName);
            var actual         = ctx.ToJson(true).JsonToObject <UiFlowContextData>(true);
            var userMetadata   = actual.ViewModels[flowScreenName];

            Assert.AreEqual(ctx.FlowHandler, userMetadata.FlowHandler);
            Assert.IsNotNull(userMetadata.UserData);
            Assert.AreEqual(expected, userMetadata.UserData);
        }
Пример #12
0
        internal FlowInitializerWithLifecycleAdapter(IUiFlowInitializationStep target)
        {
            _target = target;
            SetRegistry();
            _uiFlowContextData = new UiFlowContextData
            {
                CurrentScreenStep = ScreenName.PreStart
            };

            void SetRegistry()
            {
                var items = typeof(TInitializer).Namespace.Split('.').SkipLast(2);
                var flowsRootNamespace = string.Join('.', items);

                _target.SetPropertyValueFast(nameof(UiFlowScreen.Registry),
                                             new FlowsRegistry(typeof(TInitializer).Assembly, flowsRootNamespace, string.Empty));
            }
        }
Пример #13
0
        internal FlowScreenWithLifecycleAdapter(TFlowScreen target, IFixture fixture)
        {
            Fixture = fixture;
            _target = target;

            SetRegistry();
            _uiFlowContextData = new UiFlowContextData
            {
                CurrentScreenStep = GetStep()
            };

            void SetRegistry()
            {
                var items = typeof(TFlowScreen).Namespace.Split('.').SkipLast(2);
                var flowsRootNamespace = string.Join('.', items);

                _target.SetPropertyValueFast(nameof(UiFlowScreen.Registry),
                                             new FlowsRegistry(typeof(TFlowScreen).Assembly, flowsRootNamespace, string.Empty));
            }
        }
Пример #14
0
 public override IScreenFlowConfigurator OnDefiningAdditionalInitialStateTransitions(IScreenFlowConfigurator preStartCfg,
                                                                                     UiFlowContextData contextData)
 {
     return(preStartCfg.OnEventNavigatesTo(ScreenEvent.Start, ContainersFlowScreenName.Number1ContainerScreen));
 }
Пример #15
0
 public override IScreenFlowConfigurator OnDefiningAdditionalInitialStateTransitions(IScreenFlowConfigurator preStartCfg,
                                                                                     UiFlowContextData contextData)
 {
     return(preStartCfg.OnEventNavigatesTo(ScreenEvent.ErrorOccurred, StartFailureFlowScreenName.FailureScreen));
 }
Пример #16
0
 protected virtual async Task <TFlowInputData> OnBuildStartData(UiFlowContextData newContext,
                                                                TFlowInputData preloadedInputData)
 {
     return(preloadedInputData);
 }
Пример #17
0
 public override IScreenFlowConfigurator OnDefiningAdditionalInitialStateTransitions(IScreenFlowConfigurator preStartCfg,
                                                                                     UiFlowContextData contextData)
 {
     return(preStartCfg.OnEventNavigatesTo(ScreenEvent.Start, GreenFlowScreenName.Step0Screen
                                           , () => contextData.GetCurrentStepData <StartScreenModel>().SampleParameter != "Finish"
                                           , "normal start"
                                           )
            .OnEventNavigatesTo(ScreenEvent.Start, GreenFlowScreenName.FlowCompletedScreen
                                , () => contextData.GetCurrentStepData <StartScreenModel>().SampleParameter == "Finish"
                                , "straight to the end"
                                ));
 }
Пример #18
0
 private void Attach(UiFlowContextData contextData)
 {
     contextData.SetRepository(this);
     Store.AddOrUpdate(contextData.FlowHandler, a => Task.FromResult(contextData), (a, b) => Task.FromResult(contextData));
 }
Пример #19
0
 public override IScreenFlowConfigurator OnDefiningAdditionalInitialStateTransitions(IScreenFlowConfigurator preStartCfg,
                                                                                     UiFlowContextData contextData)
 {
     return(preStartCfg.OnEventNavigatesTo(ScreenEvent.Start, MetadataTestFlowScreenScreenName.Step0Screen));
 }
Пример #20
0
 public override IScreenFlowConfigurator OnDefiningAdditionalInitialStateTransitions(IScreenFlowConfigurator preStartCfg,
                                                                                     UiFlowContextData contextData)
 {
     return(preStartCfg.OnEventNavigatesTo(ScreenEvent.Start, ModelTesterFlowStep.InputScreen));
 }
Пример #21
0
 OnDefiningAdditionalInitialStateTransitions(IScreenFlowConfigurator preStartCfg,
                                             UiFlowContextData contextData)
 {
     return(preStartCfg);
 }
        private async Task <TResult> InputOnRedirectToRoot(FlowResultResolverRequest <TResult> input, UiFlowContextData uiFlowContextData)
        {
            var root = await _contextRepository.GetRootContainerContext(uiFlowContextData);

            return(await input.OnRedirectToRoot(root.FlowType, root.FlowHandler));
        }