public void Update(PriceEventViewModel v)
 {
     Price        = v.Price;
     High         = v.High;
     Low          = v.Low;
     TimeStampUtc = v.TimeStampUtc;
 }
        private void InitUIAverage()
        {
            foreach (var feed in _priceFeeds)
            {
                var batchBlock  = new BatchBlock <PriceEventArgs>(5);
                var actionBlock = new ActionBlock <PriceEventArgs[]>(e =>
                {
                    var average = e.Average(v => v.Price);
                    var low     = e.Min(v => v.Price);
                    var high    = e.Max(v => v.Price);
                    var update  = new PriceEventViewModel(feed.Key, DateTime.UtcNow, average, low, high);
                    UpdatePrice(update, _averagePriceDict, AveragePrices);
                });

                _broadcastBlock.LinkTo(batchBlock, p => p.Name == feed.Key);
                batchBlock.LinkTo(actionBlock);
            }
        }
 private void UpdatePrice(PriceEventViewModel v, Dictionary <string, PriceEventViewModel> dictToUpdate,
                          ObservableCollection <PriceEventViewModel> collectionToUpdate)
 {
     if (App.Current != null)
     {
         App.Current.Dispatcher.Invoke(() =>
         {
             if (dictToUpdate.TryGetValue(v.Name, out var lastPrice))
             {
                 lastPrice.Update(v);
             }
             else
             {
                 dictToUpdate.Add(v.Name, v);
                 collectionToUpdate.Add(v);
             }
         });
     }
 }
        private void InitUILatestPriceTimeInterval()
        {
            foreach (var feed in _priceFeeds)
            {
                var batchBlock    = new BatchBlock <PriceEventArgs>(10000);
                var intervalTimer = new Timer(1000);
                intervalTimer.Elapsed += (s, e) => batchBlock.TriggerBatch();

                var updateUILatestPrice = new ActionBlock <PriceEventArgs[]>(e =>
                {
                    var latest = e.OrderByDescending(o => o.TimeStampUtc)
                                 .FirstOrDefault();
                    var low    = e.Min(v => v.Price);
                    var high   = e.Max(v => v.Price);
                    var update = new PriceEventViewModel(feed.Key, DateTime.UtcNow, latest.Price, low, high);

                    UpdatePrice(update, _latestPriceDict, LatestPrices);
                });

                _broadcastBlock.LinkTo(batchBlock, p => p.Name == feed.Key);
                batchBlock.LinkTo(updateUILatestPrice);
                intervalTimer.Start();
            }
        }