private async void searchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormInputDialog dialog = new FormInputDialog("Search", "Search for:");

            var result = dialog.ShowDialog();

            if (result != System.Windows.Forms.DialogResult.OK && !string.IsNullOrEmpty(dialog.InputText))
            {
                return;
            }

            try
            {
                ShowWork(true);
                var results = await Connection.SearchForItemsAsync(ODConnection.ItemReferenceForItemId("root"), dialog.InputText, ItemRetrievalOptions.Default);

                var form = new FormSyncResults(Connection, results);
                form.Show();
            }
            catch (ODException exception)
            {
                PresentOneDriveException(exception);
            }
            ShowWork(false);
        }
示例#2
0
        public async Task <Stream> GetContentAsync(RootName root, FileId source)
        {
            var context = await RequireContext(root);

            var itemReference = ODConnection.ItemReferenceForItemId(source.Value, context.Drive.Id);
            var stream        = await AsyncFunc.Retry <Stream, ODException>(async() => await context.Connection.DownloadStreamForItemAsync(itemReference, StreamDownloadOptions.Default), RETRIES);

            return(stream);
        }
示例#3
0
        public async Task <IEnumerable <FileSystemInfoContract> > GetChildItemAsync(RootName root, DirectoryId parent)
        {
            var context = await RequireContextAsync(root);

            var itemReference = ODConnection.ItemReferenceForItemId(parent.Value, context.Drive.Id);
            var items         = await retryPolicy.ExecuteAsync(() => context.Connection.GetChildrenOfItemAsync(itemReference, ChildrenRetrievalOptions.Default));

            return(items.Collection.Select(i => i.ToFileSystemInfoContract()));
        }
示例#4
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContextAsync(root);

            var itemReference = ODConnection.ItemReferenceForItemId(target.Value, context.Drive.Id);
            var success       = await retryPolicy.ExecuteAsync(() => context.Connection.DeleteItemAsync(itemReference, ItemDeleteOptions.Default));

            return(success);
        }
示例#5
0
        public async Task <DirectoryInfoContract> NewDirectoryItemAsync(RootName root, DirectoryId parent, string name)
        {
            var context = await RequireContextAsync(root);

            var itemReference = ODConnection.ItemReferenceForItemId(parent.Value, context.Drive.Id);
            var item          = await retryPolicy.ExecuteAsync(() => context.Connection.CreateFolderAsync(itemReference, name));

            return(new DirectoryInfoContract(item.Id, item.Name, item.CreatedDateTime, item.LastModifiedDateTime));
        }
示例#6
0
        public async Task <Stream> GetContentAsync(RootName root, FileId source)
        {
            var context = await RequireContextAsync(root);

            var itemReference = ODConnection.ItemReferenceForItemId(source.Value, context.Drive.Id);
            var stream        = await retryPolicy.ExecuteAsync(() => context.Connection.DownloadStreamForItemAsync(itemReference, StreamDownloadOptions.Default));

            return(stream);
        }
示例#7
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContext(root);

            var itemReference = ODConnection.ItemReferenceForItemId(target.Value, context.Drive.Id);
            var success       = await AsyncFunc.Retry <bool, ODException>(async() => await context.Connection.DeleteItemAsync(itemReference, ItemDeleteOptions.Default), RETRIES);

            return(success);
        }
示例#8
0
        public async Task <IEnumerable <FileSystemInfoContract> > GetChildItemAsync(RootName root, DirectoryId parent)
        {
            var context = await RequireContext(root);

            var itemReference = ODConnection.ItemReferenceForItemId(parent.Value, context.Drive.Id);
            var items         = await AsyncFunc.Retry <ODItemCollection, ODException>(async() => await context.Connection.GetChildrenOfItemAsync(itemReference, ChildrenRetrievalOptions.Default), RETRIES);

            return(items.Collection.Select(i => i.ToFileSystemInfoContract()));
        }
示例#9
0
        public async Task <DirectoryInfoContract> NewDirectoryItemAsync(RootName root, DirectoryId parent, string name)
        {
            var context = await RequireContext(root);

            var itemReference = ODConnection.ItemReferenceForItemId(parent.Value, context.Drive.Id);
            var item          = await AsyncFunc.Retry <ODItem, ODException>(async() => await context.Connection.CreateFolderAsync(itemReference, name), RETRIES);

            return(new DirectoryInfoContract(item.Id, item.Name, item.CreatedDateTime, item.LastModifiedDateTime));
        }
示例#10
0
        public async Task <FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            var itemReference = ODConnection.ItemReferenceForItemId(target.Value, context.Drive.Id);
            var item          = await retryPolicy.ExecuteAsync(() => context.Connection.PatchItemAsync(itemReference, new ODItem()
            {
                Name = newName
            }));

            return(item.ToFileSystemInfoContract());
        }
示例#11
0
        public async Task <FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            var itemReference = ODConnection.ItemReferenceForItemId(target.Value, context.Drive.Id);
            var item          = await AsyncFunc.Retry <ODItem, ODException>(async() => await context.Connection.PatchItemAsync(itemReference, new ODItem()
            {
                Name = newName
            }), RETRIES);

            return(item.ToFileSystemInfoContract());
        }
示例#12
0
        public async Task <FileSystemInfoContract> MoveItemAsync(RootName root, FileSystemId source, string moveName, DirectoryId destination, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            var itemReference            = ODConnection.ItemReferenceForItemId(source.Value, context.Drive.Id);
            var destinationPathReference = ODConnection.ItemReferenceForItemId(destination.Value, context.Drive.Id);
            var item = await retryPolicy.ExecuteAsync(() => context.Connection.PatchItemAsync(itemReference, new ODItem()
            {
                ParentReference = destinationPathReference, Name = moveName
            }));

            return(item.ToFileSystemInfoContract());
        }
