Ejemplo n.º 1
0
        private static async Task MainAsync(IAmACommandProcessor commandProcessor)
        {
            // To allow the event handler(s) to release the thread
            // while doing potentially long running operations,
            // await the async (but inline) handling of the events
            await commandProcessor.PublishAsync(new GreetingEvent("Ian"));

            try
            {
                // This will cause an exception in one event handler
                await commandProcessor.PublishAsync(new GreetingEvent("Roger"));
            }
            catch (AggregateException e)
            {
                Console.WriteLine("Aggregate exception thrown after event Roger:");
                ShowExceptions(e, 1);
            }

            try
            {
                // This will cause an exception in both event handlers
                await commandProcessor.PublishAsync(new GreetingEvent("Devil"));
            }
            catch (AggregateException e)
            {
                Console.WriteLine("Aggregate exception thrown after event Devil:");
                ShowExceptions(e, 1);
            }
        }
Ejemplo n.º 2
0
        private static async Task MainAsync(IAmACommandProcessor commandProcessor)
        {
            // To allow the event handler(s) to release the thread
            // while doing potentially long running operations,
            // await the async (but inline) handling of the events
            await commandProcessor.PublishAsync(new GreetingEvent("Ian"));

            try
            {
                // This will cause an exception in one event handler
                await commandProcessor.PublishAsync(new GreetingEvent("Roger"));
            }
            catch (AggregateException e)
            {
                Console.WriteLine("Aggregate exception thrown after event Roger:");
                ShowExceptions(e, 1);
            }

            try
            {
                // This will cause an exception in both event handlers
                await commandProcessor.PublishAsync(new GreetingEvent("Devil"));
            }
            catch (AggregateException e)
            {
                Console.WriteLine("Aggregate exception thrown after event Devil:");
                ShowExceptions(e, 1);
            }
        }
Ejemplo n.º 3
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            // To allow the event handler(s) to release the thread
            // while doing potentially long running operations,
            // await the async (but inline) handling of the events
            await _commandProcessor.PublishAsync(new GreetingEvent("Ian"), cancellationToken : cancellationToken);


            try
            {
                // This will cause an exception in one event handler
                await _commandProcessor.PublishAsync(new GreetingEvent("Roger"), cancellationToken : cancellationToken);
            }
            catch (AggregateException e)
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;

                Console.WriteLine("Aggregate exception thrown after event Roger:");
                ShowExceptions(e, 1);

                Console.ResetColor();
            }

            try
            {
                // This will cause an exception in both event handlers
                await _commandProcessor.PublishAsync(new GreetingEvent("Devil"), cancellationToken : cancellationToken);
            }
            catch (AggregateException e)
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;

                Console.WriteLine("Aggregate exception thrown after event Devil:");
                ShowExceptions(e, 1);

                Console.ResetColor();
            }
        }
Ejemplo n.º 4
0
 public async Task PublishAsync <T>(T @event, bool continueOnCapturedContext = false, CancellationToken cancellationToken = default)
     where T : class, IRequest
 {
     await _commandProcessor.PublishAsync(@event, continueOnCapturedContext, cancellationToken);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Publish an event 0-n handler functions.
 /// </summary>
 /// <param name="eventToPublish">Event object to be published on the event bus.</param>
 /// <param name="cancellationToken">Cancellation token</param>
 /// <returns>Task.</returns>
 Task IEventPublisher.Publish(IList <IEvent> eventToPublish, CancellationToken?cancellationToken)
 => Task.WhenAll(
     eventToPublish
     .Select(p => _commandProcessor.PublishAsync(new BrighterEvent(p)))
     .ToList()
     );