Exemplo n.º 1
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);
            }
        }