Exemplo n.º 1
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 AsyncFunc.RetryAsync <GoogleFile, GoogleApiException>(async() => await context.Service.Files.Copy(copy, source.Value).ExecuteAsync(), RETRIES);

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

            if (source is DirectoryId)
            {
                var request = new BoxFolderRequest()
                {
                    Id = source.Value, Name = copyName, Parent = new BoxRequestEntity()
                    {
                        Id = destination.Value
                    }
                };
                var item = await AsyncFunc.RetryAsync <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.RetryAsync <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.º 3
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 item           = default(Item);
            var requestBuilder = context.Client.Drive.Items[parent.Value].ItemWithPath(name);

            if (content.Length <= LARGE_FILE_THRESHOLD)
            {
                var stream = progress != null ? new ProgressStream(content, progress) : content;
                item = await AsyncFunc.RetryAsync <Item, ServiceException>(async() => await requestBuilder.Content.Request().PutAsync <Item>(stream), RETRIES);
            }
            else
            {
                var session = await requestBuilder.CreateSession().Request().PostAsync();

                var provider = new ChunkedUploadProvider(session, context.Client, content);

                item = await ChunkedUploadAsync(provider, progress, RETRIES);
            }

            return(new FileInfoContract(item.Id, item.Name, item.CreatedDateTime ?? DateTimeOffset.FromFileTime(0), item.LastModifiedDateTime ?? DateTimeOffset.FromFileTime(0), item.Size ?? -1, item.File.Hashes.Sha1Hash.ToLowerInvariant()));
        }
Exemplo n.º 4
0
        public async Task <FileSystemInfoContract> MoveItemAsync(RootName root, FileSystemId source, string moveName, DirectoryId destination, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(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.RetryAsync <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.RetryAsync <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.º 5
0
        public async Task <FileSystemInfoContract> RenameItemAsync(RootName root, FileSystemId target, string newName, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            if (target is DirectoryId)
            {
                var request = new BoxFolderRequest()
                {
                    Id = target.Value, Name = newName
                };
                var item = await AsyncFunc.RetryAsync <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.RetryAsync <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 <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 objectId = parent.GetObjectId(name);
            var length   = content.Length;

            var item = default(SwiftResponse);

            if (length <= LARGE_FILE_THRESHOLD)
            {
                var stream = progress != null ? new ProgressStream(content, progress) : content;
                item = await AsyncFunc.RetryAsync <SwiftResponse, Exception>(async() => await context.Client.PutObject(context.Container, objectId, stream), RETRIES);

                if (!item.IsSuccess)
                {
                    throw new ApplicationException(item.Reason);
                }
            }
            else
            {
                item = await AsyncFunc.RetryAsync <SwiftResponse, Exception>(async() => await ChunkedUpload(context, objectId, content, progress), RETRIES);
            }

            var creationTime = DateTime.Parse(item.Headers["Date"]);

            return(new FileInfoContract(objectId, name, creationTime, creationTime, length, item.Headers["ETag"]));
        }
Exemplo n.º 7
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 file = new GoogleFile()
            {
                Name = name, MimeType = MIME_TYPE_FILE, Parents = new[] { parent.Value }
            };
            var insert = context.Service.Files.Create(file, content, MIME_TYPE_FILE).AsFile();

            if (progress != null)
            {
                insert.ProgressChanged += p => progress.Report(new ProgressValue((int)p.BytesSent, (int)content.Length));
            }
            var upload = await AsyncFunc.RetryAsync <IUploadProgress, GoogleApiException>(async() => await insert.UploadAsync(), RETRIES);

            var item = insert.ResponseBody;

            return(new FileInfoContract(item.Id, item.Name, new DateTimeOffset(item.CreatedTime.Value), new DateTimeOffset(item.ModifiedTime.Value), item.Size.Value, item.Md5Checksum));
        }
Exemplo n.º 8
0
        public async Task <IEnumerable <FileSystemInfoContract> > GetChildItemAsync(RootName root, DirectoryId parent)
        {
            var context = await RequireContextAsync(root);

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

            return(items.Entries.Select(i => i.ToFileSystemInfoContract()));
        }
Exemplo n.º 9
0
        public async Task <RootDirectoryInfoContract> GetRootAsync(RootName root, string apiKey, IDictionary <string, string> parameters)
        {
            var context = await RequireContextAsync(root, apiKey);

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

            return(new RootDirectoryInfoContract(item.Id, DateTimeOffset.FromFileTime(0), DateTimeOffset.FromFileTime(0)));
        }
Exemplo n.º 10
0
        public async Task <DriveInfoContract> GetDriveAsync(RootName root, string apiKey, IDictionary <string, string> parameters)
        {
            var context = await RequireContextAsync(root, apiKey);

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

            return(new DriveInfoContract(item.Id, item.SpaceAmount.Value - item.SpaceUsed.Value, item.SpaceUsed.Value));
        }
Exemplo n.º 11
0
        public async Task <RootDirectoryInfoContract> GetRootAsync(RootName root, string apiKey, IDictionary <string, string> parameters)
        {
            var context = await RequireContextAsync(root, apiKey);

            var item = await AsyncFunc.RetryAsync <Item, ServiceException>(async() => await context.Client.Drive.Root.Request().GetAsync(), RETRIES);

            return(new RootDirectoryInfoContract(item.Id, item.CreatedDateTime ?? DateTimeOffset.FromFileTime(0), item.LastModifiedDateTime ?? DateTimeOffset.FromFileTime(0)));
        }
Exemplo n.º 12
0
        public async Task <DirectoryInfoContract> NewDirectoryItemAsync(RootName root, DirectoryId parent, string name)
        {
            var context = await RequireContextAsync(root);

            var item = await AsyncFunc.RetryAsync <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)));
        }
