コード例 #1
0
        /// <summary>
        /// Pushes the given state into storage. 
        /// </summary>
        /// <param name="viewModel"> The ViewModel that the state belongs to. </param>
        /// <param name="activationData"> Data the ViewModel was activated with. </param>
        /// <param name="navigationState"> The state of platform navigation. </param>
        public async Task PushStateAsync(object viewModel, object activationData, string navigationState)
        {
            var states = await this.GetAllStatesAsync();
            var attribute = viewModel.GetType().GetTypeInfo().GetCustomAttribute<StatePersistenceBehaviorAttribute>();
            var vmType = viewModel.GetType();

            if (attribute != null)
            {
                switch (attribute.StatePersistenceBehaviorType)
                {
                    case StatePersistenceBehaviorType.ActivationAndState:
                        break;
                    case StatePersistenceBehaviorType.StateOnly:
                        activationData = null;
                        break;
                    case StatePersistenceBehaviorType.None:
                        activationData = null;
                        viewModel = null;
                        break;
                }
            }

            var state = new State
            {
                ActivationData = activationData,
                ViewModelState = this.GetViewModelStateLazy(viewModel),
                ViewModelType = vmType
            };

            states.Add(state);
        }
コード例 #2
0
        private StateWrapper SerializeState(State state)
        {
            var vmState = state.ViewModelState.Value;

            return new StateWrapper
            {
                ActivationData = JsonConvert.SerializeObject(state.ActivationData),
                ActivationDataType = state.ActivationData?.GetType().AssemblyQualifiedName ?? string.Empty,
                ViewModelState = JsonConvert.SerializeObject(vmState),
                ViewModelStateType = vmState?.GetType().AssemblyQualifiedName ?? string.Empty,
                ViewModelType = state.ViewModelType?.AssemblyQualifiedName ?? string.Empty
            };
        }