public static async Task RenameAsync(OneDriveStorageItem itemToRename) { try { Shell.Current.DisplayWaitRing = true; string newName = await OneDriveSampleHelpers.InputTextDialogAsync("New Name"); if (!string.IsNullOrEmpty(newName)) { await itemToRename.RenameAsync(newName); } } catch (ServiceException graphEx) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(graphEx); } catch (Exception ex) { await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message); TrackingManager.TrackException(ex); } finally { Shell.Current.DisplayWaitRing = false; } }
private async Task NavigateBackAsync() { if (_currentFolder != null) { OneDriveStorageFolder currentFolder = null; progressRing.IsActive = true; try { if (!string.IsNullOrEmpty(_currentFolder.Path)) { currentFolder = await _rootFolder.GetFolderAsync(_currentFolder.Path); } else { currentFolder = _rootFolder; } LstFolder.ItemsSource = await currentFolder.GetFoldersAsync(100); _currentFolder = currentFolder; } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { progressRing.IsActive = false; } } }
public static async Task MoveToAsync(OneDriveStorageItem item, OneDriveStorageFolder rootFolder) { Shell.Current.DisplayWaitRing = true; try { var folder = await OneDriveSampleHelpers.OpenFolderPicker("Move to", rootFolder); if (folder != null) { await item.MoveAsync(folder); } } catch (ServiceException exService) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(exService); } catch (Exception ex) { await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message); TrackingManager.TrackException(ex); } finally { Shell.Current.DisplayWaitRing = false; } }
private async Task DeleteAsync(IOneDriveStorageItem itemToDelete) { MessageDialog messageDialog = new MessageDialog($"Are you sure you want to delete '{itemToDelete.Name}'", "Delete"); messageDialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Shell.Current.DisplayWaitRing = true; }); try { await itemToDelete.DeleteAsync(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { OneDriveItemsList.ItemsSource = _currentFolder.GetItemsAsync(); }); } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Shell.Current.DisplayWaitRing = false; }); } }))); messageDialog.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { return; }))); messageDialog.DefaultCommandIndex = 0; messageDialog.CancelCommandIndex = 1; var command = await messageDialog.ShowAsync(); }
private async Task NavigateBackAsync() { if (_currentFolder != null) { IOneDriveStorageFolder currentFolder = null; Shell.Current.DisplayWaitRing = true; try { if (!string.IsNullOrEmpty(_currentFolder.Path)) { currentFolder = await _rootFolder.GetFolderAsync(_currentFolder.Path); } else { currentFolder = _rootFolder; } OneDriveItemsList.ItemsSource = currentFolder.GetItemsAsync(); _currentFolder = 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 { 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 void ThumbnailButton_Click(object sender, RoutedEventArgs e) { try { Shell.Current.DisplayWaitRing = true; if (_indexProvider == 3) { var file = (Toolkit.Services.OneDrive.OneDriveStorageItem)((AppBarButton)e.OriginalSource).DataContext; using (var stream = (await file.StorageItemPlatformService.GetThumbnailAsync(Toolkit.Services.MicrosoftGraph.MicrosoftGraphEnums.ThumbnailSize.Large)) as IRandomAccessStream) { await OneDriveSampleHelpers.DisplayThumbnail(stream, "thumbnail"); } } else { var file = (Services.OneDrive.OneDriveStorageItem)((AppBarButton)e.OriginalSource).DataContext; using (var stream = await file.GetThumbnailAsync(ThumbnailSize.Large)) { await OneDriveSampleHelpers.DisplayThumbnail(stream, "thumbnail"); } } } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { Shell.Current.DisplayWaitRing = false; } }
private async void ThumbnailButton_Click(object sender, RoutedEventArgs e) { try { Shell.Current.DisplayWaitRing = true; var file = (IOneDriveStorageItem)((AppBarButton)e.OriginalSource).DataContext; using (var stream = await file.GetThumbnailAsync(ThumbnailSize.Large)) { await OneDriveSampleHelpers.DisplayThumbnail(stream, "thumbnail"); } } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { Shell.Current.DisplayWaitRing = false; } }
private async Task NavigateToFolderAsync(IOneDriveStorageItem item) { if (item.IsFolder()) { Shell.Current.DisplayWaitRing = true; try { var currentFolder = await _currentFolder.GetFolderAsync(item.Name); OneDriveItemsList.ItemsSource = currentFolder.GetItemsAsync(); _currentFolder = currentFolder; } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { Shell.Current.DisplayWaitRing = false; } } }
private async Task NavigateToFolderAsync(OneDriveStorageItem item) { progressRing.IsActive = true; try { var currentFolder = await _graphCurrentFolder.GetFolderAsync(item.Name); var items = await currentFolder.GetFoldersAsync(100); if (items.Count > 0) { LstFolder.ItemsSource = items; _graphCurrentFolder = currentFolder; } } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { progressRing.IsActive = false; } }
/// <summary> /// Create a new folder in the current folder /// </summary> /// <param name="folder">Destination folder where to create the new folder</param> /// <returns>Task to support await of async call.</returns> public static async Task NewFolderAsync(OneDriveStorageFolder folder) { if (folder != null) { Shell.Current.DisplayWaitRing = true; try { string newFolderName = await OneDriveSampleHelpers.InputTextDialogAsync("New Folder Name"); if (!string.IsNullOrEmpty(newFolderName)) { await folder.StorageFolderPlatformService.CreateFolderAsync(newFolderName, CreationCollisionOption.GenerateUniqueName); } } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { Shell.Current.DisplayWaitRing = false; } } }
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) { OneDriveService.Instance.Initialize(); } else if (indexProvider == 1) { OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Msa, OneDriveScopes.OfflineAccess | OneDriveScopes.ReadWrite); } else if (indexProvider == 2) { OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Adal); } else if (indexProvider == 3) { OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Msal); } if (!await OneDriveService.Instance.LoginAsync()) { throw new Exception("Unable to sign in"); } _currentFolder = _rootFolder = await 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; } }
private async Task SigninAsync(string appClientId) { if (!await Tools.CheckInternetConnectionAsync()) { return; } SampleController.Current.DisplayWaitRing = true; bool succeeded = false; try { // Converged app authentication // Get the selected Delegated Permissions var scopes = DelegatedPermissions.SelectedItems as string[]; // If the user hasn't selected a scope then set it to FilesReadAll if (scopes == null) { scopes = new string[] { MicrosoftGraphScope.FilesReadAll }; } OneDriveService.Instance.Initialize(appClientId, scopes, null, null); if (!await OneDriveService.Instance.LoginAsync()) { throw new Exception("Unable to sign in"); } _graphCurrentFolder = _graphRootFolder = await OneDriveService.Instance.RootFolderForMeAsync(); OneDriveItemsList.ItemsSource = await _graphRootFolder.GetItemsAsync(20); OneDriveItemsList.Visibility = Visibility.Visible; succeeded = true; } catch (ServiceException serviceEx) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(serviceEx); } catch (Exception ex) { await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message); TrackingManager.TrackException(ex); } finally { SampleController.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; } }