/// <summary> /// First time initialization and reconfig in case of restore /// </summary> /// <param name="model"></param> private void Configure(Model model) { _commandStore = _config.CreateCommandStore(); _snapshotStore = _config.CreateSnapshotStore(); _journalAppender = JournalAppender.Create(model.Revision + 1, _commandStore); _kernel = _config.CreateKernel(model); _kernel.SetSynchronizer(_synchronizer); }
/// <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 ?? new EngineConfiguration(); config.ModelType = typeof(TModel); var store = config.CreateSnapshotStore(); store.WriteSnapshot(model); return(Load <TModel>(config)); }
/// <summary> /// First time initialization and reconfig in case of restore /// </summary> /// <param name="model"></param> private void Configure(Model model) { _commandStore = _config.CreateCommandStore(); _snapshotStore = _config.CreateSnapshotStore(); _journalAppender = JournalAppender.Create(model.Revision + 1, _commandStore); _kernel = _config.CreateKernel(model); _kernel.SetSynchronizer(_synchronizer); //Capture events emitted during Command.Execute model.Events.Subscribe(e => _capturedEvents.Add(e)); }
/// <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)); }
/// <summary> /// Create by writing a ModelCreated entry to the journal /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="config"></param> /// <returns></returns> public static Engine <TModel> Create <TModel>(EngineConfiguration config = null) where TModel : Model, new() { config = config ?? new EngineConfiguration(); config.ModelType = typeof(TModel); var commandStore = config.CreateCommandStore(); if (!commandStore.IsEmpty) { throw new InvalidOperationException("Cannot Create(): empty CommandStore required"); } if (!config.CreateSnapshotStore().IsEmpty) { throw new InvalidOperationException("Can't Create(): empty SnapshotStore required"); } var appender = JournalAppender.Create(0, commandStore); appender.AppendModelCreated <TModel>(); appender.Dispose(); return(Load <TModel>(config)); }
/// <summary> /// Create by writing a ModelCreated entry to the journal /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="config"></param> /// <returns></returns> public static Engine <TModel> Create <TModel>(EngineConfiguration config = null) where TModel : Model, new() { config = config ?? EngineConfiguration.Create(); if (!config.Location.HasJournal) { config.Location.SetLocationFromType <TModel>(); } var commandStore = config.CreateCommandStore(); if (!commandStore.IsEmpty) { throw new InvalidOperationException("Cannot Create(): empty CommandStore required"); } if (!config.CreateSnapshotStore().IsEmpty) { throw new InvalidOperationException("Can't Create(): empty SnapshotStore required"); } JournalAppender.Create(0, commandStore).AppendModelCreated <TModel>(); return(Load <TModel>(config)); }
/// <summary> /// Load or create the specified type from the /// location according to EngineConfiguration.Location /// </summary> /// <typeparam name="TModel">The type of the model</typeparam> /// <param name="config">The configuration to use</param> /// <returns>A running engine</returns> public static Engine <TModel> LoadOrCreate <TModel>(EngineConfiguration config = null) where TModel : Model, new() { config = config ?? new EngineConfiguration(); config.ModelType = typeof(TModel); Engine <TModel> result = null; var commandStore = config.CreateCommandStore(); var snapshotStore = config.CreateSnapshotStore(); if (commandStore.IsEmpty && snapshotStore.IsEmpty) { result = Create <TModel>(config); Logger.Debug("Engine Created"); } else { result = Load <TModel>(config); Logger.Debug("Engine Loaded"); } return(result); }