示例#1
0
 public BatchOperation(IStoreBatchProgress store, ReadModelGenerationConfig config)
 {
     _store     = store;
     _config    = config;
     _processed = _store.StartOrContinue(config.Name);
     EventStore.Logger.Debug($"'{config.Name}' [read model generation] starts/resumes after {_processed.Value} commits");
 }
示例#2
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);
            }
        }