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

            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 async Task <RootDirectoryInfoContract> GetRootAsync(RootName root, string apiKey)
        {
            var context = await RequireContext(root, apiKey);

            var item = await AsyncFunc.Retry <ListedFolder, pCloudException>(async() => await context.Client.ListFolderAsync(0), RETRIES);

            return(new RootDirectoryInfoContract(item.Id, item.Created, item.Modified));
        }
        public async Task <DriveInfoContract> GetDriveAsync(RootName root, string apiKey)
        {
            var context = await RequireContext(root, apiKey);

            var item = await AsyncFunc.Retry <UserInfo, pCloudException>(async() => await context.Client.GetUserInfoAsync(), RETRIES);

            return(new DriveInfoContract(item.UserId, item.Quota - item.UsedQuota, item.UsedQuota));
        }
        public async Task <DriveInfoContract> GetDriveAsync(RootName root, string apiKey)
        {
            var context = await RequireContext(root, apiKey);

            var item = await AsyncFunc.Retry <User, ServerException>(async() => await context.Client.UserManager.GetUserAsync(), RETRIES);

            return(new DriveInfoContract(item.Id, item.Storage.Quota - item.Storage.Used, item.Storage.Used));
        }
        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 <FileInfoContract> NewFileItemAsync(RootName root, DirectoryId parent, string name, Stream content, IProgress <ProgressValue> progress)
        {
            var context = await RequireContext(root);

            var item = await AsyncFunc.Retry <FileSystem, ServerException>(async() => await context.Client.FileSystemManager.UploadNewFileStreamAsync(parent.Value, name, new ProgressStream(content, progress), true), RETRIES);

            return(new FileInfoContract(item.Id, item.Name, item.DateLastSynced, FileSystemExtensions.Later(item.DateLastSynced, item.ModifiedTime), item.Size, null));
        }
        public async Task <DirectoryInfoContract> NewDirectoryItemAsync(RootName root, DirectoryId parent, string name)
        {
            var context = await RequireContext(root);

            var item = await AsyncFunc.Retry <FileSystem, ServerException>(async() => await context.Client.FileSystemManager.CreateNewFolderAsync(parent.Value, name, false), RETRIES);

            return(new DirectoryInfoContract(item.Id, item.Name, item.DateLastSynced, FileSystemExtensions.Later(item.DateLastSynced, item.ModifiedTime)));
        }
        public async Task <DirectoryInfoContract> NewDirectoryItemAsync(RootName root, DirectoryId parent, string name)
        {
            var context = await RequireContext(root);

            var item = await AsyncFunc.Retry <Folder, pCloudException>(async() => await context.Client.CreateFolderAsync(ToId(parent), name), RETRIES);

            return(new DirectoryInfoContract(item.Id, item.Name, item.Created, item.Modified));
        }
Exemple #11
0
        public async Task <DriveInfoContract> GetDriveAsync(RootName root, string apiKey)
        {
            var context = await RequireContext(root, apiKey);

            var item = await AsyncFunc.Retry <ODDrive, ODException>(async() => await context.Connection.GetDrive(), RETRIES);

            return(new DriveInfoContract(item.Id, item.Quota.Remaining, item.Quota.Used));
        }
        public async Task <RootDirectoryInfoContract> GetRootAsync(RootName root, string apiKey)
        {
            var context = await RequireContext(root, apiKey);

            var item = await AsyncFunc.Retry <BoxFolder, BoxException>(async() => await context.Client.FoldersManager.GetInformationAsync("0", boxFolderFields), RETRIES);

            return(new RootDirectoryInfoContract(item.Id, DateTimeOffset.MinValue, DateTimeOffset.MinValue));
        }
        public async Task <Stream> GetContentAsync(RootName root, FileId source)
        {
            var context = await RequireContext(root);

            var stream = await AsyncFunc.Retry <Stream, BoxException>(async() => await context.Client.FilesManager.DownloadStreamAsync(source.Value), RETRIES);

            return(stream);
        }
        public async Task <IEnumerable <FileSystemInfoContract> > GetChildItemAsync(RootName root, DirectoryId parent)
        {
            var context = await RequireContext(root);

            var items = await AsyncFunc.Retry <BoxCollection <BoxItem>, BoxException>(async() => await context.Client.FoldersManager.GetFolderItemsAsync(parent.Value, 1000, fields: boxFileFields), RETRIES);

            return(items.Entries.Select(i => i.ToFileSystemInfoContract()));
        }
