Exemple #1
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));
        }
Exemple #2
0
        public async Task <bool> RemoveItemAsync(RootName root, FileSystemId target, bool recurse)
        {
            var context = await RequireContextAsync(root);

            var directoryTarget = target as DirectoryId;

            if (directoryTarget != null)
            {
                await retryPolicy.ExecuteAsync(() => context.Client.DeleteFolderAsync(ToId(directoryTarget), recurse));

                return(true);
            }

            var fileTarget = target as FileId;

            if (fileTarget != null)
            {
                await retryPolicy.ExecuteAsync(() => context.Client.DeleteFileAsync(ToId(fileTarget)));

                return(true);
            }

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

            var directorySource = source as DirectoryId;

            if (directorySource != null)
            {
                var item = await retryPolicy.ExecuteAsync(() => context.Client.RenameFolderAsync(ToId(directorySource), ToId(destination), WebUtility.UrlEncode(moveName)));

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

            var fileSource = source as FileId;

            if (fileSource != null)
            {
                var item = await retryPolicy.ExecuteAsync(() => context.Client.RenameFileAsync(ToId(fileSource), ToId(destination), WebUtility.UrlEncode(moveName)));

                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, source.GetType().Name));
        }
        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));
        }
        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);

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