Пример #1
0
        public void GenerateReadModel(string operationName, Action <dynamic> modelUpdater, Action <IConfigReadModelGeneration> config = null)
        {
            operationName.MustNotBeEmpty();
            var conf = new ReadModelGenerationConfig(operationName);

            config?.Invoke(conf);

            void HandleCommit(Commit commit, Action <dynamic> updater)
            {
                var evs = Utils.UnpackEvents(commit.Timestamp, commit.EventData, _settings.EventMappers);

                foreach (var ev in evs)
                {
                    EventStore.Logger.Debug("Updating readmodel from {@event}", ev);
                    updater((dynamic)ev);
                }
            }

            using (var operation = new BatchOperation(_store, conf))
            {
                Optional <Commit> commit;
                do
                {
                    commit = operation.GetNextCommit();
                    if (commit.HasValue)
                    {
                        HandleCommit(commit.Value, modelUpdater);
                    }
                } while (commit.HasValue);
            }
        }
Пример #2
0
        public void MigrateEventsTo(IStoreEvents newStorage, string name, Action <IConfigMigration> config = null)
        {
            name.MustNotBeEmpty();
            var conf = new MigrationConfig(name);

            config?.Invoke(conf);
            var l = EventStore.Logger;

            var rew = new EventsRewriter(conf.Converters, _settings.EventMappers);

            l.Debug("Starting store migration with batch operation: {name}", name);
            using (var operation = new BatchOperation(_store, conf))
            {
                Optional <Commit> commit;
                do
                {
                    commit = operation.GetNextCommit();
                    if (commit.HasValue)
                    {
                        l.Debug("Importing commit {commit}", commit.Value.CommitId);
                        newStorage.Advanced.ImportCommit(rew.Rewrite(commit.Value));
                    }
                } while (commit.HasValue);
            }
            l.Debug("Migration {name} completed", name);
        }