public PriceBlotterViewModel(IDependencyContainer container) { _instrumentPriceUpdateSubject = new Subject <KeyValuePair <string, InstrumentPriceUpdate[]> >(); DoubleClickPriceCommand = new DelegateCommand(o => o != null, o => { var evt = DisplayPriceHistory; if (evt != null) { string selectedPriceInstrument = ((InstrumentPrice)o).InstrumentName; evt(this, new PriceHistoryEventArgs(selectedPriceInstrument)); } }); _instrumentUpdaterTaskFactory = new TaskFactory(TaskScheduler.FromCurrentSynchronizationContext()); _priceAggregatorService = container.Resolve <IPriceAggregatorService>(); IDisposable aggregatedPriceChangeSubscription = _priceAggregatorService.Subscribe(new System.Reactive.AnonymousObserver <AggregatedPriceChangeNotification>(item => { _instrumentUpdaterTaskFactory.StartNew(() => { AggregatedPriceChangeNotification tmpNotification = item; UpdateDataSource(tmpNotification); if (!_compositeDisposable.IsDisposed) { _instrumentPriceUpdateSubject.OnNext(new KeyValuePair <string, InstrumentPriceUpdate[]>(tmpNotification.LatestUpdate.Instrument, tmpNotification.RecentPriceChanges)); } }); })); _priceAggregatorService.SubScribeToNotifications(); _compositeDisposable = new CompositeDisposable(aggregatedPriceChangeSubscription, _instrumentPriceUpdateSubject, (IDisposable)container); }
public void UpdateDataSource(AggregatedPriceChangeNotification value) { AggregatedPriceChangeNotification tmpValue = value; InstrumentPrice instrumentPrice = InstrumentPrices.FirstOrDefault(x => x.InstrumentName == value.LatestUpdate.Instrument); if (instrumentPrice == null) { InstrumentPrices.Add(new InstrumentPrice { AveragePrice = value.AveragePrice, InstrumentName = value.LatestUpdate.Instrument, Price = value.LatestUpdate.Price, RecentPriceChanges = new ObservableCollection <InstrumentPriceHistory>(value.RecentPriceChanges.Where(x => x != null).Select(x => new InstrumentPriceHistory { InstrumentName = x.Instrument, Price = x.Price } )), PriceChangeStatus = value.PriceChangeStatus, AveragePriceChangeStatus = value.AveragePriceChangeStatus }); } else { instrumentPrice.AveragePrice = value.AveragePrice; instrumentPrice.InstrumentName = value.LatestUpdate.Instrument; instrumentPrice.Price = value.LatestUpdate.Price; instrumentPrice.RecentPriceChanges = new ObservableCollection <InstrumentPriceHistory>( value .RecentPriceChanges .Where(x => x != null) .Select(x => new InstrumentPriceHistory { InstrumentName = x.Instrument, Price = x.Price } )); instrumentPrice.PriceChangeStatus = value.PriceChangeStatus; instrumentPrice.AveragePriceChangeStatus = value.AveragePriceChangeStatus; } }