/// <inheritdoc/> public async Task <IProjectionResult> Project(ProjectionCurrentState state, UncommittedEvent @event, ExecutionContext executionContext, CancellationToken cancellationToken) { try { _logger.ProjectEventThroughDispatcher(_embeddingId, state); var response = await _dispatcher.Call( _requestFactory.Create(state, @event), executionContext, cancellationToken).ConfigureAwait(false); if (IsFailureResponse(response)) { return(new ProjectionFailedResult(GetFailureReason(response))); } return(response.ResponseCase switch { EmbeddingResponse.ResponseOneofCase.ProjectionDelete => new ProjectionDeleteResult(), EmbeddingResponse.ResponseOneofCase.ProjectionReplace => new ProjectionReplaceResult(response.ProjectionReplace.State), EmbeddingResponse.ResponseOneofCase.Compare => new ProjectionFailedResult(new UnexpectedEmbeddingResponse(_embeddingId, response.ResponseCase)), EmbeddingResponse.ResponseOneofCase.Delete => new ProjectionFailedResult(new UnexpectedEmbeddingResponse(_embeddingId, response.ResponseCase)), _ => new ProjectionFailedResult(new UnexpectedEmbeddingResponse(_embeddingId, response.ResponseCase)) }); }
/// <inheritdoc/> public Task <IProjectionResult> Project(ProjectionCurrentState state, CommittedEvent @event, PartitionId partitionId, string failureReason, uint retryCount, ExecutionContext executionContext, CancellationToken cancellationToken) { var request = new ProjectionRequest { RetryProcessingState = new RetryProcessingState { FailureReason = failureReason, RetryCount = retryCount } }; return(Process(state, @event, partitionId, request, executionContext, cancellationToken)); }
async Task <IProjectionResult> Process(ProjectionCurrentState state, CommittedEvent @event, PartitionId partitionId, ProjectionRequest request, ExecutionContext executionContext, CancellationToken token) { request.Event = new Contracts.StreamEvent { Event = @event.ToProtobuf(), PartitionId = partitionId.Value, ScopeId = Definition.Scope.ToProtobuf(), }; request.CurrentState = state.ToProtobuf(); var response = await _dispatcher.Call(request, executionContext, token).ConfigureAwait(false); return(response switch { { Failure : null, ResponseCase : ProjectionResponse.ResponseOneofCase.Replace } => new ProjectionReplaceResult(response.Replace.State),
/// <inheritdoc/> public Task <IProjectionResult> Project(ProjectionCurrentState state, CommittedEvent @event, PartitionId partitionId, ExecutionContext executionContext, CancellationToken cancellationToken) => Process(state, @event, partitionId, new ProjectionRequest(), executionContext, cancellationToken);
/// <summary> /// Convert to a protobuf representation of <see cref="ProjectionCurrentState"/>. /// </summary> /// <param name="state"><see cref="ProjectionCurrentState"/> to convert.</param> /// <returns>Converted <see cref="ContractsProjectionCurrentState"/>.</returns> public static ContractsProjectionCurrentState ToProtobuf(this ProjectionCurrentState state) => new()
/// <inheritdoc/> public EmbeddingRequest Create(ProjectionCurrentState current, UncommittedEvent @event) => new()
static bool BatchWouldBeTooLarge(GetAllResponse batch, ProjectionCurrentState nextState) => batch.CalculateSize() + nextState.CalculateSize() > MaxBatchMessageSize;