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); }
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); }
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())); }
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); }
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)); }
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); }
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); }
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())); }
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)); }
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()); }
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()); }
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()); }
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())); }
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); }
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); }
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()); }
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()); }
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())); }