void StartImageDownload(ListView listView, int position, IIconAndTitleItem audio) { if (_imageDownloadsInProgress.Contains(audio.Id)) { return; } var url = new Uri(audio.IconUrl); if (_imageDownloader.HasLocallyCachedCopy(url)) { var image = _imageDownloader.GetImage(url); FinishImageDownload(listView, position, audio, (Bitmap)image); } else { _imageDownloadsInProgress.Add(audio.Id); _imageDownloader.GetImageAsync(url).ContinueWith(t => { if (!t.IsFaulted) { FinishImageDownload(listView, position, audio, (Bitmap)t.Result); } }, TaskScheduler.FromCurrentSynchronizationContext() ); } }
void StartImageDownload(UITableView tableView, NSIndexPath indexPath, Person person) { if (imageDownloadsInProgress.Contains(person.Id)) { return; } imageDownloadsInProgress.Add(person.Id); imageDownloader.GetImageAsync(Gravatar.GetImageUrl(person.Email, 88)).ContinueWith(t => { if (!t.IsFaulted) { FinishImageDownload(tableView, indexPath, person, (UIImage)t.Result); } }, TaskScheduler.FromCurrentSynchronizationContext()); }
private static async void getImageThumbnail(string image, BitmapImage bmp) { try { var currAccount = PowerPlannerApp.Current.GetCurrentAccount(); if (currAccount == null) { return; } IFolder imagesFolder = await FileHelper.GetOrCreateImagesFolder(currAccount.LocalAccountId); //if already exists try { IFile file = await imagesFolder.GetFileAsync(image); if (file != null) { StorageFile nativeFile = await StorageFile.GetFileFromPathAsync(file.Path); if (nativeFile != null) { await getImageThumbnail(nativeFile, bmp); return; } } } catch { } //otherwise we need to download the image StorageFolder nativeImagesFolder = await StorageFolder.GetFolderFromPathAsync(imagesFolder.Path); await ImageDownloader.GetImageAsync(nativeImagesFolder, image, Website.GetImageUrl(currAccount.AccountId, image), bmp); } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); } }
private static async void getImage(string image, BitmapImage bmp) { try { var currAccount = PowerPlannerApp.Current.GetCurrentAccount(); if (currAccount == null) { return; } IFolder imagesFolder = await FileHelper.GetOrCreateImagesFolder(currAccount.LocalAccountId); StorageFolder nativeImagesFolder = await StorageFolder.GetFolderFromPathAsync(imagesFolder.Path); await ImageDownloader.GetImageAsync(nativeImagesFolder, image, Website.GetImageUrl(currAccount.AccountId, image), bmp); } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); } }