Esempio n. 1
0
        public void Move(string sourcePath, string destinationPath)
        {
            string text  = Path.Combine(RootDirectoryPath, PreparePath(sourcePath));
            string text2 = Path.Combine(RootDirectoryPath, PreparePath(destinationPath), Path.GetFileName(text));

            if (text == text2)
            {
                throw new Exception("Source and destination paths should be different.");
            }
            if (text2.StartsWith(text))
            {
                throw new Exception("Incorrect destination path for the move operation.");
            }
            if (FileSystemService.DirectoryExists(text))
            {
                FileSystemService.MoveDirectory(text, text2);
            }
            else if (FileSystemService.FileExists(text))
            {
                FileSystemService.MoveFile(text, text2);
            }
            else
            {
                FileManagementExceptionExecutor.ThrowFileNotFound(text);
            }
        }
Esempio n. 2
0
        public void Rename(string key, string newName)
        {
            CheckThatDirOrFileNameIsNotEmpty(key, "key");
            CheckThatDirOrFileNameIsNotEmpty(newName, "newName");
            ValidateFileItemNameSymbols(newName);
            string text = Path.Combine(RootDirectoryPath, PreparePath(key));
            string path = Path.GetDirectoryName(text) ?? string.Empty;

            if (FileSystemService.DirectoryExists(text))
            {
                if (string.Equals(Path.GetFullPath(RootDirectoryPath), Path.GetFullPath(text), StringComparison.OrdinalIgnoreCase))
                {
                    FileManagementExceptionExecutor.ThrowNoAccess();
                }
                string destDirName = Path.Combine(path, newName);
                FileSystemService.MoveDirectory(text, destDirName);
            }
            else if (FileSystemService.FileExists(text))
            {
                string extension = Path.GetExtension(text);
                if (!newName.Contains("."))
                {
                    newName += extension;
                }
                string destFileName = Path.Combine(path, newName);
                FileSystemService.MoveFile(text, destFileName);
            }
            else
            {
                FileManagementExceptionExecutor.ThrowFileNotFound(text);
            }
        }
Esempio n. 3
0
        public Stream GetFileContent(FileItemPathInfo pathInfo)
        {
            string path = pathInfo?.GetPath();
            string text = Path.Combine(RootDirectoryPath, PreparePath(path));

            if (Path.GetDirectoryName(text) == null)
            {
                _ = string.Empty;
            }
            if (FileSystemService.FileExists(text))
            {
                return(FileSystemService.GetFileContent(text));
            }
            FileManagementExceptionExecutor.ThrowFileNotFound(text);
            return(null);
        }
Esempio n. 4
0
        public void Copy(string sourcePath, string destinationPath)
        {
            string text = Path.Combine(RootDirectoryPath, PreparePath(sourcePath));
            string path = Path.Combine(RootDirectoryPath, PreparePath(destinationPath));

            if (FileSystemService.DirectoryExists(text))
            {
                string destinationPath2 = GenerateCopiedFileItemPath(path, Path.GetFileName(text), isDirectory: true);
                FileSystemService.CopyDirectory(text, destinationPath2);
            }
            else if (FileSystemService.FileExists(text))
            {
                string destinationFilePath = GenerateCopiedFileItemPath(path, Path.GetFileName(text), isDirectory: false);
                FileSystemService.CopyFile(text, destinationFilePath);
            }
            else
            {
                FileManagementExceptionExecutor.ThrowFileNotFound(destinationPath);
            }
        }