Skip to content

Instantly share code, notes, and snippets.

@mattbarrett
Created May 5, 2014 18:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattbarrett/74b13723cbcceed5d7ff to your computer and use it in GitHub Desktop.
Save mattbarrett/74b13723cbcceed5d7ff to your computer and use it in GitHub Desktop.
private void LoadSpotTiles()
{
_referenceDataRepository.GetCurrencyPairsStream()
.ObserveOn(_concurrencyService.Dispatcher)
.SubscribeOn(_concurrencyService.TaskPool)
.Subscribe(
currencyPairs => currencyPairs.ForEach(HandleCurrencyPairUpdate),
error => _log.Error("Failed to get currencies", error));
}
private void HandleCurrencyPairUpdate(ICurrencyPairUpdate update)
{
var spotTileViewModel = SpotTiles.FirstOrDefault(stvm => stvm.CurrencyPair == update.CurrencyPair.Symbol);
if (update.UpdateType == UpdateType.Add)
{
if (spotTileViewModel != null)
{
// we already have a tile for this currency pair
return;
}
var spotTile = _spotTileFactory(update.CurrencyPair, _config.Config.SubscriptionMode);
SpotTiles.Add(spotTile);
}
else
{
if (spotTileViewModel != null)
{
SpotTiles.Remove(spotTileViewModel);
spotTileViewModel.Dispose();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment