public IEnumerable <List <ThumbnailSet> > GetThumbnails(Drive drive, DriveItem driveItem, CancellationToken token) { IDriveItemThumbnailsCollectionPage page = null; try { page = client.Drives[drive.Id].Items[driveItem.Id].Thumbnails.Request().GetAsync(token).Result; } catch (Exception ex) { HandleException(ex, null, messageOnlyExceptions, $"Get thumbnails for drive item: {driveItem.Name ?? "unknown"}"); } while (page != null) { yield return(page.ToList()); if (page.NextPageRequest == null) { break; } page = page.NextPageRequest.GetAsync(token).Result; } }
private async void List_SelectionChanged(object sender, SelectionChangedEventArgs e) { _cancelGetDetails.Cancel(false); _cancelGetDetails.Dispose(); _cancelGetDetails = new CancellationTokenSource(); if (_list.SelectedItem is DriveItem driveItem && driveItem.File != null) { try { SelectedFile = driveItem; FileSize = driveItem.Size ?? 0; LastModified = driveItem.LastModifiedDateTime?.LocalDateTime.ToString() ?? string.Empty; if (FileSelected != null) { FileSelected.Invoke(this, new FileSelectedEventArgs(driveItem)); } ThumbnailImageSource = null; VisualStateManager.GoToState(this, NavStatesFileReadonly, false); GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { Task <IDriveItemPermissionsCollectionPage> taskPermissions = graphClient.Drives[_driveId].Items[driveItem.Id].Permissions.Request().GetAsync(_cancelGetDetails.Token); IDriveItemPermissionsCollectionPage permissions = await taskPermissions; if (!taskPermissions.IsCanceled) { foreach (Permission permission in permissions) { if (permission.Roles.Contains("write") || permission.Roles.Contains("owner")) { VisualStateManager.GoToState(this, NavStatesFileEdit, false); break; } } Task <IDriveItemThumbnailsCollectionPage> taskThumbnails = graphClient.Drives[_driveId].Items[driveItem.Id].Thumbnails.Request().GetAsync(_cancelGetDetails.Token); IDriveItemThumbnailsCollectionPage thumbnails = await taskThumbnails; if (!taskThumbnails.IsCanceled) { ThumbnailSet thumbnailsSet = thumbnails.FirstOrDefault(); if (thumbnailsSet != null) { Thumbnail thumbnail = thumbnailsSet.Large; if (thumbnail.Url.Contains("inputFormat=svg")) { SvgImageSource source = new SvgImageSource(); using (Stream inputStream = await graphClient.Drives[_driveId].Items[driveItem.Id].Content.Request().GetAsync()) { SvgImageSourceLoadStatus status = await source.SetSourceAsync(inputStream.AsRandomAccessStream()); if (status == SvgImageSourceLoadStatus.Success) { ThumbnailImageSource = source; } } } else { ThumbnailImageSource = new BitmapImage(new Uri(thumbnail.Url)); } } } IsDetailPaneVisible = true; ShowDetailsPane(); } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } }