예제 #1
0
 /// <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);
 }
예제 #2
0
파일: Engine.cs 프로젝트: quanhb/OrigoDB
        /// <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));
        }
예제 #3
0
        /// <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));
        }
예제 #4
0
파일: Engine.cs 프로젝트: quanhb/OrigoDB
        /// <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));
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
파일: Engine.cs 프로젝트: quanhb/OrigoDB
        /// <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 ?? EngineConfiguration.Create();
            if (!config.Location.HasJournal)
            {
                config.Location.SetLocationFromType <TModel>();
            }
            Engine <TModel> result = null;

            var store = config.CreateCommandStore();

            if (store.IsEmpty)
            {
                result = Create(new TModel(), config);
                _log.Debug("Engine Created");
            }
            else
            {
                result = Load <TModel>(config);
                _log.Debug("Engine Loaded");
            }
            return(result);
        }