Пример #1
0
        public SubmissionTester(StudentSubmission submission)
        {
            _submission = submission;
            _assignment = submission.StudentAssignment.Assignment;

            _repo = SubmissionRepository.Get(submission.StudentAssignment);
            _repo.Checkout(submission.CommitId);

            _validator = new W3CValidator(_repo.FileUri);

            var allDeviceIds = _assignment.AllScripts.Select(s => s.DeviceId).Distinct();

            foreach (var deviceId in allDeviceIds)
            {
                _allDevices.Add(Device.Parse(deviceId));
            }
            if (_allDevices.Count == 0)
            {
                _allDevices.Add(Device.Large);
            }

            _browser = BrowserFactory.GetDriver();
            if (_browser != null)
            {
                _browser.SetWindowSize(Device.Large.ViewportWidth, Device.Large.ViewportHeight);
            }
        }
Пример #2
0
        public static StudentSubmission Submit(Repository workRepository)
        {
            StudentSubmission submission = new StudentSubmission();

            try
            {
                using (var db = new AugerContext())
                {
                    var studentAssignment = db.StudentAssignments
                                            .Include(sa => sa.Assignment)
                                            .Include(sa => sa.Enrollment.User)
                                            .FirstOrDefault(sa => sa.AssignmentId == workRepository.RepositoryId && sa.Enrollment.UserName == workRepository.UserName);

                    if (studentAssignment == null)
                    {
                        var ex = new InvalidOperationException("Unable to retrieve the student assignment from the given repository.");
                        submission.Exception = ex.Message;
                        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                    }
                    else
                    {
                        var repo = SubmissionRepository.Get(studentAssignment);

                        string commitId = repo.CommitFromRepository(workRepository);
                        if (commitId != null)
                        {
                            submission.StudentAssignment = studentAssignment;
                            //submission.StudentAssignment.AssignmentId = repo.RepositoryId;
                            submission.CommitId  = commitId;
                            submission.Succeeded = true;

                            db.StudentSubmissions.Add(submission);
                            studentAssignment.HasSubmission = true;

                            db.SaveChanges();

                            using (var t = new SubmissionTester(submission))
                            {
                                t.TestAll();
                            }

                            db.SaveChanges();
                        }
                        else
                        {
                            submission.Exception = "There were no changes detected. No new submission has been saved.";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                submission.Exception = ex.Message;
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }

            return(submission);
        }