Exemplo n.º 1
0
 public DeviceService(IConnectableObservable <IDeviceView> source)
 {
     _disposable.Add(source
                     .GroupBy(x => x.DeviceId)
                     .Subscribe(deviceStream => {
         _disposable.Add(deviceStream
                         .Scan(DeviceUpdateEvent.GetInitialView(deviceStream.Key), DeviceUtils.Update)
                         .Subscribe(GetCreateSubject(deviceStream.Key)));
     }));
     _disposable.Add(source.Connect());
 }
Exemplo n.º 2
0
        BehaviorSubject <DeviceUpdateEvent> GetCreateSubject(Guid deviceId)
        {
            return(_streams.GetOrAdd(deviceId, Create).Value);

            Lazy <BehaviorSubject <DeviceUpdateEvent> > Create(Guid id)
            {
                return(new Lazy <BehaviorSubject <DeviceUpdateEvent> >(() => {
                    var subject = new BehaviorSubject <DeviceUpdateEvent>(DeviceUpdateEvent.GetInitialView(deviceId));
                    _disposable.Add(subject);
                    return subject;
                }));
            }
        }