Beispiel #1
0
 public virtual async Task <FileSystemDto> UpdateAsync([Required, StringLength(255)] string name, FileSystemUpdateDto input)
 {
     return(await FileSystemAppService.UpdateAsync(name, input));
 }
Beispiel #2
0
        public virtual Task <FileSystemDto> UpdateAsync([Required, StringLength(255)] string name, FileSystemUpdateDto input)
        {
            string fileSystemPath = GetFileSystemPath(name);
            var    renameFilePath = GetFileSystemPath(input.NewName);

            if (File.Exists(fileSystemPath))
            {
                if (File.Exists(renameFilePath))
                {
                    throw new UserFriendlyException(L["FilePathAlreadyExists"]);
                }
                File.Move(fileSystemPath, renameFilePath);

                var fileInfo   = new FileInfo(renameFilePath);
                var fileSystem = new FileSystemDto
                {
                    Type                 = FileSystemType.File,
                    Name                 = fileInfo.Name,
                    Size                 = fileInfo.Length,
                    Extension            = fileInfo.Extension,
                    CreationTime         = fileInfo.CreationTime,
                    LastModificationTime = fileInfo.LastWriteTime
                };
                if (fileInfo.Directory != null && !fileInfo.Directory.FullName.IsNullOrWhiteSpace())
                {
                    fileSystem.Parent = GetFileSystemRelativePath(fileInfo.Directory.FullName);
                }
                return(Task.FromResult(fileSystem));
            }
            if (Directory.Exists(fileSystemPath))
            {
                if (Directory.Exists(renameFilePath))
                {
                    throw new UserFriendlyException(L["FilePathAlreadyExists"]);
                }

                Directory.Move(fileSystemPath, renameFilePath);

                var directoryInfo = new DirectoryInfo(renameFilePath);
                var fileSystem    = new FileSystemDto
                {
                    Type                 = FileSystemType.Folder,
                    Name                 = directoryInfo.Name,
                    CreationTime         = directoryInfo.CreationTime,
                    LastModificationTime = directoryInfo.LastWriteTime
                };
                if (directoryInfo.Parent != null && !directoryInfo.Parent.FullName.IsNullOrWhiteSpace())
                {
                    fileSystem.Parent = GetFileSystemRelativePath(directoryInfo.Parent.FullName);
                }
                return(Task.FromResult(fileSystem));
            }
            throw new UserFriendlyException(L["FilePathNotFound"]);
        }