protected virtual void OnLoadingError() { if (LoadingError != null) { LoadingError.Invoke(this, System.EventArgs.Empty); } }
protected virtual void OnLoadingError(Exception e) { ResetState(); _synchronizationContext.Send(state => { LoadingError?.Invoke(this, new ErrorEventArgs(e)); }, 0); }
public override void OnLoadingError(ILevelInfo pLevel, string error) { LoadingError?.Invoke(new EventArgs <ILevelInfo, string>(pLevel, error)); }
private async Task LoadFolderAsync(string id = null) { // Cancel any previous operation _cancellationTokenSource?.Cancel(); _cancellationTokenSource = new CancellationTokenSource(); // Check if session is set if (AuthenticationService == null) { throw new InvalidOperationException($"No {nameof(AuthenticationService)} has been specified"); } // Keep a local copy of the token because the source can change while executing this function var token = _cancellationTokenSource.Token; // Add an option to the REST API in order to get thumbnails for each file // https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_list_thumbnails var options = new[] { new QueryOption("$expand", "thumbnails"), }; // Create the graph request builder for the drive IDriveRequestBuilder driveRequest = AuthenticationService.GraphClient.Me.Drive; // If folder id is null, the request refers to the root folder IDriveItemRequestBuilder driveItemsRequest; if (id == null) { driveItemsRequest = driveRequest.Root; } else { driveItemsRequest = driveRequest.Items[id]; } // Raise the loading event FolderLoading?.Invoke(this, EventArgs.Empty); try { try { // Make a API request loading 50 items per time var page = await driveItemsRequest.Children.Request(options).Top(50).GetAsync(token); token.ThrowIfCancellationRequested(); // Load each page await LoadGridItemsAsync(page, token); token.ThrowIfCancellationRequested(); } finally { // Raise the loaded event FolderLoaded?.Invoke(this, EventArgs.Empty); } } catch (OperationCanceledException) { } catch (Exception ex) { // Raise the error event LoadingError?.Invoke(this, ex); } }