예제 #1
0
        public async Task <JsonResult> PasteAsync(FullPath dest, IEnumerable <FullPath> paths, bool isCut, IEnumerable <string> renames, string suffix)
        {
            var response = new ReplaceResponseModel();

            var pathList = paths.ToList();

            foreach (var src in pathList)
            {
                if (src.IsDirectory)
                {
                    var newDir = new AzureBlobDirectory(AzureBlobStorageApi.PathCombine(dest.Directory.FullName, src.Directory.Name));

                    // Check if it already exists
                    if (await newDir.ExistsAsync)
                    {
                        await newDir.DeleteAsync();
                    }

                    if (isCut)
                    {
                        await RemoveThumbsAsync(src);

                        await AzureBlobStorageApi.MoveDirectoryAsync(src.Directory.FullName, newDir.FullName);

                        response.Removed.Add(src.HashedTarget);
                    }
                    else
                    {
                        // Copy directory
                        await AzureBlobStorageApi.CopyDirectoryAsync(src.Directory.FullName, newDir.FullName);
                    }

                    response.Added.Add(await BaseModel.CreateAsync(newDir, dest.RootVolume));
                }
                else
                {
                    var newFilePath = AzureBlobStorageApi.PathCombine(dest.Directory.FullName, src.File.Name);
                    await AzureBlobStorageApi.DeleteFileIfExistsAsync(newFilePath);

                    if (isCut)
                    {
                        await RemoveThumbsAsync(src);

                        // Move file
                        await AzureBlobStorageApi.MoveFileAsync(src.File.FullName, newFilePath);

                        response.Removed.Add(src.HashedTarget);
                    }
                    else
                    {
                        // Copy file
                        await AzureBlobStorageApi.CopyFileAsync(src.File.FullName, newFilePath);
                    }

                    response.Added.Add(await CustomBaseModel.CustomCreateAsync(new AzureBlobFile(newFilePath), dest.RootVolume));
                }
            }

            return(await Json(response));
        }
예제 #2
0
        public async Task <JsonResult> RenameAsync(FullPath path, string name)
        {
            var response = new ReplaceResponseModel();

            response.Removed.Add(path.HashedTarget);
            await RemoveThumbsAsync(path);

            if (path.IsDirectory)
            {
                // Get new path
                var newPath = AzureStorageAPI.PathCombine(path.Directory.Parent.FullName, name);

                // Move file
                await AzureStorageAPI.MoveDirectoryAsync(path.Directory.FullName, newPath);

                // Add it to added entries list
                response.Added.Add(await BaseModel.CreateAsync(new AzureStorageDirectory(newPath), path.RootVolume));
            }
            else
            {
                // Get new path
                var newPath = AzureStorageAPI.PathCombine(path.File.DirectoryName ?? string.Empty, name);

                // Move file
                await AzureStorageAPI.MoveFileAsync(path.File.FullName, newPath);

                // Add it to added entries list
                response.Added.Add(await BaseModel.CreateAsync(new AzureStorageFile(newPath), path.RootVolume));
            }

            return(await Json(response));
        }
        public async Task <JsonResult> PasteAsync(FullPath dest, IEnumerable <FullPath> paths, bool isCut)
        {
            var response = new ReplaceResponseModel();

            foreach (var src in paths)
            {
                if (src.IsDirectory)
                {
                    var newDir = new AzureStorageDirectory(AzureStorageAPI.UrlCombine(dest.Directory.FullName, src.Directory.Name));

                    // Check if it already exists
                    if (await newDir.ExistsAsync)
                    {
                        // Exists
                        await newDir.DeleteAsync();
                    }

                    if (isCut)
                    {
                        RemoveThumbs(src);
                        await AzureStorageAPI.MoveDirectory(src.Directory.FullName, newDir.FullName);

                        response.Removed.Add(src.HashedTarget);
                    }
                    else
                    {
                        // Copy directory
                        await AzureStorageAPI.CopyDirectory(src.Directory.FullName, newDir.FullName);
                    }
                    response.Added.Add(await BaseModel.Create(this, newDir, dest.RootVolume));
                }
                else
                {
                    string newFilePath = AzureStorageAPI.UrlCombine(dest.Directory.FullName, src.File.Name);
                    await AzureStorageAPI.DeleteFileIfExists(newFilePath);

                    if (isCut)
                    {
                        RemoveThumbs(src);

                        // Move file
                        await AzureStorageAPI.MoveFile(src.File.FullName, newFilePath);

                        response.Removed.Add(src.HashedTarget);
                    }
                    else
                    {
                        // Copy file
                        await AzureStorageAPI.CopyFile(src.File.FullName, newFilePath);
                    }

                    response.Added.Add(await BaseModel.Create(this, new AzureStorageFile(newFilePath), dest.RootVolume));
                }
            }

            return(await Json(response));
        }
