Exemple #1
0
        public async Task Save(IAsyncStateMachineSaver <TState> stateMachineSaver)
        {
            Guard.AgainstNullArgument("stateMachineSaver", stateMachineSaver);

            await stateMachineSaver.SaveCurrentState(this.currentState != null?
                                                     new Initializable <TState> {
                Value = this.currentState.Id
            } :
                                                     new Initializable <TState>()).ConfigureAwait(false);

            IEnumerable <IState <TState, TEvent> > superStatesWithLastActiveState = this.states.GetStates()
                                                                                    .Where(s => s.SubStates.Any())
                                                                                    .Where(s => s.LastActiveState != null)
                                                                                    .ToList();

            var historyStates = superStatesWithLastActiveState.ToDictionary(
                s => s.Id,
                s => s.LastActiveState.Id);

            await stateMachineSaver.SaveHistoryStates(historyStates).ConfigureAwait(false);
        }
Exemple #2
0
        /// <summary>
        /// Saves the current state and history states to a persisted state. Can be restored using <see cref="Load"/>.
        /// </summary>
        /// <param name="stateMachineSaver">Data to be persisted is passed to the saver.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task Save(IAsyncStateMachineSaver <TState> stateMachineSaver)
        {
            Guard.AgainstNullArgument("stateMachineSaver", stateMachineSaver);

            await this.stateMachine.Save(stateMachineSaver).ConfigureAwait(false);
        }