/// <inheritdoc/>
        protected override async Task <EventHandlerResponse> Handle(HandleEventRequest request, CancellationToken cancellationToken)
        {
            try
            {
                var committed = _converter.ToSDK(request.Event.Event);
                try
                {
                    if (committed.Event is TEventType typedEvent)
                    {
                        await _handler.Handle(typedEvent, committed.DeriveContext()).ConfigureAwait(false);

                        return(new EventHandlerResponse());
                    }

                    throw new EventHandlerDoesNotHandleEvent(typeof(TEventType));
                }
                finally
                {
                    try
                    {
                        var correlationId = committed.ExecutionContext.CorrelationId;
                        var eventType     = committed.Event.GetType();
                        _completion.EventHandlerCompletedForEvent(correlationId, Identifier, eventType);
                    }
                    catch (Exception ex)
                    {
                        _logger.Warning(ex, "Error notifying waiters of event handler completion");
                    }
                }
            }
            catch (CouldNotDeserializeEvent ex)
            {
                throw new CouldNotDeserializeEventFromScope(request.Event.ScopeId.To <ScopeId>(), ex);
            }
        }
Пример #2
0
        /// <inheritdoc/>
        public async Task <CommittedEvents> Commit(UncommittedEvents uncommittedEvents, CancellationToken cancellationToken)
        {
            _logger.Debug("Committing events");
            var request = new Contracts.CommitEventsRequest
            {
                CallContext = GetCurrentCallContext(),
            };

            request.Events.AddRange(_eventConverter.ToProtobuf(uncommittedEvents));
            var response = await _eventStoreClient.CommitAsync(request, cancellationToken : cancellationToken);

            ThrowIfFailure(response.Failure);
            try
            {
                return(_eventConverter.ToSDK(response.Events));
            }
            catch (CouldNotDeserializeEvent ex)
            {
                throw new CouldNotDeserializeEventFromScope(ScopeId.Default, ex);
            }
        }
Пример #3
0
        /// <inheritdoc/>
        protected override Task <TFilterResponse> Handle(FilterEventRequest request, CancellationToken cancellationToken)
        {
            try
            {
                var committed = _converter.ToSDK(request.Event);
                if (committed.Event is TEventType typedEvent)
                {
                    return(Filter(typedEvent, committed.DeriveContext()));
                }

                throw new EventTypeIsIncorrectForFilter(typeof(TEventType), committed.Event.GetType());
            }
            catch (CouldNotDeserializeEvent ex)
            {
                throw new CouldNotDeserializeEventFromScope(request.ScopeId.To <ScopeId>(), ex);
            }
        }