public FileSystemInfoContract RenameItem(RootName root, FileSystemId target, string newName)
        {
            var contract = _localState.RenameItem(root, target, newName);

            TryReplace(target, contract.Id);
            return(contract);
        }
Exemplo n.º 2
0
        public async Task <FileSystemInfoContract> MoveItemAsync(RootName root, FileSystemId source, string moveName, DirectoryId destination, Func <FileSystemInfoLocator> locatorResolver)
        {
            // Emulate MoveItem through CopyItem + RemoveItem

            var context = await RequireContextAsync(root);

            var sourceObjectId      = new StorageObjectId(source.Value);
            var destinationObjectId = new StorageObjectId(destination.Value);
            var directorySource     = source as DirectoryId;

            if (directorySource != null)
            {
                moveName += Path.AltDirectorySeparatorChar;
            }

            var item = await retryPolicy.ExecuteAsync(() => context.Client.CopyObjectAsync(sourceObjectId.Bucket, sourceObjectId.Path, destinationObjectId.Bucket, $"{destinationObjectId.Path}{moveName}"));

            if (directorySource != null)
            {
                var subDestination = new DirectoryId(item.Id);
                foreach (var subItem in await GetChildItemAsync(root, directorySource))
                {
                    await retryPolicy.ExecuteAsync(() => MoveItemAsync(root, subItem.Id, subItem.Name, subDestination, locatorResolver));
                }
            }

            await retryPolicy.ExecuteAsync(() => context.Client.DeleteObjectAsync(sourceObjectId.Bucket, sourceObjectId.Path));

            return(item.ToFileSystemInfoContract());
        }
        public FileSystemInfoContract MoveItem(RootName root, FileSystemId source, string moveName, DirectoryId destination)
        {
            var contract = _localState.MoveItem(root, source, moveName, destination);

            TryReplace(source, contract.Id);
            return(contract);
        }
Exemplo n.º 4
0
        public async Task <FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func <FileSystemInfoLocator> locatorResolver)
        {
            if (string.IsNullOrEmpty(newName))
            {
                throw new ArgumentNullException(nameof(newName));
            }

            var context = await RequireContextAsync(root);

            var lastSlashIndex = target.Value.TrimEnd('/').LastIndexOf('/');

            newName = target.Value.Substring(0, lastSlashIndex + 1) + newName + (target.Value.EndsWith("/") ? "/" : string.Empty);

            var moveResponse = await context.Client.Move(target.Value, newName);

            CheckSuccess(moveResponse, nameof(WebDavClient.Move), target.Value, newName);

            var propfindResponse = await context.Client.Propfind(newName);

            CheckSuccess(propfindResponse, nameof(WebDavClient.Propfind), newName);

            var item = propfindResponse.Resources.Single(r => r.Uri == newName);

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

            if (target is DirectoryId)
            {
                var request = new BoxFolderRequest()
                {
                    Id = target.Value, Name = newName
                };
                var item = await AsyncFunc.Retry <BoxFolder, BoxException>(async() => await context.Client.FoldersManager.UpdateInformationAsync(request, fields: boxFolderFields), RETRIES);

                return(new DirectoryInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value));
            }
            else
            {
                var request = new BoxFileRequest()
                {
                    Id = target.Value, Name = newName
                };
                var item = await AsyncFunc.Retry <BoxFile, BoxException>(async() => await context.Client.FilesManager.UpdateInformationAsync(request, fields: boxFileFields), RETRIES);

                return(new FileInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value, item.Size.Value, item.Sha1.ToLowerInvariant()));
            }
        }
Exemplo n.º 6
0
        public async Task <FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func <FileSystemInfoLocator> locatorResolver)
        {
            if (locatorResolver == null)
            {
                throw new ArgumentNullException(nameof(locatorResolver));
            }

            var context = await RequireContextAsync(root);

            var directoryTarget = target as DirectoryId;

            if (directoryTarget != null)
            {
                var locator = locatorResolver();
                var item    = await retryPolicy.ExecuteAsync(() => context.Client.RenameFolderAsync(ToId(directoryTarget), ToId(locator.ParentId), newName));

                return(new DirectoryInfoContract(item.Id, item.Name, item.Created, item.Modified));
            }

            var fileTarget = target as FileId;

            if (fileTarget != null)
            {
                var locator = locatorResolver();
                var item    = await retryPolicy.ExecuteAsync(() => context.Client.RenameFileAsync(ToId(fileTarget), ToId(locator.ParentId), newName));

                return(new FileInfoContract(item.Id, item.Name, item.Created, item.Modified, (FileSize)item.Size, null));
            }

            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.ItemTypeNotSupported, target.GetType().Name));
        }
