/// <summary> /// Initializes a new instance of the <see cref="OneDriveStorageFolderPlatform"/> class. /// </summary> /// <param name="service">Instance of OneDriveService</param> /// <param name="oneDriveStorageFolder">Instance of OneDriveStorageFolder</param> public OneDriveStorageFolderPlatform( Toolkit.Services.OneDrive.OneDriveService service, Toolkit.Services.OneDrive.OneDriveStorageFolder oneDriveStorageFolder) { _service = service; _oneDriveStorageFolder = oneDriveStorageFolder; }
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; } } }
public FoldersPickerControl(List <Toolkit.Services.OneDrive.OneDriveStorageFolder> folders, Toolkit.Services.OneDrive.OneDriveStorageFolder rootFolder) { this.InitializeComponent(); _graphFolders = folders; _graphCurrentFolder = _graphRootFolder = rootFolder; _legacyMode = false; }
private void LstFolder_ItemClick(object sender, ItemClickEventArgs e) { if (!_legacyMode) { _graphDestinationFolder = e.ClickedItem as Toolkit.Services.OneDrive.OneDriveStorageFolder; } else { _destinationFolder = e.ClickedItem as OneDriveStorageFolder; } }
/// <summary> /// Upload large file. /// </summary> /// <param name="folder">The destination folder</param> /// <returns>Task to support await of async call.</returns> public static async Task UploadLargeFileAsync(Toolkit.Services.OneDrive.OneDriveStorageFolder folder) { try { if (folder != null) { var selectedFile = await OpenLocalFileAsync(); if (selectedFile != null) { using (var localStream = await selectedFile.OpenReadAsync()) { Shell.Current.DisplayWaitRing = true; // If the file exceed the Maximum size (ie 4MB) var largeFileCreated = await folder.StorageFolderPlatformService.UploadFileAsync(selectedFile.Name, localStream, CreationCollisionOption.GenerateUniqueName, 320 * 1024); } } } } catch (OperationCanceledException ex) { await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message); } catch (ServiceException graphEx) { await OneDriveSampleHelpers.DisplayMessageAsync(graphEx.Error.Message); } catch (Exception ex) { await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message); TrackingManager.TrackException(ex); } finally { Shell.Current.DisplayWaitRing = false; } }
private async Task NavigateToFolderAsync(Toolkit.Services.OneDrive.OneDriveStorageItem item) { if (item.IsFolder()) { Shell.Current.DisplayWaitRing = true; try { var currentFolder = await _graphCurrentFolder.GetFolderAsync(item.Name); OneDriveItemsList.ItemsSource = await currentFolder.GetItemsAsync(20); _graphCurrentFolder = currentFolder; } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { Shell.Current.DisplayWaitRing = 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(Toolkit.Services.OneDrive.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 NavigateToFolderAsync(Toolkit.Services.OneDrive.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> /// Creates an instance of platform-specific implementation. /// </summary> /// <param name="oneDriveService">Instance of the service.</param> /// <param name="oneDriveStorageFolder">Instance of the storage folder.</param> /// <returns>Returns concrete type.</returns> public IOneDriveStorageFolderPlatform CreateOneDriveStorageFolderPlatformInstance(Toolkit.Services.OneDrive.OneDriveService oneDriveService, Toolkit.Services.OneDrive.OneDriveStorageFolder oneDriveStorageFolder) { return(new OneDriveStorageFolderPlatform(oneDriveService, oneDriveStorageFolder)); }
public static async Task <Toolkit.Services.OneDrive.OneDriveStorageFolder> OpenFolderPicker(string title, Toolkit.Services.OneDrive.OneDriveStorageFolder rootFolder) { FoldersPickerControl folderPicker = new FoldersPickerControl(await rootFolder.GetFoldersAsync(100), rootFolder); ContentDialog dialog = new ContentDialog { Content = folderPicker, Title = title, PrimaryButtonText = "Ok" }; if (await dialog.ShowAsync() == ContentDialogResult.Primary) { return(folderPicker.SelectedGraphFolder); } else { return(null); } }
public static async Task MoveToAsync(Toolkit.Services.OneDrive.OneDriveStorageItem item, Toolkit.Services.OneDrive.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 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; } }