/// <summary> /// Returns strong typed page of data. /// </summary> /// <param name="pageIndex">Page number.</param> /// <param name="pageSize">Size of page.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns>Strong typed page of data.</returns> public async Task <IEnumerable <T> > GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default(CancellationToken)) { // First Call if (_isFirstCall) { _nextPage = _requestBuilder.CreateChildrenRequest(pageSize, _orderBy, _filter); _isFirstCall = false; } if (cancellationToken.IsCancellationRequested) { return(null); } if (_nextPage != null) { var oneDriveItems = await _nextPage.GetAsync(cancellationToken); _nextPage = oneDriveItems.NextPageRequest; return(ProcessResult(oneDriveItems)); } // no more data return(null); }
/// <summary> /// Create children http request with specific options /// </summary> /// <param name="top">The number of items to return in a result set.</param> /// <param name="orderBy">Sort the order of items in the response collection</param> /// <param name="filter">Filters the response based on a set of criteria.</param> /// <returns>Returns the http request</returns> private IItemChildrenCollectionRequest CreateChildrenRequest(int top, OrderBy orderBy = OrderBy.None, string filter = null) { IItemChildrenCollectionRequest oneDriveitemsRequest = null; if (orderBy == OrderBy.None && string.IsNullOrEmpty(filter)) { return(((IItemRequestBuilder)RequestBuilder).Children.Request().Top(top)); } if (orderBy == OrderBy.None) { return(((IItemRequestBuilder)RequestBuilder).Children.Request().Top(top).Filter(filter)); } string order = $"{orderBy} asc".ToLower(); if (string.IsNullOrEmpty(filter)) { oneDriveitemsRequest = ((IItemRequestBuilder)RequestBuilder).Children.Request().Top(top).OrderBy(order); } else { oneDriveitemsRequest = ((IItemRequestBuilder)RequestBuilder).Children.Request().Top(top).OrderBy(order).Filter(filter); } return(oneDriveitemsRequest); }
/// <summary> /// Create children http request with specific options /// </summary> /// <param name="requestBuilder">request builder</param> /// <param name="top">The number of items to return in a result set.</param> /// <param name="orderBy">Sort the order of items in the response collection</param> /// <param name="filter">Filters the response based on a set of criteria.</param> /// <returns>Returns the http request</returns> public static IItemChildrenCollectionRequest CreateChildrenRequest(this IItemRequestBuilder requestBuilder, int top, OrderBy orderBy = OrderBy.None, string filter = null) { IItemChildrenCollectionRequest oneDriveitemsRequest = null; if (orderBy == OrderBy.None && string.IsNullOrEmpty(filter)) { return(requestBuilder.Children.Request().Top(top)); } if (orderBy == OrderBy.None) { return(requestBuilder.Children.Request().Top(top).Filter(filter)); } string order = OneDriveHelper.TransformOrderByToODataString(orderBy); if (string.IsNullOrEmpty(filter)) { oneDriveitemsRequest = requestBuilder.Children.Request().Top(top).OrderBy(order); } else { oneDriveitemsRequest = requestBuilder.Children.Request().Top(top).OrderBy(order).Filter(filter); } return(oneDriveitemsRequest); }
/// <summary> /// Initializes the NextPageRequest property. /// </summary> public void InitializeNextPageRequest(IBaseClient client, string nextPageLinkString) { if (!string.IsNullOrEmpty(nextPageLinkString)) { this.NextPageRequest = new ItemChildrenCollectionRequest( nextPageLinkString, client, null); } }
/// <summary> /// Request a list of DriveItem 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 MicrosoftGraphOneDriveItemCollection that represents the specified files or folders</returns> private async Task <OneDriveStorageItemsCollection> RequestOneDriveItemsAsync(IItemChildrenCollectionRequest request, CancellationToken cancellationToken) { var oneDriveItems = await request.GetAsync(cancellationToken).ConfigureAwait(false); _nextPageItemsRequest = oneDriveItems.NextPageRequest; List <IOneDriveStorageItem> items = new List <IOneDriveStorageItem>(); foreach (var oneDriveItem in oneDriveItems) { items.Add(InitializeOneDriveStorageItem(oneDriveItem.CopyToDriveItem())); } 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 MicrosoftGraphOneDriveItemCollection that represents the specified files or folders</returns> private async Task <List <IOneDriveStorageFolder> > RequestOneDriveFoldersAsync(IItemChildrenCollectionRequest request, CancellationToken cancellationToken) { var oneDriveItems = await request.GetAsync(cancellationToken); _nextPageFoldersRequest = oneDriveItems.NextPageRequest; List <Item> oneDriveFolders = QueryFolders(oneDriveItems); List <IOneDriveStorageFolder> folders = new List <IOneDriveStorageFolder>(); foreach (var oneDriveFolder in oneDriveFolders) { folders.Add(InitializeOneDriveStorageFolder(oneDriveFolder.CopyToDriveItem())); } return(folders); }
/// <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 OneDriveStorageFile that represents the specified files</returns> private async Task <List <IOneDriveStorageFile> > RequestOneDriveFilesAsync(IItemChildrenCollectionRequest 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 <Item> oneDriveFiles = QueryFiles(oneDriveItems); // TODO: Algo to get only File List <IOneDriveStorageFile> files = new List <IOneDriveStorageFile>(); foreach (var oneDriveFile in oneDriveFiles) { files.Add(InitializeOneDriveStorageFile(oneDriveFile.CopyToDriveItem())); } return(files); }
/// <inheritdoc/> public async Task <IReadOnlyList <IOneDriveStorageItem> > GetItemsAsync(uint startIndex, uint maxItemsToRetrieve, CancellationToken cancellationToken = default(CancellationToken)) { IItemChildrenCollectionRequest oneDriveitemsRequest = null; var request = ((IItemRequestBuilder)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 <IOneDriveStorageItem> items = new List <IOneDriveStorageItem>(); for (int i = (int)startIndex; i < maxToRetrieve && i < tempo.Count; i++) { items.Add(InitializeOneDriveStorageItem(tempo[i].CopyToDriveItem())); } return(new OneDriveStorageItemsCollection(items)); }
/// <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> /// <returns>When this method completes successfully, it returns a list of the subfolders and files in the current folder.</returns> public async Task <OneDriveStorageItemsCollection> GetItemsAsync(uint startIndex, uint maxItemsToRetrieve) { IItemChildrenCollectionRequest oneDriveitemsRequest = null; var request = 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().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 ListFilesFolders(string path) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // update the title path if (path == "/") { pathText.Text = "CloudStreamer"; } else { pathText.Text = path; } fileScrollViewer.Visibility = Visibility.Collapsed; progressRing.Visibility = Visibility.Visible; progressRing.IsActive = true; }); // handle login try { await UpdateOrInitOneDriveAuthIfNecessary(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e, "error"); try { await ExitOrRetryWithMessage("Failed to authenticate with OneDrive. Error: " + e.ToString()); } catch (Exception ex) { Crashes.TrackError(ex, new Dictionary <string, string> { { "On", "Call Error Dialog" }, { "Where", "MainPage.xaml:InitOneDrive" }, { "DueTo", e.Message } }); } return; } if (oneDriveClient == null) { return; } try { IItemChildrenCollectionRequest request; if (path == "/") { request = oneDriveClient.Drive.Root.Children.Request(); } else { request = oneDriveClient.Drive.Root.ItemWithPath(path).Children.Request(); } IItemChildrenCollectionRequest sortedRequest = request.OrderBy(currentSortBy + " " + currentSortByDir); sortedRequest = sortedRequest.Expand("thumbnails"); files = (ItemChildrenCollectionPage)await sortedRequest.GetAsync(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e, "error"); try { await ExitOrRetryWithMessage("Failed to load Files from OneDrive. Error: " + e.ToString()); } catch (Exception ex) { Crashes.TrackError(ex, new Dictionary <string, string> { { "On", "Call Error Dialog" }, { "Where", "MainPage.xaml:ListFilesFolders" }, { "DueTo", e.Message } }); } } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { fileItems = new IncrementalLoadingCollection(files); fileScrollViewer.ItemsSource = fileItems; loading = false; progressRing.IsActive = false; progressRing.Visibility = Visibility.Collapsed; fileScrollViewer.Visibility = Visibility.Visible; }); System.Diagnostics.Debug.WriteLine("Got " + fileItems.Count() + " files"); }
/// <inheritdoc/> public async Task <IReadOnlyList <IOneDriveStorageItem> > GetItemsAsync(int top, OrderBy orderBy = OrderBy.None, string filter = null, CancellationToken cancellationToken = default(CancellationToken)) { IItemChildrenCollectionRequest oneDriveItemsRequest = RequestBuilder.CreateChildrenRequest(top, orderBy, filter); return(await RequestOneDriveItemsAsync(oneDriveItemsRequest, cancellationToken).ConfigureAwait(false)); }
/// <inheritdoc/> public async Task <List <IOneDriveStorageFolder> > GetFoldersAsync(int top = 100, OrderBy orderBy = OrderBy.None, string filter = null, CancellationToken cancellationToken = default(CancellationToken)) { IItemChildrenCollectionRequest oneDriveItemsRequest = CreateChildrenRequest(top, orderBy, filter); return(await RequestOneDriveFoldersAsync(oneDriveItemsRequest, cancellationToken)); }