Exemplo n.º 13
0
        public async Task <DirectoryInfoContract> NewDirectoryItemAsync(RootName root, DirectoryId parent, string name)
        {
            var context = await RequireContextAsync(root);

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

            return(new DirectoryInfoContract(item.Id, item.Name, item.Created, item.Modified));
        }
Exemplo n.º 14
0
        public async Task <Stream> GetContentAsync(RootName root, FileId source)
        {
            var context = await RequireContextAsync(root);

            var stream = await AsyncFunc.RetryAsync <Stream, ServiceException>(async() => await context.Client.Drive.Items[source.Value].Content.Request().GetAsync(), RETRIES);

            return(stream);
        }
Exemplo n.º 15
0
        public async Task <Stream> GetContentAsync(RootName root, FileId source)
        {
            var context = await RequireContextAsync(root);

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

            return(stream);
        }
Exemplo n.º 16
0
        public async Task <RootDirectoryInfoContract> GetRootAsync(RootName root, string apiKey, IDictionary <string, string> parameters)
        {
            var context = await RequireContextAsync(root, apiKey);

            var item = await AsyncFunc.RetryAsync <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)));
        }
Exemplo n.º 17
0
        public async Task <RootDirectoryInfoContract> GetRootAsync(RootName root, string apiKey, IDictionary <string, string> parameters)
        {
            var context = await RequireContextAsync(root, apiKey);

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

            return(new RootDirectoryInfoContract(item.Id, item.CreatedDateTime, item.LastModifiedDateTime));
        }
Exemplo n.º 18
0
        public async Task <DriveInfoContract> GetDriveAsync(RootName root, string apiKey, IDictionary <string, string> parameters)
        {
            var context = await RequireContextAsync(root, apiKey);

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

            return(new DriveInfoContract(item.Id, item.Quota.Remaining, item.Quota.Used));
        }
Exemplo n.º 19
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.º 20
0
        public async Task <DriveInfoContract> GetDriveAsync(RootName root, string apiKey, IDictionary <string, string> parameters)
        {
            var context = await RequireContextAsync(root, apiKey);

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

            return(new DriveInfoContract(item.UserId, item.Quota - item.UsedQuota, item.UsedQuota));
        }
Exemplo n.º 21
0
        public async Task <bool> ClearContentAsync(RootName root, FileId target, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            var item = await AsyncFunc.RetryAsync <Item, ServiceException>(async() => await context.Client.Drive.Items[target.Value].Content.Request().PutAsync <Item>(Stream.Null), RETRIES);

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

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

            return(true);
        }
Exemplo n.º 23
0
        public async Task <DriveInfoContract> GetDriveAsync(RootName root, string apiKey, IDictionary <string, string> parameters)
        {
            var context = await RequireContextAsync(root, apiKey);

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

            return(new DriveInfoContract(item.Id, item.Storage.Quota - item.Storage.Used, item.Storage.Used));
        }
Exemplo n.º 24
0
        public async Task <RootDirectoryInfoContract> GetRootAsync(RootName root, string apiKey, IDictionary <string, string> parameters)
        {
            var context = await RequireContextAsync(root, apiKey);

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

            return(new RootDirectoryInfoContract(item.Id, item.Created, item.Modified));
        }
Exemplo n.º 25
0
        public async Task <IEnumerable <FileSystemInfoContract> > GetChildItemAsync(RootName root, DirectoryId parent)
        {
            var context = await RequireContextAsync(root);

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

            return(items.Children.Select(i => i.ToFileSystemInfoContract()));
        }
Exemplo n.º 26
0
        public async Task <bool> ClearContentAsync(RootName root, FileId target, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            await AsyncFunc.RetryAsync <IUploadProgress, GoogleApiException>(async() => await context.Service.Files.Update(null, target.Value, Stream.Null, MIME_TYPE_FILE).UploadAsync(), RETRIES);

            return(true);
        }
Exemplo n.º 27
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.º 28
0
        public async Task <bool> SetContentAsync(RootName root, FileId target, Stream content, IProgress <ProgressValue> progress, Func <FileSystemInfoLocator> locatorResolver)
        {
            var context = await RequireContextAsync(root);

            var item = await AsyncFunc.RetryAsync <Item, OneDriveException>(async() => await context.Client.Drive.Items[target.Value].Content.Request().PutAsync <Item>(content), RETRIES);

            return(true);
        }
Exemplo n.º 29
0
        public async Task <DriveInfoContract> GetDriveAsync(RootName root, string apiKey, IDictionary <string, string> parameters)
        {
            var context = await RequireContextAsync(root, apiKey);

            var item = await AsyncFunc.RetryAsync <MediaFireGetUserInfoResponse, MediaFireApiException>(async()
                                                                                                        => await context.Agent.GetAsync <MediaFireGetUserInfoResponse>(MediaFireApiUserMethods.GetInfo), RETRIES);

            return(new DriveInfoContract(item.UserDetails.Email, item.UserDetails.StorageLimit - item.UserDetails.UsedStorageSize, item.UserDetails.UsedStorageSize));
        }
Exemplo n.º 30
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 AsyncFunc.RetryAsync <bool, ODException>(async() => await context.Connection.DeleteItemAsync(itemReference, ItemDeleteOptions.Default), RETRIES);

            return(success);
        }