示例#1
0
        public ActionResult DownloadProject(IDEPostData data)
        {
            var repo = _GetRepo(data);

            if (repo == null)
            {
                return(new HttpNotFoundResult());
            }
            try
            {
                var name = "project.zip";
                //var zip = new Ionic.Zip.ZipFile();
                //zip.AddDirectory(repo.FilePath);
                //var ents = zip.SelectEntries(".git");
                //zip.RemoveEntries(ents);
                //var str = new System.IO.MemoryStream();
                //zip.Save(str);
                //str.Flush();
                //str.Seek(0, 0);
                //zip.Dispose();
                var str  = repo.Folder.GetAsZipStream();
                var file = File(str, "application/zip", name);
                return(file);
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
示例#2
0
        protected Repository _GetRepo(IDEPostData data)
        {
            Repository repo = null;

            try
            {
                var course = _GetCourse();
                if (course?.CourseId != data.CourseId)
                {
                    return(null);
                }

                repo = (T)Activator.CreateInstance(typeof(T), data.CourseId, data.UserName, data.RepositoryId, true);

                var user = ApplicationUser.Current;
                if (user == null)
                {
                    return(null);
                }

                // if this isn't the current user's repository and the user does not have sufficient rights,
                // then the repository must be shared
                if (!string.Equals(user.UserName, data.UserName, StringComparison.OrdinalIgnoreCase) && !user.IsInRole(UserRoles.SuperUserRole) && !user.IsInstructorForCourse(course))
                {
                    var pg = repo as PlaygroundRepository;
                    if (pg != null)
                    {
                        if (!pg.GetIsShared())
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }

                // if we get here, all is well so return the repo
                return(repo);
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }
            return(null);
        }
示例#3
0
        public ActionResult Submit(IDEPostData data)
        {
            var repo = _GetRepo(data);

            if (repo == null)
            {
                return(new HttpNotFoundResult());
            }
            try
            {
                // TODO: in the future manage issues with versions in this repo
                var submission = SubmissionManager.Submit(repo);
                return(new JsonNetResult(submission));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
示例#4
0
        public ActionResult GetFolder(IDEPostData data)
        {
            var repo = _GetRepo(data);

            if (repo == null)
            {
                string message = $"Unable to find repo for {data.CourseId} / {data.UserName} / {data.RepositoryId}";
                Elmah.ErrorSignal.FromCurrentContext().Raise(new System.IO.FileNotFoundException(message));
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound, message));
            }
            try
            {
                // TODO: in the future manage issues with versions in this repo
                var folder = repo.GetFolder();
                return(new JsonNetResult(folder));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
示例#5
0
        public ActionResult GetImportableProjects(IDEPostData data)
        {
            Course course = _GetCourse();

            if (course?.CourseId != data.CourseId)
            {
                return(new HttpNotFoundResult());
            }

            if (User?.GetName()?.ToLowerInvariant() != data.UserName.ToLowerInvariant())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Attempt to retrieve importable projects from another user."));
            }

            try
            {
                var projects = new ImportableProjects();

                var playgrounds = PlaygroundRepository.GetAllPlaygrounds(data.CourseId, data.UserName);
                foreach (var playground in playgrounds)
                {
                    if (typeof(T) == typeof(PlaygroundRepository) && playground.PlaygroundId == data.RepositoryId)
                    {
                        continue;
                    }
                    projects.Playgrounds.Add(new ImportableProjects.ImportableProject()
                    {
                        Type         = ImportableProjects.Types.PLAYGROUND,
                        CourseId     = playground.CourseId,
                        RepositoryId = playground.PlaygroundId,
                        Name         = playground.Name
                    });
                }

                var assignments = _db.StudentAssignments
                                  .Include(sa => sa.Assignment.Course)
                                  .Where(sa => sa.Enrollment.UserName == data.UserName) // CASE INSENSITIVE
                                  .OrderByDescending(sa => sa.Assignment.DateCreated);
                foreach (var assignment in assignments)
                {
                    var name = assignment.Assignment.AssignmentName;
                    if (course.CourseId != assignment.Assignment.CourseId)
                    {
                        name += $" ({assignment.Assignment.Course.ShortName})";
                    }
                    if (typeof(T) != typeof(WorkRepository) || assignment.AssignmentId.Value != data.RepositoryId)
                    {
                        if (WorkRepository.Exists(course.CourseId, data.UserName, data.RepositoryId))
                        {
                            projects.AssignmentWorkspaces.Add(new ImportableProjects.ImportableProject()
                            {
                                Type         = ImportableProjects.Types.WORKSPACE,
                                CourseId     = assignment.Assignment.CourseId,
                                RepositoryId = assignment.AssignmentId.Value,
                                Name         = name
                            });
                        }
                    }
                    if (assignment.HasSubmission)
                    {
                        if (typeof(T) != typeof(SubmissionRepository) || assignment.AssignmentId.Value != data.RepositoryId)
                        {
                            projects.AssignmentSubmissions.Add(new ImportableProjects.ImportableProject()
                            {
                                Type         = ImportableProjects.Types.SUBMISSION,
                                CourseId     = assignment.Assignment.CourseId,
                                RepositoryId = assignment.AssignmentId.Value,
                                Name         = name
                            });
                        }
                    }
                }

                return(new JsonNetResult(projects));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }