Beispiel #1
0
    protected static Contracts.CommittedAggregateEvents with_committed_events(params Contracts.CommittedAggregateEvents.Types.CommittedAggregateEvent[] events)
    {
        var aggregate_version_after_commit = number_of_events_in_aggregate_when_commit_happened + (ulong)events.Length;
        var result = new Contracts.CommittedAggregateEvents
        {
            AggregateRootId = aggregate_root_id.ToProtobuf(),
            EventSourceId   = event_source_id,
            // The aggregate root version of the committed aggregate events is the version of the last event, meaning the aggregate root version before commit happened + number of events - 1
            AggregateRootVersion = aggregate_version_after_commit - 1
        };

        result.Events.AddRange(events);
        return(result);
    }
Beispiel #2
0
    public static async Task <FetchForAggregateResponse> FetchForAggregate(this IEventStore eventStore, ArtifactId aggregateRootId, EventSourceId eventSourceId, Dolittle.Runtime.Execution.ExecutionContext executionContext)
    {
        var response = await eventStore.FetchAggregateEvents(new FetchForAggregateRequest
        {
            CallContext = new CallRequestContext
            {
                ExecutionContext = executionContext.ToProtobuf()
            },
            Aggregate = new Aggregate {
                AggregateRootId = aggregateRootId.ToProtobuf(), EventSourceId = eventSourceId
            }
        }, CancellationToken.None);

        return(response);
    }
Beispiel #3
0
    /// <inheritdoc />
    public async Task <Try <AggregateRootWithTenantScopedInstances> > Get(MicroserviceAddress runtime, ArtifactId aggregateRootId, TenantId tenant = null)
    {
        var client  = _clients.CreateClientFor <AggregateRootsClient>(runtime);
        var request = new GetOneRequest()
        {
            TenantId        = tenant?.ToProtobuf(),
            AggregateRootId = aggregateRootId.ToProtobuf()
        };

        var response = await client.GetOneAsync(request);

        if (response.Failure is not null)
        {
            return(new GetOneFailed(response.Failure.Reason));
        }
        return(FromProtobuf(response.AggregateRoot));
    }
Beispiel #4
0
    /// <inheritdoc />
    public async Task <CommittedAggregateEvents> GetEvents(MicroserviceAddress runtime, ArtifactId aggregateRootId, EventSourceId eventSourceId, TenantId tenant = null)
    {
        var client  = _clients.CreateClientFor <AggregateRootsClient>(runtime);
        var request = new GetEventsRequest()
        {
            TenantId  = tenant?.ToProtobuf(),
            Aggregate = new Aggregate
            {
                AggregateRootId = aggregateRootId.ToProtobuf(),
                EventSourceId   = eventSourceId
            }
        };

        var response = await client.GetEventsAsync(request);

        if (response.Failure is not null)
        {
            throw new GetEventsFailed(response.Failure.Reason);
        }
        return(FromProtobuf(response.Events));
    }