Пример #1
0
        public static async Task MoveToAsync(Services.OneDrive.OneDriveStorageItem item, 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;
            }
        }
Пример #2
0
        public static async Task RenameAsync(Services.OneDrive.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 DeleteAsync(Services.OneDrive.OneDriveStorageItem 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();
        }
Пример #4
0
        /// <summary>
        /// Download a file
        /// </summary>
        /// <param name="item">File to download from OneDrive</param>
        /// <returns>Task to support await of async call.</returns>
        public static async Task DownloadAsync(Services.OneDrive.OneDriveStorageItem item)
        {
            try
            {
                Shell.Current.DisplayWaitRing = true;
                var oneDriveFile = (Services.OneDrive.OneDriveStorageFile)item;
                using (var remoteStream = await oneDriveFile.OpenAsync())
                {
                    await SaveToLocalFolder(remoteStream, oneDriveFile.Name);
                }
            }
            catch (Exception ex)
            {
                await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message);

                TrackingManager.TrackException(ex);
            }
            finally
            {
                Shell.Current.DisplayWaitRing = false;
            }
        }