private async Task NavigateBackGraphAsync() { if (_graphCurrentFolder != null) { Toolkit.Services.OneDrive.OneDriveStorageFolder currentFolder = null; Shell.Current.DisplayWaitRing = true; try { if (!string.IsNullOrEmpty(_graphCurrentFolder.Path)) { currentFolder = await _graphRootFolder.GetFolderAsync(_graphCurrentFolder.Path); } else { currentFolder = _graphRootFolder; } OneDriveItemsList.ItemsSource = await currentFolder.GetItemsAsync(20); _graphCurrentFolder = currentFolder; } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { Shell.Current.DisplayWaitRing = false; } } }
private async void GetFoldersAndFilesButton_Click(object sender, RoutedEventArgs e) { if (!await Tools.CheckInternetConnectionAsync()) { return; } string txtTop = TopText.Text; int top = 0; if (string.IsNullOrEmpty(txtTop)) { top = 20; } else { top = Convert.ToInt32(txtTop); } Shell.Current.DisplayWaitRing = true; try { if (_indexProvider == 3) { OneDriveItemsList.ItemsSource = await _graphCurrentFolder.GetItemsAsync(top); } else { OneDriveItemsList.ItemsSource = await _currentFolder.GetItemsAsync(top); } } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { Shell.Current.DisplayWaitRing = false; menuButton.Visibility = Visibility.Visible; BackButton.Visibility = Visibility.Visible; } }
private async Task SigninAsync(int indexProvider, string appClientId) { if (!await Tools.CheckInternetConnectionAsync()) { return; } Shell.Current.DisplayWaitRing = true; bool succeeded = false; try { // OnlineId if (indexProvider == 0) { Services.OneDrive.OneDriveService.Instance.Initialize(); } else if (indexProvider == 1) { Services.OneDrive.OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Msa, OneDriveScopes.OfflineAccess | OneDriveScopes.ReadWrite); } else if (indexProvider == 2) { Services.OneDrive.OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Adal); } else if (indexProvider == 3) { Services.OneDrive.OneDriveService.GraphInstance.Initialize(appClientId, DelegatedPermissionScopes.Text.Split(' ')); } if (indexProvider == 3) { if (!await Services.OneDrive.OneDriveService.GraphInstance.LoginAsync()) { throw new Exception("Unable to sign in"); } _graphCurrentFolder = _graphRootFolder = await Services.OneDrive.OneDriveService.GraphInstance.RootFolderForMeAsync(); OneDriveItemsList.ItemsSource = await _graphRootFolder.GetItemsAsync(20); } else { if (!await Services.OneDrive.OneDriveService.Instance.LoginAsync()) { throw new Exception("Unable to sign in"); } _currentFolder = _rootFolder = await Services.OneDrive.OneDriveService.Instance.RootFolderAsync(); OneDriveItemsList.ItemsSource = _rootFolder.GetItemsAsync(); } succeeded = true; } catch (ServiceException serviceEx) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(serviceEx); } catch (Exception ex) { await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message); TrackingManager.TrackException(ex); } finally { Shell.Current.DisplayWaitRing = false; } if (succeeded) { FilesBox.Visibility = Visibility.Visible; UserBox.Visibility = Visibility.Visible; ClientIdBox.Visibility = Visibility.Collapsed; ClientIdHelper.Visibility = Visibility.Collapsed; LogOutButton.Visibility = Visibility.Visible; ConnectButton.Visibility = Visibility.Collapsed; menuButton.Visibility = Visibility.Visible; BackButton.Visibility = Visibility.Visible; } else { FilesBox.Visibility = Visibility.Collapsed; UserBox.Visibility = Visibility.Collapsed; ClientIdBox.Visibility = Visibility.Visible; ClientIdHelper.Visibility = Visibility.Visible; LogOutButton.Visibility = Visibility.Collapsed; ConnectButton.Visibility = Visibility.Visible; menuButton.Visibility = Visibility.Collapsed; BackButton.Visibility = Visibility.Collapsed; } }