コード例 #1
0
 private Sequence <int> CreateCombinedSequence(StudentSubmission submission)
 {
     return(new Sequence <int>(
                submission.Files
                .SelectMany(f => f.Tokens.Select(t => new Token <int>(t)))
                .ToList()));
 }
コード例 #2
0
ファイル: SubmissionTester.cs プロジェクト: ptyork/AugerLite
        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);
            }
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: Extensions.cs プロジェクト: Qkrisi/classroom-client
        public static void AddAttachments(this StudentSubmission submission, params Attachment[] attachments)
        {
            var request = new ModifyAttachmentsRequest();

            foreach (var attachment in attachments)
            {
                request.AddAttachments.Add(attachment);
            }
            SubmissionResourceHandler.ModifyAttachments(request, submission.CourseId, submission.CourseWorkId, submission.Id).Execute();
        }
コード例 #5
0
ファイル: SubmissionTester.cs プロジェクト: ptyork/AugerLite
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _browser.Dispose();
                }

                _presubmissionResults = null;
                _fullResults          = null;
                _submission           = null;
                _assignment           = null;
                _repo       = null;
                _validator  = null;
                _allDevices = null;
                _browser    = null;

                disposedValue = true;
            }
        }
コード例 #6
0
        public static async Task CargarDatosIniciales(object sender, EventArgs e)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("credentials-p4.json", FileMode.Open, FileAccess.Read))
            {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            //Servicio

            // Create Classroom API service.
            var service = new ClassroomService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            //1. Obtenemos los alumnos y los envíos de manera asíncrona

            CoursesResource.StudentsResource.ListRequest request = service.Courses.Students.List(_idcurso);
            CoursesResource.CourseWorkResource.StudentSubmissionsResource.ListRequest request2 = service.Courses.CourseWork.StudentSubmissions.List(_idcurso, _idtarea);

            var TareaClsAPi    = DescargarClsAPI(request);
            var TareaEnvíosAPI = DescargarClsEnvíosAPI(request2);

            var todasTareas = new List <Task> {
                TareaEnvíosAPI, TareaClsAPi
            };

            while (todasTareas.Count > 0)
            {
                Task finishedTask = await Task.WhenAny(todasTareas);

                if (finishedTask == TareaEnvíosAPI)
                {
                    /*frmppal.toolStripProgressBar2.ProgressBar.Style = ProgressBarStyle.Continuous;
                     * frmppal.toolStripProgressBar2.ProgressBar.Value = frmppal.toolStripProgressBar2.ProgressBar.Maximum;*/
                }
                else if (finishedTask == TareaClsAPi)
                {
                    /*frmppal.toolStripProgressBar3.ProgressBar.Style = ProgressBarStyle.Continuous;
                     * frmppal.toolStripProgressBar3.ProgressBar.Value = frmppal.toolStripProgressBar2.ProgressBar.Maximum;*/
                }
                todasTareas.Remove(finishedTask);
            }

            ListStudentsResponse resp_lista_estudiantes = TareaClsAPi.Result;
            var lista_estudiantes = resp_lista_estudiantes.Students;
            ListStudentSubmissionsResponse resp_lista_envíos = TareaEnvíosAPI.Result;
            var lista_envíos = resp_lista_envíos.StudentSubmissions;

            //MessageBox.Show(r.ToString());

            //2. Por cada envío, sus adjuntos, y almacenamos esa información en un diccionario de envíos
            if (lista_envíos != null && lista_envíos.Count > 0)
            {
                foreach (var envio in lista_envíos)
                {
                    //Console.WriteLine("{0} / {1}", trabajo.Id, trabajo.Description);
                    Console.WriteLine("{0} / {1} / {2}", envio.Id, envio.UpdateTime, envio.UserId);

                    /*this.TxtBoxDatosEnvío.Text = "Id Envío: " + envio.Id + Environment.NewLine;
                     * this.TxtBoxDatosEnvío.Text += "Fecha Envío: " + envio.UpdateTime + Environment.NewLine;
                     * this.TxtBoxDatosEnvío.Text += "Estado: " + envio.State + Environment.NewLine;
                     * this.TxtBoxDatosEnvío.Text += "Borrador: " + envio.DraftGrade + Environment.NewLine;
                     * this.TxtBoxDatosEnvío.Text += "Id Usuario: " + envio.UserId;*/

                    _envíos.Add(envio.UserId, envio);

                    /*if (envio.AssignmentSubmission != null)
                     * {
                     *  if (envio.AssignmentSubmission.Attachments != null && envio.AssignmentSubmission.Attachments.Count > 0)
                     *  {
                     *      Console.WriteLine("- Adjuntos -");
                     *      foreach (var adjunto in envio.AssignmentSubmission.Attachments)
                     *      {
                     *          Console.WriteLine(" - Enlace - {0}", adjunto.DriveFile.AlternateLink);
                     *          Console.WriteLine(" - Fichero - {0}", adjunto.DriveFile.Title);
                     *          Console.WriteLine(" - Id - {0}", adjunto.DriveFile.Id);
                     *          //Console.WriteLine(" - Id - {0}", adjunto.);
                     *
                     *          //this.DtGVAdjuntos.Rows.Add(adjunto.DriveFile.Id, adjunto.DriveFile.Title, adjunto.DriveFile.AlternateLink, "-");
                     *
                     *      }
                     *  }
                     *  else
                     *  {
                     *      //this.TxtBoxDatosEnvío.Text += Environment.NewLine + "No hay adjuntos";
                     *  }
                     * }
                     * else
                     * {
                     *  //this.TxtBoxDatosEnvío.Text += Environment.NewLine + "No hay información";
                     *
                     *
                     * }*/
                }
            }

            //3. Presentamos la información por pantalla
            if (lista_estudiantes != null && lista_estudiantes.Count > 0)
            {
                foreach (var estudiante in lista_estudiantes)
                {
                    string estudiante_id        = estudiante.UserId;
                    string estudiante_nombre    = estudiante.Profile.Name.GivenName;
                    string estudiante_apellidos = estudiante.Profile.Name.FamilyName;
                    string estudiante_email     = estudiante.Profile.EmailAddress;

                    Console.WriteLine("Correo electrónico: {0}", estudiante_email);
                    Console.WriteLine("{0} / {1} / {2} / {3}", estudiante.UserId, estudiante.Profile.Name.FullName, estudiante.Profile.Name.FamilyName, estudiante.Profile.Name.GivenName);
                    //2. Por cada alumno, obtenemos sus envíos
                    StudentSubmission envío = _envíos[estudiante_id];

                    string envío_id         = envío.Id;
                    string envío_fecha      = envío.UpdateTime.ToString();
                    string envío_estado     = envío.State;
                    string envío_retrasado  = envío.Late.ToString();
                    int    envío_n_adjuntos = 0;
                    if (envío.AssignmentSubmission != null)
                    {
                        if (envío.AssignmentSubmission.Attachments != null)
                        {
                            envío_n_adjuntos = envío.AssignmentSubmission.Attachments.Count();
                        }
                    }

                    frmTarea.DtGVEnvíos.Rows.Add(estudiante_id, estudiante_nombre, estudiante_apellidos, envío_id, envío_fecha, envío_estado, envío_retrasado, envío_n_adjuntos, "-");
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Updates one or more fields of a student submission. See google.classroom.v1.StudentSubmission for details of which fields may be updated and who may change them. This request must be made by the Developer Console project of the [OAuth client ID](https://support.google.com/cloud/answer/6158849) used to create the corresponding course work item. This method returns the following error codes: * `PERMISSION_DENIED` if the requesting developer project did not create the corresponding course work, if the user is not permitted to make the requested modification to the student submission, or for access errors. * `INVALID_ARGUMENT` if the request is malformed. * `NOT_FOUND` if the requested course, course work, or student submission does not exist.
        /// Documentation https://developers.google.com/classroom/v1/reference/studentSubmissions/patch
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated classroom service.</param>
        /// <param name="courseId">Identifier of the course. This identifier can be either the Classroom-assigned identifier or an alias.</param>
        /// <param name="courseWorkId">Identifier of the course work.</param>
        /// <param name="id">Identifier of the student submission.</param>
        /// <param name="body">A valid classroom v1 body.</param>
        /// <param name="optional">Optional paramaters.</param>        /// <returns>StudentSubmissionResponse</returns>
        public static StudentSubmission Patch(classroomService service, string courseId, string courseWorkId, string id, StudentSubmission body, StudentSubmissionsPatchOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (courseId == null)
                {
                    throw new ArgumentNullException(courseId);
                }
                if (courseWorkId == null)
                {
                    throw new ArgumentNullException(courseWorkId);
                }
                if (id == null)
                {
                    throw new ArgumentNullException(id);
                }

                // Building the initial request.
                var request = service.StudentSubmissions.Patch(body, courseId, courseWorkId, id);

                // Applying optional parameters to the request.
                request = (StudentSubmissionsResource.PatchRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request StudentSubmissions.Patch failed.", ex);
            }
        }
コード例 #8
0
        private void FrmTarea2_Load(object sender, EventArgs e)
        {
            this.Text = "Tarea: " + _titulo_tarea;

            UserCredential credential;

            using (var stream =
                       new FileStream("credentials-p4.json", FileMode.Open, FileAccess.Read))
            {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            //Servicio

            // Create Classroom API service.
            var service = new ClassroomService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            CoursesResource.StudentsResource.ListRequest request = service.Courses.Students.List(_idcurso);
            CoursesResource.CourseWorkResource.StudentSubmissionsResource.ListRequest request2 = service.Courses.CourseWork.StudentSubmissions.List(_idcurso, _idtarea);

            ListStudentsResponse           resp_lista_estudiantes = request.Execute();
            ListStudentSubmissionsResponse resp_lista_envíos      = request2.Execute();

            var lista_estudiantes = resp_lista_estudiantes.Students;
            var lista_envíos      = resp_lista_envíos.StudentSubmissions;

            if (lista_envíos != null && lista_envíos.Count > 0)
            {
                foreach (var envio in lista_envíos)
                {
                    Console.WriteLine("{0} / {1} / {2}", envio.Id, envio.UpdateTime, envio.UserId);
                    _envíos.Add(envio.UserId, envio);
                }
            }

            if (lista_estudiantes != null && lista_estudiantes.Count > 0)
            {
                foreach (var estudiante in lista_estudiantes)
                {
                    string estudiante_id        = estudiante.UserId;
                    string estudiante_nombre    = estudiante.Profile.Name.GivenName;
                    string estudiante_apellidos = estudiante.Profile.Name.FamilyName;
                    string estudiante_email     = estudiante.Profile.EmailAddress;

                    Console.WriteLine("Correo electrónico: {0}", estudiante_email);
                    Console.WriteLine("{0} / {1} / {2} / {3}", estudiante.UserId, estudiante.Profile.Name.FullName, estudiante.Profile.Name.FamilyName, estudiante.Profile.Name.GivenName);
                    //2. Por cada alumno, obtenemos sus envíos
                    StudentSubmission envío = _envíos[estudiante_id];

                    string envío_id         = envío.Id;
                    string envío_fecha      = envío.UpdateTime.ToString();
                    string envío_estado     = envío.State;
                    string envío_retrasado  = envío.Late.ToString();
                    int    envío_n_adjuntos = 0;
                    if (envío.AssignmentSubmission != null)
                    {
                        if (envío.AssignmentSubmission.Attachments != null)
                        {
                            envío_n_adjuntos = envío.AssignmentSubmission.Attachments.Count();
                        }
                    }

                    frmTarea2.DtGVEnvíos.Rows.Add(estudiante_id, estudiante_nombre, estudiante_apellidos, envío_id, envío_fecha, envío_estado, envío_retrasado, envío_n_adjuntos, "-");
                }
            }
        }
コード例 #9
0
        public void DescargarLista()
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("credentials-drive.json", FileMode.Open, FileAccess.Read))
            {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "token2.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes2,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Drive API service.
            var service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName2,
            });

            //var todasTareas = new List<Task> { };
            foreach (DataGridViewRow fila in frmTarea2.DtGVEnvíos.Rows)
            {
                //if(fila.Cells["ClnNAdjuntosEnvío"].Value.)
                //MessageBox.Show(fila.Cells["ClnIdAdjunto"].Value.ToString());
                //1. Preparar carpeta

                string nombre_alumno     = fila.Cells["ClnApellidosAlumno"].Value.ToString() + ", " + fila.Cells["ClnNombreAlumno"].Value.ToString();
                string fecha_entrega     = fila.Cells["ClnFechaEnvío"].Value.ToString();
                string cadena_ruta_fecha = fecha_entrega.Substring(8, 2) + fecha_entrega.Substring(3, 2) + fecha_entrega.Substring(0, 2);

                //MessageBox.Show(ComponerRuta(nombre_alumno, cadena_ruta_fecha));

                string filepath = ComponerRuta(nombre_alumno, cadena_ruta_fecha);

                Directory.CreateDirectory(filepath);

                /*string filepath = @"D:\Temp\tomate";
                *  if (!Directory.Exists(filepath))
                *   Directory.CreateDirectory(filepath);*/

                if (Int32.Parse(fila.Cells["ClnNAdjuntosEnvío"].Value.ToString()) > 0)
                {
                    fila.Cells["ClnDescarga"].Value = "Descargando...";
                    //todasTareas.Add(DownloadFile(service, fila.Cells["ClnIdAdjunto"].Value.ToString(), string.Format(filepath + @"\{0}", fila.Cells["ClnNombreFichero"].Value.ToString()), fila.Index, frmppal.DtGVAdjuntos));
                    StudentSubmission envío = _envíos[fila.Cells["ClnIdAlumno"].Value.ToString()];

                    if (envío.AssignmentSubmission != null)
                    {
                        if (envío.AssignmentSubmission.Attachments != null && envío.AssignmentSubmission.Attachments.Count > 0)
                        {
                            Console.WriteLine("- Adjuntos -");
                            var todasTareas = new List <Task> {
                            };                                    //prueba
                            foreach (var adjunto in envío.AssignmentSubmission.Attachments)
                            {
                                if (adjunto.DriveFile != null)
                                {
                                    Console.WriteLine(" - Enlace - {0}", adjunto.DriveFile.AlternateLink);
                                    Console.WriteLine(" - Fichero - {0}", adjunto.DriveFile.Title);
                                    Console.WriteLine(" - Id - {0}", adjunto.DriveFile.Id);
                                    //Console.WriteLine(" - Id - {0}", adjunto.);

                                    //this.DtGVAdjuntos.Rows.Add(adjunto.DriveFile.Id, adjunto.DriveFile.Title, adjunto.DriveFile.AlternateLink, "-");

                                    string nombre_fichero = adjunto.DriveFile.Title;
                                    foreach (var c in Path.GetInvalidFileNameChars())
                                    {
                                        nombre_fichero = nombre_fichero.Replace(c, '-');
                                    }

                                    //var todasTareas = new List<Task> { };
                                    todasTareas.Add(DownloadFile(service, adjunto.DriveFile.Id, string.Format(filepath + @"\{0}", nombre_fichero), fila.Index, frmTarea2.DtGVEnvíos, frmTarea2.DtGDescargas));
                                    //todasTareas.
                                    //Task.WaitAll(todasTareas.ToArray());
                                }
                                else
                                {
                                    fila.Cells["ClnDescarga"].Value = "Error";
                                }
                            }
                        }
                        else
                        {
                            fila.Cells["ClnDescarga"].Value = "No hay adjuntos";
                        }
                    }
                }
                else
                {
                    fila.Cells["ClnDescarga"].Value = "Ignorado";
                }
            }
        }
コード例 #10
0
 public SubmissionWrapper(StudentSubmission submission)
 {
     Submission = submission;
 }