private static IDisposable WhenNewProviderArrives(IObservable <IDataProvider> providers, IObserver <IAccount> observer, Predicate <IAccount> filter)
 {
     return(providers.AsObservable().Subscribe((provider) =>
     {
         _log.DebugFormat("New provider is created - {0}", provider.Name);
         var task = new Task(() =>
         {
             var accounts = provider.GetAccounts();
             foreach (var account in accounts)
             {
                 if (filter(account))
                 {
                     _log.InfoFormat("New account created - {0} : {1}", provider.Name, account.AccountId);
                     ProvidersMap.Add(account, provider);
                     observer.OnNext(account);
                 }
             }
             observer.OnCompleted();
         });
         task.Start();
     },
                                               (error) =>
     {
         _log.ErrorFormat("Cannot create provider - {0}. \n Deatils: {1}", error.Message, error.StackTrace);
         observer.OnError(error);
     }));
 }
Beispiel #2
0
        public static IObservableChannel MockObservableChannel(IObservable <IObserverDto <ProtocolMessage> > replaySubject)
        {
            var mockChannel       = Substitute.For <IChannel>();
            var mockEventStream   = replaySubject.AsObservable();
            var observableChannel = new ObservableChannel(mockEventStream, mockChannel);

            return(observableChannel);
        }
 public ConnectableObservable(IObservable <T> source, ISubject <T> subject)
 {
     this.source  = source.AsObservable();
     this.subject = subject;
 }
Beispiel #4
0
 /// <summary>
 /// Creates an observable that can be connected and disconnected from its source.
 /// </summary>
 /// <param name="source">Underlying observable source sequence that can be connected and disconnected from the wrapper.</param>
 /// <param name="subject">Subject exposed by the connectable observable, receiving data from the underlying source sequence upon connection.</param>
 public ConnectableObservable(IObservable <TSource> source, ISubject <TSource, TResult> subject)
 {
     _subject = subject;
     _source  = source.AsObservable(); // This gets us auto-detach behavior; otherwise, we'd have to roll our own, including trampoline installation.
     _gate    = new object();
 }
Beispiel #5
0
 public ReconnectableObservable(IObservable <TSource> source, Func <ISubject <TSource, TResult> > subjectSelector)
 {
     subjectFactory   = subjectSelector;
     observableSource = source.AsObservable();
     gate             = new object();
 }
Beispiel #6
0
 public IObservable <RaceDataDto> GetStream()
 {
     return(_stream.AsObservable());
 }