コード例 #1
0
ファイル: BrowseController.cs プロジェクト: ptyork/AugerLite
        public ActionResult BrowsePlay(int courseId, string userName, int playgroundId, string pathInfo)
        {
            var repo = PlaygroundRepository.Get(courseId, userName, playgroundId);
            var user = ApplicationUser.Current;

            // if this is the user's own repository OR the user is a super user OR the repository is shared,
            // then the repository should be browsable
            if (string.Equals(user.UserName, userName, StringComparison.OrdinalIgnoreCase) || user.IsInRole(UserRoles.SuperUserRole) || repo.GetIsShared())
            {
                return(_Browse(repo.FilePath, pathInfo));
            }
            // also allow instructors to view any repo for their courses
            try
            {
                var course = _GetCourse(courseId);
                if (course != null && user.IsInstructorForCourse(course))
                {
                    return(_Browse(repo.FilePath, pathInfo));
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }
            return(new HttpNotFoundResult());
        }
コード例 #2
0
ファイル: Playground.cs プロジェクト: ptyork/AugerLite
 public Playground(PlaygroundRepository repo)
 {
     this.UserName     = repo.UserName;
     this.CourseId     = repo.CourseId;
     this.PlaygroundId = repo.RepositoryId;
     this.Name         = repo.GetName();
     this.CreationDate = repo.Folder.CreationTime;
     this.UpdateDate   = repo.Folder.LastWriteTime;
     this.IsShared     = repo.GetIsShared();
 }
コード例 #3
0
ファイル: ViewController.cs プロジェクト: KPECTuK/glue-test
    // ReSharper disable once UnusedMember.Local
    private void OnEnable()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        _repository = new PlaygroundRepository();
        InitializeView();
        _controller = new PlaygroundController(this, _repository, this);
    }
コード例 #4
0
 public PlaygroundController(IExecutor executor, PlaygroundRepository repository, ViewController view)
 {
     Generator  = new OptionGeneratorCheating(repository);
     Repository = repository;
     View       = view;
     _stages    = new StageControllerBase[]
     {
         new StageControllerOwnSelect(executor, this),
         new StageControllerFoeSelect(executor, this),
         new StageControllerRoundResult(executor, this),
         new StageControllerCounterChange(executor, this),
         new StageControllerWaitForRound(executor, this),
     };
     _current = Array.FindIndex(_stages, _ => _ is StageControllerWaitForRound);
 }
コード例 #5
0
        public ActionResult ImportProject(ProjectImportPostData data)
        {
            var repo = _GetRepo(data);

            if (repo == null)
            {
                return(new HttpNotFoundResult());
            }

            Repository sourceRepo = null;
            int        courseId   = data.SourceCourseId > 0 ? data.SourceCourseId : data.CourseId;

            if (data.SourceType == ImportableProjects.Types.PLAYGROUND)
            {
                string userName = String.IsNullOrWhiteSpace(data.SourceUserName) ? data.UserName : data.SourceUserName;
                sourceRepo = PlaygroundRepository.Get(courseId, userName, data.SourceRepositoryId);
            }
            else if (data.SourceType == ImportableProjects.Types.WORKSPACE)
            {
                sourceRepo = WorkRepository.Get(courseId, data.UserName, data.SourceRepositoryId);
            }
            else if (data.SourceType == ImportableProjects.Types.SUBMISSION)
            {
                sourceRepo = SubmissionRepository.Get(courseId, data.UserName, data.SourceRepositoryId);
                sourceRepo.Checkout();
            }
            if (sourceRepo == null)
            {
                return(new HttpNotFoundResult());
            }

            try
            {
                repo.Commit("Before Import Project");
                repo.CopyFromRepository(sourceRepo);
                repo.Commit("After Import Project");
                return(Json("success"));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
コード例 #6
0
 public OptionGeneratorCheating(PlaygroundRepository repository)
 {
     _repository = repository;
     _inner      = new OptionGeneratorRandom(repository);
 }
コード例 #7
0
 public OptionGeneratorRandom(PlaygroundRepository repository)
 {
     _repository = repository;
 }
コード例 #8
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));
            }
        }