Beispiel #1
0
        /// <summary>
        /// Create from an existing model by writing a snapshot
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="model"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static Engine <TModel> Create <TModel>(TModel model, EngineConfiguration config = null) where TModel : Model
        {
            config = config ?? EngineConfiguration.Create();
            if (!config.Location.HasJournal)
            {
                config.Location.SetLocationFromType <TModel>();
            }
            ISnapshotStore store = config.CreateSnapshotStore();

            store.WriteSnapshot(model);
            return(Load <TModel>(config));
        }
Beispiel #2
0
        /// <summary>
        /// Writes a snapshot reflecting the current state of the model to the associated <see cref="ISnapshotStore"/>
        /// <remarks>The snapshot is a read operation blocking writes but not other reads (unless using an ImmutablilityKernel).</remarks>
        /// </summary>
        public void CreateSnapshot()
        {
            ulong revision = 0;

            _kernel.Read(model =>
            {
                revision = model.Revision;
                _snapshotStore.WriteSnapshot(model);
                _journalAppender.Handle(new SnapshotCreated(revision));
            });

            if (_config.TruncateJournalOnSnapshot)
            {
                _commandStore.Truncate(revision);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Writes a snapshot reflecting the current state of the model to the associated <see cref="ICommandStore"/>
 /// <remarks>The snapshot is a read operation blocking writes but not other reads (unless using an ImmutablilityKernel).</remarks>
 /// </summary>
 public void CreateSnapshot()
 {
     _kernel.Read(model => _snapshotStore.WriteSnapshot(model));
 }