Beispiel #1
0
        public CourseContext(CourseService courseService, LanguageService languageService, CcData item, bool problemDir, string id = null)
        {
            CourseService   = courseService;
            LanguageService = languageService;
            Item            = item;
            Id        = id ?? Guid.Empty.ToString();
            CourseDir = courseService[item.CourseName].CourseDir;

            _tmpDir     = Path.Combine(Path.GetTempPath(), "automatest", Id);
            _problemDir = Path.Combine(CourseDir, Item.CourseYear, "problems", Item.Problem);
            _studentDir = problemDir ? _problemDir : Item.ResultDir(CourseDir);
            _dockerDir  = $"/tmp/{Id}";

            ProblemDir = new FileTree(_problemDir);
            TmpDir     = new FileTree(_tmpDir);
            StudentDir = new FileTree(_studentDir);
            DockerDir  = new FileTree(_dockerDir);
        }
Beispiel #2
0
        private IEnumerable <SimpleFile> BrowseFiles(CcData item, CourseProblem problem)
        {
            var context            = new CourseContext(_courseService, _languageService, item);
            var referenceRootDir   = new DirectoryInfo(context.ProblemDir.Root);
            var referenceOutputDir = new DirectoryInfo(context.ProblemDir.OutputDir);
            var allowedDirs        = new List <string> {
                "output", "input", "error", ".verification"
            };
            var resultDir  = item.ResultDir(problem.CourseYearConfig.Course.CourseDir);
            var studentDir = new DirectoryInfo(context.StudentDir.Root);

            var files = new List <SimpleFile>();

            if (item.Action == "solve")
            {
                files.AddRange(problem.Export.Select(i => ToSimpleFile(new FileInfo($"{resultDir}/{i}"))));
                files.Add(new SimpleFile
                {
                    RawPath  = studentDir.FullName,
                    Filename = "generated",
                    IsDir    = true,
                    Files    = studentDir.Exists
                            ? studentDir.GetDirectories()
                               .Where(i => allowedDirs.Contains(i.Name))
                               .Select(i => ToSimpleFile(i)).ToList()
                            : new List <SimpleFile>()
                });

                files.Add(ToSimpleFile(referenceOutputDir, "reference"));
                files.ForEach(i => PopulateRelPath(i));

                return(FilterEmptyFiles(files));
            }
            else
            {
                files.Add(ToSimpleFile(referenceRootDir, "reference"));
                files.ForEach(i => PopulateRelPath(i));
                return(FilterEmptyFiles(files));
            }
        }