Exemplo n.º 7
0
        public void RemoveItem(RootName root, FileSystemId target, bool recurse)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            var effectivePath = GetFullPath(root, target.Value);

            var directory = new DirectoryInfo(effectivePath);

            if (directory.Exists)
            {
                directory.Delete(recurse);
                return;
            }

            var file = new FileInfo(effectivePath);

            if (file.Exists)
            {
                file.Delete();
                return;
            }

            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resource.PathNotFound, target.Value));
        }
Exemplo n.º 8
0
        public async Task <FileSystemInfoContract> CopyItemAsync(RootName root, FileSystemId source, string copyName, DirectoryId destination, bool recurse)
        {
            var context = await RequireContextAsync(root);

            if (string.IsNullOrEmpty(copyName))
            {
                var lastSlashIndex = source.Value.TrimEnd('/').LastIndexOf('/');
                copyName = source.Value.Substring(lastSlashIndex + 1);
            }
            else if (source.Value.EndsWith("/", StringComparison.Ordinal) && !copyName.EndsWith("/", StringComparison.Ordinal))
            {
                copyName += "/";
            }

            var targetName = destination.Value + copyName;

            var copyResponse = await retryPolicy.ExecuteAsync(() => context.Client.Copy(source.Value, targetName));

            CheckSuccess(copyResponse, nameof(WebDavClient.Copy), source.Value, targetName);

            var propfindResponse = await retryPolicy.ExecuteAsync(() => context.Client.Propfind(targetName));

            CheckSuccess(propfindResponse, nameof(WebDavClient.Propfind), targetName);

            var item = propfindResponse.Resources.Single(r => WebUtility.UrlDecode(r.Uri) == targetName);

            return(item.ToFileSystemInfoContract());
        }
Exemplo n.º 9
0
        public async Task <FileSystemInfoContract> CopyItemAsync(RootName root, FileSystemId source, string copyName, DirectoryId destination, bool recurse)
        {
            var context = await RequireContext(root);

            if (source is DirectoryId)
            {
                var request = new BoxFolderRequest()
                {
                    Id = source.Value, Name = copyName, Parent = new BoxRequestEntity()
                    {
                        Id = destination.Value
                    }
                };
                var item = await AsyncFunc.Retry <BoxFolder, BoxException>(async() => await context.Client.FoldersManager.CopyAsync(request, boxFolderFields), RETRIES);

                return(new DirectoryInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value));
            }
            else
            {
                var request = new BoxFileRequest()
                {
                    Id = source.Value, Name = copyName, Parent = new BoxRequestEntity()
                    {
                        Id = destination.Value
                    }
                };
                var item = await AsyncFunc.Retry <BoxFile, BoxException>(async() => await context.Client.FilesManager.CopyAsync(request, boxFileFields), RETRIES);

                return(new FileInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value, item.Size.Value, item.Sha1.ToLowerInvariant()));
            }
        }
Exemplo n.º 10
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContextAsync(root);

            var response = default(SwiftResponse);

            if (target is DirectoryId && recurse)
            {
                var directoryId     = target.Value.TrimEnd('/');
                var queryParameters = new Dictionary <string, string>()
                {
                    ["marker"]     = directoryId,
                    ["end_marker"] = directoryId + '0'
                };

                var container = await context.Client.GetContainer(context.Container, queryParams : queryParameters);

                response = await context.Client.DeleteObjects(context.Container, container.Objects.Select(i => i.Object).Concat(new[] { directoryId }));
            }
            else
            {
                response = await context.Client.DeleteObject(context.Container, target.Value.TrimEnd('/'));
            }

            return(response.IsSuccess);
        }
