private async Task <IEnumerable <T> > GetPageGraphSdkAsync(int pageSize, CancellationToken cancellationToken = default(CancellationToken)) { // First Call if (_isFirstCall) { _nextPageGraph = ((IDriveItemRequestBuilder)_requestBuilder).CreateChildrenRequest(pageSize, _orderBy, _filter); _isFirstCall = false; } if (cancellationToken.IsCancellationRequested) { return(null); } if (_nextPageGraph != null) { var oneDriveItems = await _nextPageGraph.GetAsync(cancellationToken); _nextPageGraph = oneDriveItems.NextPageRequest; return(ProcessResultGraphSdk(oneDriveItems)); } // no more data return(null); }
private async Task LoadNextPageAsync() { try { if (_nextPageRequest != null) { Task <IDriveItemChildrenCollectionPage> taskItems = _nextPageRequest.GetAsync(_cancelLoadFile.Token); IDriveItemChildrenCollectionPage items = await taskItems; if (!taskItems.IsCanceled) { foreach (DriveItem item in items) { _list.Items.Add(item); } _nextPageRequest = items.NextPageRequest; HasMore = _nextPageRequest != null; } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } }
/// <summary> /// Request a list of DriveItem from oneDrive and create a GraphOneDriveStorageItemsCollection Collection /// </summary> /// <param name="request">Http request to execute</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>When this method completes successfully, it returns GraphOneDriveStorageItemsCollection that represents the specified files or folders</returns> private async Task <OneDriveStorageItemsCollection> RequestOneDriveItemsAsync(IDriveItemChildrenCollectionRequest request, CancellationToken cancellationToken) { var oneDriveItems = await request.GetAsync(cancellationToken).ConfigureAwait(false); _nextPageItemsRequest = oneDriveItems.NextPageRequest; List <OneDriveStorageItem> items = new List <OneDriveStorageItem>(); foreach (var oneDriveItem in oneDriveItems) { items.Add(InitializeOneDriveStorageItem(oneDriveItem)); } return(new OneDriveStorageItemsCollection(items)); }
/// <summary> /// Request a list of Folder from oneDrive and create a MicrosoftGraphOneDriveItemCollection Collection /// </summary> /// <param name="request">Http request to execute</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>When this method completes successfully, it returns GraphOneDriveStorageItemsCollection that represents the specified files or folders</returns> private async Task <List <OneDriveStorageFolder> > RequestOneDriveFoldersAsync(IDriveItemChildrenCollectionRequest request, CancellationToken cancellationToken) { var oneDriveItems = await request.GetAsync(cancellationToken); _nextPageFoldersRequest = oneDriveItems.NextPageRequest; List <DriveItem> oneDriveFolders = QueryFolders(oneDriveItems); List <OneDriveStorageFolder> folders = new List <OneDriveStorageFolder>(); foreach (var oneDriveFolder in oneDriveFolders) { folders.Add(InitializeOneDriveStorageFolder(oneDriveFolder)); } return(folders); }
private async Task ProcessFiles(IDriveItemChildrenCollectionRequest childrenCollectionRequest, string path) { var driveItems = await childrenCollectionRequest.GetAsync(); var items = new List <DriveItem>(driveItems.CurrentPage); while (driveItems.NextPageRequest != null) { var request = driveItems .NextPageRequest; var response = await request.GetAsync(); items.AddRange(response.CurrentPage); driveItems = response; } foreach (var item in items) { if (item.Folder != null) { var request = _graphserviceClient .Me .Drive .Items[item.Id] .Children .Request(); Console.Write("O"); await ProcessFiles(request, $"{path}/{item.Name}"); } else { var file = new File { Id = item.Id, Name = item.Name, Uri = item.WebUrl, Path = path, Size = item.Size.GetValueOrDefault(), MimeType = item.File?.MimeType, Sha1Hash = item.File?.Hashes?.Sha1Hash }; _items.Add(file); Console.Write("o"); } } }
/// <summary> /// Request a list of items /// </summary> /// <param name="request">Http request to execute</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>When this method completes successfully, it returns a list of IOneDriveStorageFile that represents the specified files</returns> private async Task <List <OneDriveStorageFile> > RequestOneDriveFilesAsync(IDriveItemChildrenCollectionRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var oneDriveItems = await request.GetAsync(cancellationToken); _nextPageFilesRequest = oneDriveItems.NextPageRequest; // TODO: The first items on the list are never a file List <DriveItem> oneDriveFiles = QueryFiles(oneDriveItems); // TODO: Algo to get only File List <OneDriveStorageFile> files = new List <OneDriveStorageFile>(); foreach (var oneDriveFile in oneDriveFiles) { files.Add(InitializeOneDriveStorageFile(oneDriveFile)); } return(files); }
/// <summary> /// Gets an index-based range of files and folders from the list of all files and subfolders in the current folder. /// </summary> /// <param name="startIndex">The zero-based index of the first item in the range to get</param> /// <param name="maxItemsToRetrieve">The maximum number of items to get</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>When this method completes successfully, it returns a list of the subfolders and files in the current folder.</returns> public async Task <IReadOnlyList <OneDriveStorageItem> > GetItemsAsync(uint startIndex, uint maxItemsToRetrieve, CancellationToken cancellationToken = default(CancellationToken)) { IDriveItemChildrenCollectionRequest oneDriveitemsRequest = null; var request = ((IDriveItemRequestBuilder)RequestBuilder).Children.Request(); // skip is not working right now // oneDriveitemsRequest = request.Top((int)maxItemsToRetrieve).Skip((int)startIndex); int maxToRetrieve = (int)(maxItemsToRetrieve + startIndex); oneDriveitemsRequest = request.Top(maxToRetrieve); var tempo = await oneDriveitemsRequest.GetAsync(cancellationToken).ConfigureAwait(false); List <OneDriveStorageItem> items = new List <OneDriveStorageItem>(); for (int i = (int)startIndex; i < maxToRetrieve && i < tempo.Count; i++) { items.Add(InitializeOneDriveStorageItem(tempo[i])); } return(new OneDriveStorageItemsCollection(items)); }
private async Task LoadNextPageAsync() { try { if (_nextPageRequest != null) { Task <IDriveItemChildrenCollectionPage> taskItems = _nextPageRequest.GetAsync(_cancelLoadFile.Token); IDriveItemChildrenCollectionPage items = await taskItems; if (!taskItems.IsCanceled) { foreach (DriveItem item in items) { _list.Items.Add(item); } _nextPageRequest = items.NextPageRequest; HasMore = _nextPageRequest != null; } } } catch { } }
public static async Task <DriveItem[]> GetAllAsync(this IDriveItemChildrenCollectionRequest request) { var collectionPage = await request.GetAsync(); return(await GetAllAsync(collectionPage)); }