コード例 #1
0
        public async Task ReactAsync(EventBase @event, CancellationToken cancellationToken)
        {
            var context = @event.GetContext();

            var reactions = fFactory.Create(@event).ToArray();

            if (reactions.Length == 0)
            {
                fLogger.LogInformation(context, $"No reaction for event '{@event.GetType()}'");
                return;
            }

            // TODO: Paralelized reacting
            foreach (var reaction in reactions)
            {
                await reaction.ReactAsync(@event, cancellationToken);
            }
        }
コード例 #2
0
        private async Task HandleEventAsync(EventBase @event)
        {
            using (fLogger.TrackRequest(@event.GetContext(), $"SignalR - Authority client event - '{@event.GetType()}'.", out var requestContext))
            {
                try
                {
                    @event.ChangeContext(requestContext);
                    using var scope = fServiceProvider.CreateScope();
                    var reactionFacade = scope.ServiceProvider.GetRequiredService <IEventReactionFacade>();
                    await reactionFacade.ReactAsync(@event, fState.CancellationSource.Token);

                    requestContext.Success();
                }
                catch
                {
                    requestContext.Fail();
                    throw;
                }
            }
        }