Exemplo n.º 1
0
 /// <summary>
 /// Publishes information about an error that arose during the handling of an event.
 /// </summary>
 /// <param name="error">The error</param>
 /// <returns>
 ///     An <see cref="IObservable{T}" /> that will be notified once each time the event is handled.
 /// </returns>
 public virtual IObservable <Unit> PublishErrorAsync(EventHandlingError error)
 {
     return(Observable.Create <Unit>(observer =>
     {
         errorSubject.OnNext(error);
         observer.OnNext(Unit.Default);
         observer.OnCompleted();
         return Disposable.Empty;
     }));
 }
Exemplo n.º 2
0
 internal static IDisposable SubscribeDurablyAndPublishErrors <THandler, TEvent>(
     this IObservable <TEvent> events,
     THandler handler,
     Action <TEvent> handle,
     IEventBus bus)
     where TEvent : IEvent => events.Subscribe(
     onNext : e =>
 {
     try
     {
         handle(e);
     }
     catch (Exception exception)
     {
         var error = new EventHandlingError(exception, handler, e);
         bus.PublishErrorAsync(error).Wait();
     }
 },
     onError: exception => bus.PublishErrorAsync(new EventHandlingError(exception, handler))
     .Wait());
Exemplo n.º 3
0
 internal static IDisposable SubscribeConsequences <TEvent>(
     IHaveConsequencesWhen <TEvent> handler,
     IObservable <TEvent> observable,
     IEventBus bus)
     where TEvent : IEvent => observable
 .Subscribe(
     onNext : e =>
 {
     try
     {
         handler.HaveConsequences(e);
     }
     catch (Exception exception)
     {
         var error = new EventHandlingError(exception, handler, e);
         bus.PublishErrorAsync(error).Wait();
     }
 },
     onError: exception => bus.PublishErrorAsync(new EventHandlingError(exception, handler))
     .Wait());
Exemplo n.º 4
0
 internal static IDisposable SubscribeProjector <TEvent, TProjector>(
     TProjector handler,
     IObservable <TEvent> observable,
     IEventBus bus)
     where TEvent : IEvent
     where TProjector : class, IUpdateProjectionWhen <TEvent> =>
 observable
 .Subscribe(
     onNext : e =>
 {
     try
     {
         handler.UpdateProjection(e);
     }
     catch (Exception exception)
     {
         var error = new EventHandlingError(exception, handler, e);
         bus.PublishErrorAsync(error).Wait();
     }
 },
     onError: exception => bus.PublishErrorAsync(new EventHandlingError(exception, handler))
     .Wait());