예제 #1
0
        /// <summary>
        /// Downloads the submissions for a given checkpoint, according to the
        /// options specified by the user, in the form of a zip archive.
        /// </summary>
        public async Task <Stream> DownloadSubmissionsAsync(
            string classroomName,
            string projectName,
            string checkpointName,
            IList <int> selectedUserIds,
            ProjectSubmissionDownloadFormat format)
        {
            var checkpoint = await LoadCheckpointAsync
                             (
                classroomName,
                projectName,
                checkpointName
                             );

            var allCheckpointSubmissions = GetCheckpointSubmissionsQuery
                                           (
                checkpoint,
                section: null                       // Include all sections
                                           );

            var selectedUserIdsHash = new HashSet <int>(selectedUserIds);

            var userIdsWithSubmissions = new HashSet <int>
                                         (
                await allCheckpointSubmissions
                .Where(submission => selectedUserIdsHash.Contains(submission.Commit.UserId))
                .GroupBy(submission => submission.Commit.User)
                .Select(group => group.Key.Id)
                .ToListAsync()
                                         );

            var sectionMemberships = await LoadSectionMembershipsAsync(classroomName);

            var studentDownloadRequests = sectionMemberships
                                          .Where
                                          (
                sm => selectedUserIdsHash.Contains(sm.ClassroomMembership.UserId)
                                          )
                                          .Select
                                          (
                sm => new StudentDownloadRequest
                (
                    sm.ClassroomMembership,
                    userIdsWithSubmissions.Contains(sm.ClassroomMembership.User.Id)
                )
                                          )
                                          .ToList();

            var templateContents = await _submissionDownloader.DownloadTemplateContentsAsync
                                   (
                checkpoint.Project
                                   );

            var submissionContents = await _submissionDownloader.DownloadSubmissionsAsync
                                     (
                checkpoint,
                studentDownloadRequests
                                     );

            return(await _submissionArchiveBuilder.BuildSubmissionArchiveAsync
                   (
                       checkpoint.Project,
                       templateContents,
                       submissionContents,
                       format
                   ));
        }
예제 #2
0
        /// <summary>
        /// Downloads all submissions for a given checkpoint in a section,
        /// in the form of a zip archive. The archive will also include
        /// the latest state of repositories for which there is no submission.
        /// </summary>
        public async Task <Stream> DownloadSubmissionsAsync(
            string classroomName,
            string projectName,
            string checkpointName,
            string sectionName)
        {
            var section = await LoadSectionAsync(classroomName, sectionName);

            var checkpoint = await LoadCheckpointAsync
                             (
                classroomName,
                projectName,
                checkpointName
                             );

            var students = await _dbContext.ClassroomMemberships
                           .Where
                           (
                cm => cm.SectionMemberships.Any
                (
                    sm => sm.SectionId == section.Id &&
                    sm.Role == SectionRole.Student
                )
                           )
                           .Include(cm => cm.User)
                           .ToListAsync();

            var allCheckpointSubmissions =
                await GetCheckpointSubmissionsQuery(checkpoint, section)
                .ToListAsync();

            var usersWithSubmissions = new HashSet <User>
                                       (
                allCheckpointSubmissions
                .GroupBy(submission => submission.Commit.User)
                .Select(group => group.Key)
                .ToList()
                                       );

            var studentDownloadRequests = students
                                          .Select
                                          (
                student => new StudentDownloadRequest
                (
                    student,
                    usersWithSubmissions.Contains(student.User)
                )
                                          ).ToList();

            var templateContents = await _submissionDownloader.DownloadTemplateContentsAsync
                                   (
                checkpoint.Project
                                   );

            var submissionContents = await _submissionDownloader.DownloadSubmissionsAsync
                                     (
                checkpoint,
                studentDownloadRequests
                                     );

            return(await _submissionArchiveBuilder.BuildSubmissionArchiveAsync
                   (
                       checkpoint.Project,
                       templateContents,
                       submissionContents
                   ));
        }