Exemplo n.º 11
0
        public async Task <FileSystemInfoContract> MoveItemAsync(RootName root, FileSystemId source, string moveName, DirectoryId destination, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            if (string.IsNullOrEmpty(moveName))
            {
                var lastSlashIndex = source.Value.TrimEnd('/').LastIndexOf('/');
                moveName = source.Value.Substring(lastSlashIndex + 1);
            }
            else if (source.Value.EndsWith("/") && !moveName.EndsWith("/"))
            {
                moveName += "/";
            }

            var targetName = destination.Value + moveName;

            var moveResponse = await context.Client.Move(source.Value, targetName);

            CheckSuccess(moveResponse, nameof(WebDavClient.Move), source.Value, targetName);

            var propfindResponse = await context.Client.Propfind(targetName);

            CheckSuccess(propfindResponse, nameof(WebDavClient.Propfind), targetName);

            var item = propfindResponse.Resources.Single(r => WebUtility.UrlDecode(r.Uri) == targetName);

            return(item.ToFileSystemInfoContract());
        }
Exemplo n.º 12
0
        public void RemoveItem(RootName root, FileSystemId target, bool recurse)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (string.IsNullOrEmpty(rootPath))
            {
                throw new InvalidOperationException($"{nameof(rootPath)} not initialized".ToString(CultureInfo.CurrentCulture));
            }

            var effectivePath = GetFullPath(rootPath, target.Value);

            var directory = new DirectoryInfo(effectivePath);

            if (directory.Exists)
            {
                directory.Delete(recurse);
                return;
            }

            var file = new FileInfo(effectivePath);

            if (file.Exists)
            {
                file.Delete();
                return;
            }

            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.PathNotFound, target.Value));
        }
Exemplo n.º 13
0
        public async Task <FileSystemInfoContract> CopyItemAsync(RootName root, FileSystemId source, string copyName, DirectoryId destination, bool recurse)
        {
            if (source is DirectoryId)
            {
                throw new NotSupportedException(Properties.Resources.CopyingOfDirectoriesNotSupported);
            }

            var context = await RequireContextAsync(root);

            var copy = new GoogleFile()
            {
                Title = copyName
            };

            if (destination != null)
            {
                copy.Parents = new[] { new ParentReference()
                                       {
                                           Id = destination.Value
                                       } }
            }
            ;
            var item = await retryPolicy.ExecuteAsync(() => context.Service.Files.Copy(copy, source.Value).ExecuteAsync());

            return(item.ToFileSystemInfoContract());
        }
Exemplo n.º 14
0
        public async Task <FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            if (target is DirectoryId)
            {
                await context.Agent.GetAsync <MediaFireEmptyResponse>(MediaFireApiFolderMethods.Update, new Dictionary <string, object>() {
                    [MediaFireApiParameters.FolderKey]  = target.Value,
                    [MediaFireApiParameters.FolderName] = newName
                });

                var item = await context.Agent.GetAsync <MediaFireGetFolderInfoResponse>(MediaFireApiFolderMethods.GetInfo, new Dictionary <string, object>() {
                    [MediaFireApiParameters.FolderKey] = target.Value
                });

                return(new DirectoryInfoContract(item.FolderInfo.FolderKey, item.FolderInfo.Name, item.FolderInfo.Created, item.FolderInfo.Created));
            }
            else
            {
                await context.Agent.GetAsync <MediaFireEmptyResponse>(MediaFireApiFileMethods.Update, new Dictionary <string, object>() {
                    [MediaFireApiParameters.QuickKey] = target.Value,
                    [MediaFireApiParameters.FileName] = newName
                });

                var item = await context.Agent.GetAsync <MediaFireGetFileInfoResponse>(MediaFireApiFileMethods.GetInfo, new Dictionary <string, object>() {
                    [MediaFireApiParameters.QuickKey] = target.Value
                });

                return(new FileInfoContract(item.FileInfo.QuickKey, item.FileInfo.Name, item.FileInfo.Created, item.FileInfo.Created, item.FileInfo.Size, item.FileInfo.Hash));
            }
        }
Exemplo n.º 15
0
        public async Task <FileSystemInfoContract> MoveItemAsync(RootName root, FileSystemId source, string moveName, DirectoryId destination, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            if (source is DirectoryId)
            {
                var request = new BoxFolderRequest()
                {
                    Id = source.Value, Parent = new BoxRequestEntity()
                    {
                        Id = destination.Value, Type = BoxType.folder
                    }, Name = moveName
                };
                var item = await AsyncFunc.Retry <BoxFolder, BoxException>(async() => await context.Client.FoldersManager.UpdateInformationAsync(request, fields: boxFolderFields), RETRIES);

                return(new DirectoryInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value));
            }
            else
            {
                var request = new BoxFileRequest()
                {
                    Id = source.Value, Parent = new BoxRequestEntity()
                    {
                        Id = destination.Value, Type = BoxType.file
                    }, Name = moveName
                };
                var item = await AsyncFunc.Retry <BoxFile, BoxException>(async() => await context.Client.FilesManager.UpdateInformationAsync(request, fields: boxFileFields), RETRIES);

                return(new FileInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value, item.Size.Value, item.Sha1.ToLowerInvariant()));
            }
        }