예제 #4
0
        public async Task <JsonResult> PasteAsync(FullPath dest, IEnumerable <FullPath> paths, bool isCut, IEnumerable <string> renames, string suffix)
        {
            var response = new ReplaceResponseModel();

            foreach (var src in paths)
            {
                if (src.IsDirectory)
                {
                    var newDir = new FileSystemDirectory(Path.Combine(dest.Directory.FullName, src.Directory.Name));
                    if (await newDir.ExistsAsync)
                    {
                        Directory.Delete(newDir.FullName, true);
                    }

                    if (isCut)
                    {
                        await RemoveThumbsAsync(src);

                        Directory.Move(src.Directory.FullName, newDir.FullName);
                        response.Removed.Add(src.HashedTarget);
                    }
                    else
                    {
                        DirectoryCopy(src.Directory.FullName, newDir.FullName, true);
                    }

                    response.Added.Add(await BaseModel.CreateAsync(newDir, dest.RootVolume));
                }
                else
                {
                    var newFile = new FileSystemFile(Path.Combine(dest.Directory.FullName, src.File.Name));
                    if (await newFile.ExistsAsync)
                    {
                        await newFile.DeleteAsync();
                    }

                    if (isCut)
                    {
                        await RemoveThumbsAsync(src);

                        File.Move(src.File.FullName, newFile.FullName);
                        response.Removed.Add(src.HashedTarget);
                    }
                    else
                    {
                        File.Copy(src.File.FullName, newFile.FullName);
                    }
                    response.Added.Add(await BaseModel.CreateAsync(newFile, dest.RootVolume));
                }
            }
            return(await Json(response));
        }
예제 #5
0
        public async Task <JsonResult> Paste(string source, string dest, IEnumerable <string> targets, bool isCut)
        {
            FullPath             destPath = ParsePath(dest);
            ReplaceResponseModel response = new ReplaceResponseModel();

            foreach (var item in targets)
            {
                FullPath src = ParsePath(item);
                if (src.Directory != null)
                {
                    DirectoryInfo newDir = new DirectoryInfo(Path.Combine(destPath.Directory.FullName, src.Directory.Name));
                    if (newDir.Exists)
                    {
                        Directory.Delete(newDir.FullName, true);
                    }
                    if (isCut)
                    {
                        RemoveThumbs(src);
                        src.Directory.MoveTo(newDir.FullName);
                        response.Removed.Add(item);
                    }
                    else
                    {
                        DirectoryCopy(src.Directory, newDir.FullName, true);
                    }
                    response.Added.Add(BaseModel.Create(newDir, destPath.Root));
                }
                else
                {
                    string newFilePath = Path.Combine(destPath.Directory.FullName, src.File.Name);
                    if (System.IO.File.Exists(newFilePath))
                    {
                        System.IO.File.Delete(newFilePath);
                    }
                    if (isCut)
                    {
                        RemoveThumbs(src);
                        src.File.MoveTo(newFilePath);
                        response.Removed.Add(item);
                    }
                    else
                    {
                        System.IO.File.Copy(src.File.FullName, newFilePath);
                    }
                    response.Added.Add(BaseModel.Create(new FileInfo(newFilePath), destPath.Root));
                }
            }
            return(await Json(response));
        }
예제 #6
0
        public async Task <JsonResult> Rename(string target, string name)
        {
            FullPath fullPath = ParsePath(target);
            var      answer   = new ReplaceResponseModel();

            answer.Removed.Add(target);
            RemoveThumbs(fullPath);
            if (fullPath.Directory != null)
            {
                string newPath = Path.Combine(fullPath.Directory.Parent.FullName, name);
                System.IO.Directory.Move(fullPath.Directory.FullName, newPath);
                answer.Added.Add(BaseModel.Create(new DirectoryInfo(newPath), fullPath.Root));
            }
            else
            {
                string newPath = Path.Combine(fullPath.File.DirectoryName, name);
                System.IO.File.Move(fullPath.File.FullName, newPath);
                answer.Added.Add(BaseModel.Create(new FileInfo(newPath), fullPath.Root));
            }
            return(await Json(answer));
        }
        public async Task <JsonResult> RenameAsync(FullPath path, string name)
        {
            var response = new ReplaceResponseModel();

            response.Removed.Add(path.HashedTarget);
            await RemoveThumbs(path);

            if (path.IsDirectory)
            {
                var newPath = new FileSystemDirectory(Path.Combine(path.Directory.Parent.FullName, name));
                Directory.Move(path.Directory.FullName, newPath.FullName);
                response.Added.Add(await BaseModel.Create(this, newPath, path.RootVolume));
            }
            else
            {
                var newPath = new FileSystemFile(Path.Combine(path.File.DirectoryName, name));
                File.Move(path.File.FullName, newPath.FullName);
                response.Added.Add(await BaseModel.Create(this, newPath, path.RootVolume));
            }
            return(await Json(response));
        }