示例#13
0
        public async Task <FileInfoContract> NewFileItemAsync(RootName root, DirectoryId parent, string name, Stream content, IProgress <ProgressValue> progress)
        {
            var context = await RequireContext(root);

            var itemReference = ODConnection.ItemReferenceForItemId(parent.Value, context.Drive.Id);
            var uploadOptions = progress != null ? new ItemUploadOptions()
            {
                ProgressReporter = (complete, transfered, total) => progress.Report(new ProgressValue(complete, (int)transfered, (int)total))
            } : ItemUploadOptions.Default;
            var item = await AsyncFunc.Retry <ODItem, ODException>(async() => await context.Connection.PutNewFileToParentItemAsync(itemReference, name, content, uploadOptions), RETRIES);

            return(new FileInfoContract(item.Id, item.Name, item.CreatedDateTime, item.LastModifiedDateTime, item.Size, item.File.Hashes.Sha1.ToLowerInvariant()));
        }
示例#14
0
        public async Task <bool> SetContentAsync(RootName root, FileId target, Stream content, IProgress <ProgressValue> progress, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            var itemReference = ODConnection.ItemReferenceForItemId(target.Value, context.Drive.Id);
            var uploadOptions = progress != null ? new ItemUploadOptions()
            {
                ProgressReporter = (complete, transfered, total) => progress.Report(new ProgressValue(complete, (int)transfered, (int)total))
            } : ItemUploadOptions.Default;
            var item = await AsyncFunc.Retry <ODItem, ODException>(async() => await context.Connection.PutContentsAsync(itemReference, content, uploadOptions), RETRIES);

            return(true);
        }
示例#15
0
        public async Task <bool> SetContentAsync(RootName root, FileId target, Stream content, IProgress <ProgressValue> progress, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            var itemReference = ODConnection.ItemReferenceForItemId(target.Value, context.Drive.Id);
            var uploadOptions = progress != null ? new ItemUploadOptions()
            {
                ProgressReporter = (complete, transfered, total) => progress.Report(new ProgressValue(complete, (int)transfered, (int)total))
            } : ItemUploadOptions.Default;
            var retryPolicyWithAction = Policy.Handle <ODException>().WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
                                                                                        (ex, ts) => content.Seek(0, SeekOrigin.Begin));
            var item = await retryPolicyWithAction.ExecuteAsync(() => context.Connection.PutContentsAsync(itemReference, content, uploadOptions));

            return(true);
        }
示例#16
0
        public async Task <FileSystemInfoContract> CopyItemAsync(RootName root, FileSystemId source, string copyName, DirectoryId destination, bool recurse)
        {
            var context = await RequireContext(root);

            var itemReference            = ODConnection.ItemReferenceForItemId(source.Value, context.Drive.Id);
            var destinationPathReference = ODConnection.ItemReferenceForItemId(destination.Value, context.Drive.Id);
            var task = await context.Connection.CopyItemAsync(itemReference, destinationPathReference, copyName);

            while (task.Status.Status != AsyncJobStatus.Complete)
            {
                await Task.Delay(20);

                await task.Refresh(context.Connection);
            }

            return(task.FinishedItem.ToFileSystemInfoContract());
        }
示例#17
0
        public async Task <FileSystemInfoContract> CopyItemAsync(RootName root, FileSystemId source, string copyName, DirectoryId destination, bool recurse)
        {
            var context = await RequireContextAsync(root);

            var itemReference            = ODConnection.ItemReferenceForItemId(source.Value, context.Drive.Id);
            var destinationPathReference = ODConnection.ItemReferenceForItemId(destination.Value, context.Drive.Id);
            var task = await retryPolicy.ExecuteAsync(() => context.Connection.CopyItemAsync(itemReference, destinationPathReference, copyName));

            while (task.Status.Status != AsyncJobStatus.Completed)
            {
                await Task.Delay(20);

                await task.Refresh(context.Connection);
            }

            var destinationPathItems = await retryPolicy.ExecuteAsync(() => context.Connection.GetChildrenOfItemAsync(destinationPathReference, ChildrenRetrievalOptions.Default));

            return(destinationPathItems.Collection.Single(item => item.Name == copyName).ToFileSystemInfoContract());
        }
示例#18
0
        public async Task <FileInfoContract> NewFileItemAsync(RootName root, DirectoryId parent, string name, Stream content, IProgress <ProgressValue> progress)
        {
            if (content.Length == 0)
            {
                return(new ProxyFileInfoContract(name));
            }

            var context = await RequireContextAsync(root);

            var itemReference = ODConnection.ItemReferenceForItemId(parent.Value, context.Drive.Id);
            var uploadOptions = progress != null ? new ItemUploadOptions()
            {
                ProgressReporter = (complete, transfered, total) => progress.Report(new ProgressValue(complete, (int)transfered, (int)total))
            } : ItemUploadOptions.Default;
            var retryPolicyWithAction = Policy.Handle <ODException>().WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
                                                                                        (ex, ts) => content.Seek(0, SeekOrigin.Begin));
            var item = await retryPolicyWithAction.ExecuteAsync(() => context.Connection.PutNewFileToParentItemAsync(itemReference, name, content, uploadOptions));

            return(new FileInfoContract(item.Id, item.Name, item.CreatedDateTime, item.LastModifiedDateTime, (FileSize)item.Size, item.File.Hashes.Sha1.ToLowerInvariant()));
        }