Exemple #15
0
        public async Task <RootDirectoryInfoContract> GetRootAsync(RootName root, string apiKey)
        {
            var context = await RequireContext(root, apiKey);

            var item = await AsyncFunc.Retry <GoogleFile, GoogleApiException>(async() => await context.Service.Files.Get("root").ExecuteAsync(), RETRIES);

            return(new RootDirectoryInfoContract(item.Id, new DateTimeOffset(item.CreatedDate.Value), new DateTimeOffset(item.ModifiedDate.Value)));
        }
        public async Task <DriveInfoContract> GetDriveAsync(RootName root, string apiKey)
        {
            var context = await RequireContext(root, apiKey);

            var item = await AsyncFunc.Retry <BoxUser, BoxException>(async() => await context.Client.UsersManager.GetCurrentUserInformationAsync(), RETRIES);

            return(new DriveInfoContract(item.Id, item.SpaceAmount.Value - item.SpaceUsed.Value, item.SpaceUsed.Value));
        }
Exemple #17
0
        public async Task <RootDirectoryInfoContract> GetRootAsync(RootName root, string apiKey)
        {
            var context = await RequireContext(root, apiKey);

            var item = await AsyncFunc.Retry <ODItem, ODException>(async() => await context.Connection.GetRootItemAsync(ItemRetrievalOptions.Default), RETRIES);

            return(new RootDirectoryInfoContract(item.Id, item.CreatedDateTime, item.LastModifiedDateTime));
        }
        public async Task <IEnumerable <FileSystemInfoContract> > GetChildItemAsync(RootName root, DirectoryId parent)
        {
            var context = await RequireContext(root);

            var items = await AsyncFunc.Retry <FileSystem, ServerException>(async() => await context.Client.FileSystemManager.GetFileSystemInformationAsync(parent.Value), RETRIES);

            return(items.Children.Select(i => i.ToFileSystemInfoContract()));
        }
Exemple #19
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);
        }
Exemple #20
0
        public async Task <bool> ClearContentAsync(RootName root, FileId target, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            await AsyncFunc.Retry <IUploadProgress, GoogleApiException>(async() => await context.Service.Files.Update(null, target.Value, new MemoryStream(), MIME_TYPE_FILE).UploadAsync(), RETRIES);

            return(true);
        }
        public async Task <bool> ClearContentAsync(RootName root, FileId target, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            var locator = locatorResolver();
            await AsyncFunc.Retry <BoxFile, BoxException>(async() => await context.Client.FilesManager.UploadNewVersionAsync(locator.Name, target.Value, new MemoryStream()), RETRIES);

            return(true);
        }
Exemple #22
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));
        }
Exemple #23
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);
        }
Exemple #24
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()));
        }
        public async Task <bool> SetContentAsync(RootName root, FileId target, Stream content, IProgress <ProgressValue> progress, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            var locator = locatorResolver();
            var item    = await AsyncFunc.Retry <BoxFile, BoxException>(async() => await context.Client.FilesManager.UploadNewVersionAsync(locator.Name, target.Value, new ProgressStream(content, progress)), RETRIES);

            return(true);
        }
Exemple #26
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 async Task <FileInfoContract> NewFileItemAsync(RootName root, DirectoryId parent, string name, Stream content, IProgress <ProgressValue> progress)
        {
            var context = await RequireContext(root);

            var tokenSource = new CancellationTokenSource();
            var item        = await AsyncFunc.Retry <pCloudFile, pCloudException>(async() => await context.Client.UploadFileAsync(new ProgressStream(content, progress), ToId(parent), name, tokenSource.Token), RETRIES);

            return(new FileInfoContract(item.Id, item.Name, item.Created, item.Modified, item.Size, null));
        }
        public async Task <bool> ClearContentAsync(RootName root, FileId target, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContext(root);

            var locator = locatorResolver();
            var item    = await AsyncFunc.Retry <FileSystem, ServerException>(async() => await context.Client.FileSystemManager.UploadNewFileStreamAsync(locator.ParentId.Value, locator.Name, new MemoryStream(), true), RETRIES);

            return(true);
        }
        public async Task <RootDirectoryInfoContract> GetRootAsync(RootName root, string apiKey)
        {
            var context = await RequireContext(root, apiKey);

            var item = await AsyncFunc.Retry <FileSystem, ServerException>(async() => await context.Client.GetRootFolder(), RETRIES);

            var user = await AsyncFunc.Retry <User, ServerException>(async() => await context.Client.UserManager.GetUserAsync(), RETRIES);

            return(new RootDirectoryInfoContract(item.Id, new DateTimeOffset(user.CreatedTime, TimeSpan.Zero), new DateTimeOffset(item.ModifiedTime, TimeSpan.Zero)));
        }
        public async Task <IEnumerable <FileSystemInfoContract> > GetChildItemAsync(RootName root, DirectoryId parent)
        {
            var context = await RequireContext(root);

            var item = await AsyncFunc.Retry <ListedFolder, pCloudException>(async() => await context.Client.ListFolderAsync(ToId(parent)), RETRIES);

            var items = item.Contents;

            return(items.Select(i => i.ToFileSystemInfoContract()));
        }