public bool RebuildIndex() { var indexState = index.GetIndexState(); if (indexState.IsPresent()) { return(true); } var indexBuilder = index.GetIndexBuilder(); foreach (var aggregateCommit in eventStorePlayer.LoadAggregateCommits()) { foreach (var @event in aggregateCommit.Events) { try { var unwrapedEvent = @event.Unwrap(); var rootId = System.Text.Encoding.UTF8.GetString(aggregateCommit.AggregateRootId); var eventOrigin = new EventOrigin(rootId, aggregateCommit.Revision, aggregateCommit.Events.IndexOf(@event), aggregateCommit.Timestamp); indexBuilder.Feed(unwrapedEvent, eventOrigin); } catch (Exception ex) { log.ErrorException(ex.Message, ex); } } } indexBuilder.Complete(); return(true); }
IEnumerable <IndexRecord> GetAllIndexRecords() { var eventsCounter = 0; foreach (var aggregateCommit in eventStorePlayer.LoadAggregateCommits()) { foreach (var @event in aggregateCommit.Events) { // TODO: Decorator if (eventsCounter % 1000 == 0) { log.Info(() => $"Rebuilding index progress: {eventsCounter}"); } string eventTypeId = @event.Unwrap().GetType().GetContractId(); yield return(new IndexRecord(eventTypeId, aggregateCommit.AggregateRootId)); eventsCounter++; } } }
protected override async Task <JobExecutionStatus> RunJob(IClusterOperations cluster, CancellationToken cancellationToken = default) { bool hasMoreRecords = true; while (hasMoreRecords && Data.IsCompleted == false) { var result = eventStorePlayer.LoadAggregateCommits(Data.PaginationToken); foreach (var aggregateCommit in result.Commits) { index.Index(aggregateCommit); } Data.PaginationToken = result.PaginationToken; Data = await cluster.PingAsync(Data).ConfigureAwait(false); hasMoreRecords = result.Commits.Any(); } Data.IsCompleted = true; Data = await cluster.PingAsync(Data).ConfigureAwait(false); return(JobExecutionStatus.Completed); }
public void Rebuild(Type projectionType, ProjectionVersion version) { projectionStore.InitializeProjectionStore(version); foreach (var aggregateCommit in eventStorePlayer.LoadAggregateCommits()) { foreach (var @event in aggregateCommit.Events) { try { var unwrapedEvent = @event.Unwrap(); var rootId = System.Text.Encoding.UTF8.GetString(aggregateCommit.AggregateRootId); var eventOrigin = new EventOrigin(rootId, aggregateCommit.Revision, aggregateCommit.Events.IndexOf(@event), aggregateCommit.Timestamp); projectionRepository.Save(projectionType, @event, eventOrigin); } catch (Exception ex) { log.ErrorException(ex.Message, ex); } } } }
public void Validate(EventStreamIntegrityPolicy policy) { var aggregateCommits = new List <AggregateCommit>(); byte[] currentId = { 0 }; foreach (var commit in player.LoadAggregateCommits(1000)) { if (ByteArrayHelper.Compare(currentId, commit.AggregateRootId) == false) { if (aggregateCommits.Count > 0) { var result = policy.Apply(new EventStream(aggregateCommits)); if (result.IsIntegrityViolated) { throw new Exception(result.Output.ToString()); } aggregateCommits.Clear(); } } aggregateCommits.Add(commit); currentId = commit.AggregateRootId; } }