private void OnDownloadCardImages(object sender, RoutedEventArgs e) { Task.Factory.StartNew(() => { var download = new CardImageDownload(NotificationCenter.Instance); var definitions = StaticMagicData.CardDefinitions.ToList(); foreach (var card in definitions) { download.DownloadImage(card, null); } }); }
public static void OnImageChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { var instance = d as CardImage; if (instance != null) { instance.imageControl.Source = instance._emptyImage; // Trigger download and display var card = instance.SelectedCard; instance.SetDefinition = card != null ? StaticMagicData.SetDefinitionsBySetCode[card.SetCode] : null; MagicCardPrice cardPrice = null; var cardFileName = string.Empty; Task.Factory.StartNew(() => { cardPrice = StaticPriceDatabase.FindPrice(card, false, false, "CardImage control", false); var download = new CardImageDownload(instance._notificationCenter); cardFileName = download.DownloadImage(card, cardPrice); }).ContinueWith(task => { // Lookup card price: instance.CardPrice = cardPrice; if (string.IsNullOrWhiteSpace(cardFileName)) { instance.imageControl.Source = instance._emptyImage; } else { var uri = new Uri(cardFileName); var bitmap = new BitmapImage(uri); bitmap.Freeze(); instance.imageControl.Source = bitmap; } }, TaskScheduler.FromCurrentSynchronizationContext()); } }