Exemplo n.º 1
0
        private void SubscribeByDelegateAndTopic <T>(Action <T> handler, Func <T, bool> topic, Action <Exception> onError)
        {
            IDisposable subscription            = GetSubscriptionSubject <T>();
            IObservableWithOutcomes <T> subject = (IObservableWithOutcomes <T>)subscription;

            SubscribeWithDelegate(handler, subject, onError, topic);
        }
Exemplo n.º 2
0
 /// <summary> An error has been caught coming from the user handler; we need to allow a hook to pipeline it. </summary>
 private static void OnHandlerError <T>(Action <Exception> a, Exception e, IObservableWithOutcomes <T> observable)
 {
     a(e);
     observable.Outcomes.Add(new ObservableOutcome {
         Error = e, Result = false
     });
 }
Exemplo n.º 3
0
        private void SubscribeByInterfaceAndTopic <T>(IConsume <T> consumer, Func <T, bool> topic, Action <Exception> onError)
        {
            IDisposable subscription            = GetSubscriptionSubject <T>();
            IObservableWithOutcomes <T> subject = (IObservableWithOutcomes <T>)subscription;

            SubscribeWithInterface(consumer, subject, onError, topic);
        }
Exemplo n.º 4
0
        private void SubscribeWithInterface <T>(IConsume <T> consumer, IObservableWithOutcomes <T> observable,
                                                Action <Exception> onError, Func <T, bool> filter = null)
        {
            var subscriptionType = typeof(T);
            var unsubscription   = _unsubscriptions.GetOrAdd(subscriptionType, t => new CancellationTokenSource());

            if (filter != null)
            {
                observable.Subscribe(@event =>
                {
                    try
                    {
                        if (!filter(@event))
                        {
                            observable.Outcomes.Add(new ObservableOutcome {
                                Result = false
                            });
                        }
                        else
                        {
                            var result = Handle(consumer, @event);
                            observable.Outcomes.Add(new ObservableOutcome {
                                Result = result
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        OnHandlerError(onError, ex, observable);
                    }
                }, e => OnError(e, observable), () => OnCompleted(observable), unsubscription.Token);
            }
            else
            {
                observable.Subscribe(@event =>
                {
                    try
                    {
                        var result = Handle(consumer, @event);
                        observable.Outcomes.Add(new ObservableOutcome {
                            Result = result
                        });
                    }
                    catch (Exception ex)
                    {
                        OnHandlerError(onError, ex, observable);
                    }
                }, e => OnError(e, observable), () => OnCompleted(observable), unsubscription.Token);
            }
        }
Exemplo n.º 5
0
 /// <summary> The observable sequence falted; technically this should never happen, since it would also cause observances to fail going forward on this thread, so we should treat this similarly to a fault, since delivery is shut down.</summary>
 private static void OnError <T>(Exception e, IObservableWithOutcomes <T> observable)
 {
     observable.Outcomes.Add(new ObservableOutcome {
         Error = e, Result = false
     });
 }
Exemplo n.º 6
0
 /// <summary> The observable sequence has completed; technically, this should never happen unless disposing, so we should treat this similarly to a fault since we can't guarantee delivery. </summary>
 private static void OnCompleted <T>(IObservableWithOutcomes <T> observable)
 {
     observable.Outcomes.Add(new ObservableOutcome {
         Result = false
     });
 }