Esempio n. 1
0
 private void EnsureTempDirectoryCreated()
 {
     if (!FileSystemService.DirectoryExists(FileSystemConfiguration.UploadTempPath))
     {
         FileSystemService.CreateDirectory(FileSystemConfiguration.UploadTempPath);
     }
 }
Esempio n. 2
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. 3
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. 4
0
        public async Task DeleteProjectAsync(string curUserId, string projectId)
        {
            string ptProjectId;

            using (IConnection conn = await RealtimeService.ConnectAsync(curUserId))
            {
                IDocument <SFProject> projectDoc = await conn.FetchAsync <SFProject>(projectId);

                if (!projectDoc.IsLoaded)
                {
                    throw new DataNotFoundException("The project does not exist.");
                }
                if (!IsProjectAdmin(projectDoc.Data, curUserId))
                {
                    throw new ForbiddenException();
                }

                ptProjectId = projectDoc.Data.ParatextId;
                // delete the project first, so that users get notified about the deletion
                string[] projectUserIds = projectDoc.Data.UserRoles.Keys.ToArray();
                await projectDoc.DeleteAsync();

                async Task removeUser(string projectUserId)
                {
                    IDocument <User> userDoc = await conn.FetchAsync <User>(projectUserId);

                    await RemoveUserFromProjectAsync(conn, projectDoc, userDoc);
                }

                var tasks = new List <Task>();
                foreach (string projectUserId in projectUserIds)
                {
                    tasks.Add(removeUser(projectUserId));
                }
                await Task.WhenAll(tasks);
            }

            await ProjectSecrets.DeleteAsync(projectId);

            await RealtimeService.DeleteProjectAsync(projectId);

            await _engineService.RemoveProjectAsync(projectId);

            string projectDir = Path.Combine(SiteOptions.Value.SiteDir, "sync", ptProjectId);

            if (FileSystemService.DirectoryExists(projectDir))
            {
                FileSystemService.DeleteDirectory(projectDir);
            }
            string audioDir = GetAudioDir(projectId);

            if (FileSystemService.DirectoryExists(audioDir))
            {
                FileSystemService.DeleteDirectory(audioDir);
            }
        }
    public async Task DirectoryExists()
    {
        // Given
        var          fileSystemService = new FileSystemService(_fileSystem);
        const string path1             = "/";
        const string path2             = "/nope";

        _fileSystem.Directory.Exists(path1).Returns(true);
        _fileSystem.Directory.Exists(path2).Returns(false);

        // When
        var actual1 = await fileSystemService.DirectoryExists(path1);

        var actual2 = await fileSystemService.DirectoryExists(path2);

        // Then
        Assert.True(actual1);
        Assert.False(actual2);
    }
Esempio n. 6
0
        private string GetFullDirPathWithCheckOnExistence(string rootKey)
        {
            string text = Path.Combine(RootDirectoryPath, PreparePath(rootKey));

            if (!FileSystemService.DirectoryExists(text))
            {
                throw new DirectoryNotFoundException(text);
            }
            return(text);
        }
Esempio n. 7
0
        public void CreateDirectory(string rootKey, string name)
        {
            CheckThatDirOrFileNameIsNotEmpty(name, "name");
            ValidateFileItemNameSymbols(name);
            string path = Path.Combine(GetFullDirPathWithCheckOnExistence(rootKey), name);

            if (FileSystemService.DirectoryExists(path))
            {
                FileManagementExceptionExecutor.ThrowDirectoryExists(Path.Combine(PreparePath(rootKey), name));
            }
            FileSystemService.CreateDirectory(path);
        }
Esempio n. 8
0
        protected virtual string GenerateCopiedFileItemPath(string path, string copiedFileItemName, bool isDirectory)
        {
            int    num = 0;
            string text;

            do
            {
                string str = (num < 1) ? string.Empty : $" {num}";
                text = Path.Combine(path, copiedFileItemName + " " + CopiedPrefix + str);
                num++;
            }while (isDirectory ? FileSystemService.DirectoryExists(text) : FileSystemService.FileExists(text));
            return(text);
        }
Esempio n. 9
0
        public void Remove(string path)
        {
            CheckThatDirOrFileNameIsNotEmpty(path, "path");
            string text = Path.Combine(RootDirectoryPath, PreparePath(path));

            if (FileSystemService.DirectoryExists(text))
            {
                FileSystemService.RemoveDirectory(text);
                return;
            }
            if (FileSystemService.FileExists(text))
            {
                FileSystemService.RemoveFile(text);
                return;
            }
            throw new FileNotFoundException(null, text);
        }
Esempio n. 10
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);
            }
        }