Exemplo n.º 16
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContext(root);

            var item = await AsyncFunc.Retry <string, GoogleApiException>(async() => await context.Service.Files.Delete(target.Value).ExecuteAsync(), RETRIES);

            return(true);
        }
Exemplo n.º 17
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContextAsync(root);

            var success = await AsyncFunc.RetryAsync <bool, ServerException>(async() => await context.Client.FileSystemManager.DeleteAsync(target.Value), RETRIES);

            return(success);
        }
Exemplo n.º 18
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContextAsync(root);

            var success = await retryPolicy.ExecuteAsync(() => context.Client.FileSystemManager.DeleteAsync(target.Value));

            return(success);
        }
Exemplo n.º 19
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContextAsync(root);

            var item = await retryPolicy.ExecuteAsync(() => context.Service.Files.Delete(target.Value).ExecuteAsync());

            return(true);
        }
Exemplo n.º 20
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContextAsync(root);

            await AsyncFunc.RetryAsync <ServiceException>(async() => await context.Client.Drive.Items[target.Value].Request().DeleteAsync(), RETRIES);

            return(true);
        }
Exemplo n.º 21
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContextAsync(root);

            var deleteResponse = await context.Client.Delete(target.Value);

            return(deleteResponse.IsSuccessful);
        }
Exemplo n.º 22
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContextAsync(root);

            await retryPolicy.ExecuteAsync(() => context.Client.Drive.Items[target.Value].Request().DeleteAsync());

            return(true);
        }
Exemplo n.º 23
0
        public void RemoveItem(RootName root, FileSystemId target, bool recurse)
        {
            var context = RequireContext(root);

            var nodes = context.Client.GetNodes();
            var item  = nodes.Single(n => n.Id == target.Value);

            context.Client.Delete(item);
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
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);
        }
        public void RemoveItem(RootName root, FileSystemId target, bool recurse)
        {
            _localState.RemoveItem(root, target, recurse);
            var fileId = new FileId(target.Value);

            if (_contentCache.ContainsKey(fileId))
            {
                _contentCache.Remove(fileId, out _);
            }
        }
Exemplo n.º 27
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContext(root);

            var success = target is DirectoryId
                ? await AsyncFunc.Retry <bool, BoxException>(async() => await context.Client.FoldersManager.DeleteAsync(target.Value, recurse), RETRIES)
                : await AsyncFunc.Retry <bool, BoxException>(async() => await context.Client.FilesManager.DeleteAsync(target.Value), RETRIES);

            return(success);
        }
Exemplo n.º 28
0
        public async Task <FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            var nodes = await context.Client.GetNodesAsync();

            var targetItem = nodes.Single(n => n.Id == target.Value);
            var item       = await context.Client.RenameAsync(targetItem, newName);

            return(item.ToFileSystemInfoContract());
        }
Exemplo n.º 29
0
        public async Task <FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            var item = await retryPolicy.ExecuteAsync(() => context.Client.Drive.Items[target.Value].Request().UpdateAsync(new Item()
            {
                Name = newName
            }));

            return(item.ToFileSystemInfoContract());
        }
