static async Task commit_events(UncommittedEvents uncommitted_events)
    {
        var response = await event_store.Commit(uncommitted_events, Runtime.CreateExecutionContextFor(tenant)).ConfigureAwait(false);

        var newly_committed_events = response.Events.ToCommittedEvents();
        var all_committed_events   = committed_events.ToList();

        all_committed_events.AddRange(newly_committed_events);
        committed_events = new CommittedEvents(all_committed_events);
    }
Exemple #2
0
        // void FastForward(ICommandContext commandContext, T aggregateRoot)
        // {
        //     _logger.Trace($"FastForward - {typeof(T).AssemblyQualifiedName}");
        //     var identifier = _artifactTypeMap.GetArtifactFor(typeof(T));
        //     _logger.Trace($"With identifier '{identifier?.ToString()??"<unknown identifier>"}'");

        //     var version = _eventSourceVersions.GetFor(identifier, aggregateRoot.EventSourceId);
        //     aggregateRoot.FastForward(version);
        // }

        void ReApplyEvents(ICommandContext commandContext, T aggregateRoot)
        {
            var identifier      = _artifactTypeMap.GetArtifactFor(typeof(T));
            var commits         = _eventStore.Fetch(new EventSourceKey(aggregateRoot.EventSourceId, identifier.Id));
            var committedEvents = new CommittedEvents(aggregateRoot.EventSourceId, FromCommits(commits));

            if (committedEvents.HasEvents)
            {
                aggregateRoot.ReApply(committedEvents);
            }
        }
Exemple #3
0
        void SetupStore()
        {
            _store.StartOrContinue("m").Returns(new ProcessedCommitsCount(0));

            _store.GetNextBatch(Arg.Any <MigrationConfig>(), new ProcessedCommitsCount(3)).Returns(new CommittedEvents(new Commit[0]));
            CreateEvents();
            _commits = new CommittedEvents(
                new [] {
                Setup.Commit(_events[0], _events[1]),
                Setup.Commit(_events[2]),
                Setup.Commit(_events[3])
            }
                );
            _store.GetNextBatch(Arg.Any <MigrationConfig>(), new ProcessedCommitsCount(0)).Returns(_commits);
        }
    /// <inheritdoc />
    public async Task Commit(CommittedEvents events, ConsentId consent, ScopeId scope)
    {
        foreach (var @event in events)
        {
            var sequenceNumber = await _policies.WriteEvent.ExecuteAsync(
                _ => _receivedEventsWriter.Write(@event, consent, scope, CancellationToken.None),
                CancellationToken.None).ConfigureAwait(false);

            await _eventStoreClient.CommitExternal(new CommitExternalEventsRequest
            {
                ScopeId = scope.ToProtobuf(),
                Event   = new CommittedEvent(
                    sequenceNumber,
                    @event.Occurred,
                    @event.EventSource,
                    @event.ExecutionContext,
                    @event.Type,
                    @event.Public,
                    @event.Content).ToProtobuf()
            }, CancellationToken.None).ConfigureAwait(false);
        }
    }
Exemple #5
0
    static void should_have_stored_committed_events(IEventContentConverter event_content_converter, CommittedEvents events, List <Event> stored_events)
    {
        stored_events.Count.ShouldEqual(events.Count);
        if (stored_events.Count == 0)
        {
            return;
        }
        stored_events.ShouldEachConformTo(_ => _.Aggregate.WasAppliedByAggregate == false);
        stored_events.ShouldEachConformTo(_ => _.EventHorizon.FromEventHorizon == false);

        for (var i = 0; i < stored_events.Count; i++)
        {
            should_be_the_same_base_committed_event(event_content_converter, events[i], stored_events[i]);
        }
    }
Exemple #6
0
 public void ReApply(CommittedEvents eventStream)
 {
     throw new System.NotImplementedException();
 }
 public override void ReApply(CommittedEvents eventStream)
 {
     ReApplyCalled = true;
     EventsApplied = eventStream;
     base.ReApply(eventStream);
 }
Exemple #8
0
 /// <summary>
 /// Converts the <see cref="CommittedEvents" /> to <see cref="IEnumerable{T}" /> of <see cref="Contracts.CommittedEvent" />.
 /// </summary>
 /// <param name="committedEvents">The committed events.</param>
 /// <returns>The converted <see cref="IEnumerable{T}" /> of <see cref="Contracts.CommittedEvent" />.</returns>
 public static IEnumerable <Contracts.CommittedEvent> ToProtobuf(this CommittedEvents committedEvents) =>
 committedEvents.AsEnumerable().Select(_ => _.ToProtobuf());
Exemple #9
0
 public override void ReApply(CommittedEvents committedEvents)
 {
     ReApplyCalled = true;
     EventsApplied = committedEvents;
     base.ReApply(committedEvents);
 }