Exemplo n.º 30
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContextAsync(root);

            var nodes = await context.Client.GetNodesAsync();

            var item = nodes.Single(n => n.Id == target.Value);
            await context.Client.DeleteAsync(item);

            return(true);
        }
        protected FileSystemInfoContract(FileSystemId id, string name, DateTimeOffset created, DateTimeOffset updated)
        {
            if (id == null)
                throw new ArgumentNullException(nameof(id));
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException(nameof(name));

            Id = id;
            Name = name;
            Created = created;
            Updated = updated;
        }
        public async Task<FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func<FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            if (target is DirectoryId) {
                var request = new BoxFolderRequest() { Id = target.Value, Name = newName };
                var item = await AsyncFunc.Retry<BoxFolder, BoxException>(async () => await context.Client.FoldersManager.UpdateInformationAsync(request, fields: boxFolderFields), RETRIES);

                return new DirectoryInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value);
            }
            else {
                var request = new BoxFileRequest() { Id = target.Value, Name = newName };
                var item = await AsyncFunc.Retry<BoxFile, BoxException>(async () => await context.Client.FilesManager.UpdateInformationAsync(request, fields: boxFileFields), RETRIES);

                return new FileInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value, item.Size.Value, item.Sha1.ToLowerInvariant());
            }
        }
 public FileSystemInfoContract RenameItem(RootName root, FileSystemId target, string newName)
 {
     throw new NotSupportedException(Resources.RenamingOfFilesNotSupported);
 }
        public FileSystemInfoContract MoveItem(RootName root, FileSystemId source, string moveName, DirectoryId destination)
        {

            var context = RequireContext(root);

            var nodes = context.Client.GetNodes();
            var sourceItem = nodes.Single(n => n.Id == source.Value);
            if (!string.IsNullOrEmpty(moveName) && moveName != sourceItem.Name)
                throw new NotSupportedException(Resources.RenamingOfFilesNotSupported);
            var destinationParentItem = nodes.Single(n => n.Id == destination.Value);
            var item = context.Client.Move(sourceItem, destinationParentItem);

            return item.ToFileSystemInfoContract();
        }
        public async Task<FileSystemInfoContract> CopyItemAsync(RootName root, FileSystemId source, string copyName, DirectoryId destination, bool recurse)
        {
            var fileSource = source as FileId;
            if (fileSource == null)
                 throw new NotSupportedException(Resources.CopyingOfDirectoriesNotSupported);

            var context = await RequireContext(root);

            var item = await AsyncFunc.Retry<pCloudFile, pCloudException>(async () => await context.Client.CopyFileAsync(ToId(fileSource), ToId(destination), copyName), RETRIES);

            return new FileInfoContract(item.Id, item.Name, item.Created, item.Modified, item.Size, null);
        }
        public async Task<FileSystemInfoContract> MoveItemAsync(RootName root, FileSystemId source, string moveName, DirectoryId destination, Func<FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            var directorySource = source as DirectoryId;
            if (directorySource != null) {
                var item = await context.Client.RenameFolderAsync(ToId(directorySource), ToId(destination), moveName);

                return new DirectoryInfoContract(item.Id, item.Name, item.Created, item.Modified);
            }

            var fileSource = source as FileId;
            if (fileSource != null) {
                var item = await context.Client.RenameFileAsync(ToId(fileSource), ToId(destination), moveName);

                return new FileInfoContract(item.Id, item.Name, item.Created, item.Modified, item.Size, null);
            }

            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.ItemTypeNotSupported, source.GetType().Name));
        }
        public async Task<bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContext(root);

            var directoryTarget = target as DirectoryId;
            if (directoryTarget != null) {
                await context.Client.DeleteFolderAsync(ToId(directoryTarget), recurse);
                return true;
            }

            var fileTarget = target as FileId;
            if (fileTarget != null) {
                await context.Client.DeleteFileAsync(ToId(fileTarget));
                return true;
            }

            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.ItemTypeNotSupported, target.GetType().Name));
        }
        public async Task<FileSystemInfoContract> MoveItemAsync(RootName root, FileSystemId source, string moveName, DirectoryId destination, Func<FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            if (source is DirectoryId) {
                var request = new BoxFolderRequest() { Id = source.Value, Parent = new BoxRequestEntity() { Id = destination.Value, Type = BoxType.folder }, Name = moveName };
                var item = await AsyncFunc.Retry<BoxFolder, BoxException>(async () => await context.Client.FoldersManager.UpdateInformationAsync(request, fields: boxFolderFields), RETRIES);

                return new DirectoryInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value);
            }
            else {
                var request = new BoxFileRequest() { Id = source.Value, Parent = new BoxRequestEntity() { Id = destination.Value, Type = BoxType.file }, Name = moveName };
                var item = await AsyncFunc.Retry<BoxFile, BoxException>(async () => await context.Client.FilesManager.UpdateInformationAsync(request, fields: boxFileFields), RETRIES);

                return new FileInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value, item.Size.Value, item.Sha1.ToLowerInvariant());
            }
        }
        public async Task<FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func<FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            var success = await AsyncFunc.Retry<bool, ServerException>(async () => await context.Client.FileSystemManager.RenameFileAsync(target.Value, newName, false), RETRIES);
            if (!success)
                throw new ApplicationException(string.Format(CultureInfo.CurrentCulture, Resources.RenameFailed, target.Value, newName));

            var renamedItemPath = target.Value.Substring(0, target.Value.LastIndexOf('/')) + @"/" + newName;
            var item = await AsyncFunc.Retry<FileSystem, ServerException>(async () => await context.Client.FileSystemManager.GetFileSystemInformationAsync(renamedItemPath), RETRIES);

            return item.ToFileSystemInfoContract();
        }
        public async Task<bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContext(root);

            var success = await AsyncFunc.Retry<bool, ServerException>(async () => await context.Client.FileSystemManager.DeleteAsync(target.Value), RETRIES);

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

            var copy = new GoogleFile() { Title = copyName };
            if (destination != null)
                copy.Parents = new[] { new ParentReference() { Id = destination.Value } };
            var item = await AsyncFunc.Retry<GoogleFile, GoogleApiException>(async () => await context.Service.Files.Copy(copy, source.Value).ExecuteAsync(), RETRIES);

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

            if (string.IsNullOrEmpty(moveName))
                moveName = locatorResolver().Name;
            var success = await AsyncFunc.Retry<bool, ServerException>(async () => await context.Client.FileSystemManager.MoveFileAsync(source.Value, destination.Value, moveName, false), RETRIES);
            if (!success)
                throw new ApplicationException(string.Format(CultureInfo.CurrentCulture, Resources.MoveFailed, source.Value, destination.Value, moveName?.Insert(0, @"/") ?? string.Empty));

            var movedItemPath = destination.Value.Substring(0, destination.Value.LastIndexOf('/')) + @"/" + moveName;
            var item = await AsyncFunc.Retry<FileSystem, ServerException>(async () => await context.Client.FileSystemManager.GetFileSystemInformationAsync(movedItemPath), RETRIES);

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

            var move = new GoogleFile() { Parents = new[] { new ParentReference() { Id = destination.Value } }, Title = moveName };
            var patch = context.Service.Files.Patch(move, source.Value);
            var item = await AsyncFunc.Retry<GoogleFile, GoogleApiException>(async () => await patch.ExecuteAsync(), RETRIES);

            return item.ToFileSystemInfoContract();
        }
 public FileSystemInfoContract CopyItem(RootName root, FileSystemId source, string copyName, DirectoryId destination, bool recurse)
 {
     throw new NotSupportedException(Resources.CopyingOfFilesNotSupported);
 }
        public async Task<bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContext(root);

            var item = await AsyncFunc.Retry<string, GoogleApiException>(async () => await context.Service.Files.Delete(target.Value).ExecuteAsync(), RETRIES);

            return true;
        }
        public void RemoveItem(RootName root, FileSystemId target, bool recurse)
        {
            var context = RequireContext(root);

            var nodes = context.Client.GetNodes();
            var item = nodes.Single(n => n.Id == target.Value);
            context.Client.Delete(item);
        }
        public async Task<FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func<FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            var patch = context.Service.Files.Patch(new GoogleFile() { Title = newName }, target.Value);
            var item = await AsyncFunc.Retry<GoogleFile, GoogleApiException>(async () => await patch.ExecuteAsync(), RETRIES);

            return item.ToFileSystemInfoContract();
        }
        public FileSystemInfoContract RenameItem(RootName root, FileSystemId target, string newName)
        {
            if (root == null)
                throw new ArgumentNullException(nameof(root));
            if (target == null)
                throw new ArgumentNullException(nameof(target));
            if (string.IsNullOrEmpty(newName))
                throw new ArgumentNullException(nameof(newName));

            var effectivePath = GetFullPath(root, target.Value);
            var newPath = GetFullPath(root, Path.Combine(Path.GetDirectoryName(target.Value), newName));

            var directory = new DirectoryInfo(effectivePath);
            if (directory.Exists) {
                directory.MoveTo(newPath);
                return new DirectoryInfoContract(GetRelativePath(root, directory.FullName), directory.Name, directory.CreationTime, directory.LastWriteTime);
            }

            var file = new FileInfo(effectivePath);
            if (file.Exists) {
                file.MoveTo(newPath);
                return new FileInfoContract(GetRelativePath(root, file.FullName), file.Name, file.CreationTime, file.LastWriteTime, file.Length, null);
            }

            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resource.PathNotFound, target.Value));
        }
        public void RemoveItem(RootName root, FileSystemId target, bool recurse)
        {
            if (root == null)
                throw new ArgumentNullException(nameof(root));
            if (target == null)
                throw new ArgumentNullException(nameof(target));

            var effectivePath = GetFullPath(root, target.Value);

            var directory = new DirectoryInfo(effectivePath);
            if (directory.Exists) {
                directory.Delete(recurse);
                return;
            }

            var file = new FileInfo(effectivePath);
            if (file.Exists) {
                file.Delete();
                return;
            }

            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resource.PathNotFound, target.Value));
        }
 public Task<FileSystemInfoContract> CopyItemAsync(RootName root, FileSystemId source, string copyName, DirectoryId destination, bool recurse)
 {
     return Task.FromException<FileSystemInfoContract>(new NotSupportedException(Resources.CopyingOfFilesOrDirectoriesNotSupported));
 }
        public FileSystemInfoContract MoveItem(RootName root, FileSystemId source, string moveName, DirectoryId destination)
        {
            if (root == null)
                throw new ArgumentNullException(nameof(root));
            if (source == null)
                throw new ArgumentNullException(nameof(source));
            if (string.IsNullOrEmpty(moveName))
                throw new ArgumentNullException(nameof(moveName));
            if (destination == null)
                throw new ArgumentNullException(nameof(destination));

            var effectivePath = GetFullPath(root, source.Value);
            var destinationPath = destination.Value;
            if (Path.IsPathRooted(destinationPath))
                destinationPath = destinationPath.Remove(0, Path.GetPathRoot(destinationPath).Length);
            var effectiveMovePath = GetFullPath(root, Path.Combine(destinationPath, moveName));

            var directory = new DirectoryInfo(effectivePath);
            if (directory.Exists) {
                directory.MoveTo(effectiveMovePath);
                return new DirectoryInfoContract(GetRelativePath(root, directory.FullName), directory.Name, directory.CreationTime, directory.LastWriteTime);
            }

            var file = new FileInfo(effectivePath);
            if (file.Exists) {
                file.MoveTo(effectiveMovePath);
                return new FileInfoContract(GetRelativePath(root, file.FullName), file.Name, file.CreationTime, file.LastWriteTime, file.Length, null);
            }

            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resource.PathNotFound, source.Value));
        }
        public async Task<FileSystemInfoContract> CopyItemAsync(RootName root, FileSystemId source, string copyName, DirectoryId destination, bool recurse)
        {
            var context = await RequireContext(root);

            if (source is DirectoryId) {
                var request = new BoxFolderRequest() { Id = source.Value, Name = copyName, Parent = new BoxRequestEntity() { Id = destination.Value } };
                var item = await AsyncFunc.Retry<BoxFolder, BoxException>(async () => await context.Client.FoldersManager.CopyAsync(request, boxFolderFields), RETRIES);

                return new DirectoryInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value);
            }
            else {
                var request = new BoxFileRequest() { Id = source.Value, Name = copyName, Parent = new BoxRequestEntity() { Id = destination.Value } };
                var item = await AsyncFunc.Retry<BoxFile, BoxException>(async () => await context.Client.FilesManager.CopyAsync(request, boxFileFields), RETRIES);

                return new FileInfoContract(item.Id, item.Name, item.CreatedAt.Value, item.ModifiedAt.Value, item.Size.Value, item.Sha1.ToLowerInvariant());
            }
        }
        public async Task<FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func<FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            var directoryTarget = target as DirectoryId;
            if (directoryTarget != null) {
                var locator = locatorResolver();
                var item = await context.Client.RenameFolderAsync(ToId(directoryTarget), ToId(locator.ParentId), newName);

                return new DirectoryInfoContract(item.Id, item.Name, item.Created, item.Modified);
            }

            var fileTarget = target as FileId;
            if (fileTarget != null) {
                var locator = locatorResolver();
                var item = await context.Client.RenameFileAsync(ToId(fileTarget), ToId(locator.ParentId), newName);

                return new FileInfoContract(item.Id, item.Name, item.Created, item.Modified, item.Size, null);
            }

            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.ItemTypeNotSupported, target.GetType().Name));
        }