public static PlaygroundRepository Create(int courseId, string userName, string name)
        {
            if (string.IsNullOrWhiteSpace(_basePath))
            {
                throw new InvalidOperationException("This repository type has not been initialized.");
            }

            var dir = Directory.CreateDirectory($"{_basePath}\\{courseId}\\{userName}");
            var max = 0;

            foreach (var subdir in dir.GetDirectories())
            {
                int id;
                if (int.TryParse(subdir.Name, out id))
                {
                    if (id > max)
                    {
                        max = id;
                    }
                }
            }
            var repo = new PlaygroundRepository(courseId, userName, ++max, true);

            repo.SetName(name);
            return(repo);
        }
        public static List <Playground> GetSharedPlaygrounds(int courseId)
        {
            if (string.IsNullOrWhiteSpace(_basePath))
            {
                throw new InvalidOperationException("This repository type has not been initialized.");
            }

            var playgrounds = new List <Playground>();
            var fileName    = $"{_basePath}\\{courseId}\\.shared-playgrounds.txt";

            if (File.Exists(fileName))
            {
                var sharedText = File.ReadAllText(fileName);
                var sharedList = sharedText.Split(',');
                foreach (var path in sharedList)
                {
                    var parts = path.Split('\\');
                    if (parts.Length != 2)
                    {
                        continue;
                    }
                    var userName     = parts[0];
                    int playgroundId = 0;
                    if (int.TryParse(parts[1], out playgroundId))
                    {
                        var repo = new PlaygroundRepository(courseId, userName, playgroundId);
                        playgrounds.Add(repo.GetPlayground());
                    }
                }
            }
            return(playgrounds);
        }
 public static void Delete(PlaygroundRepository repo)
 {
     repo.SetIsShared(false);
     _Retry(() => {
         foreach (var info in repo.Folder.GetFileSystemInfos("*", SearchOption.AllDirectories))
         {
             info.Attributes = FileAttributes.Normal;
         }
         repo.Folder.Delete(true);
     });
 }
        public static List <Playground> GetAllPlaygrounds(int courseId, string userName)
        {
            if (string.IsNullOrWhiteSpace(_basePath))
            {
                throw new InvalidOperationException("This repository type has not been initialized.");
            }

            var playgrounds = new List <Playground>();
            var dir         = Directory.CreateDirectory($"{_basePath}\\{courseId}\\{userName}");

            foreach (var subdir in dir.GetDirectories().OrderBy(d => d.Name))
            {
                int playgroundId;
                if (int.TryParse(subdir.Name, out playgroundId))
                {
                    var repo = new PlaygroundRepository(courseId, userName, playgroundId);
                    playgrounds.Add(repo.GetPlayground());
                }
            }
            return(playgrounds);
        }
Beispiel #5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            TemplateManager.Init(GetPath("AugerTemplateDir"));
            SubmissionRepository.Init(GetPath("AugerSubmissionDir"));
            WorkRepository.Init(GetPath("AugerWorkDir"));
            PlaygroundRepository.Init(GetPath("AugerPlaygroundDir"));
            TempDir.Init(GetPath("AugerTempDir"));
            //TemplateManager.Init(Server.MapPath("~/app_data/templates/"));
            //SubmissionRepository.Init(Server.MapPath("~/app_data/repo/"));
            //WorkRepository.Init(Server.MapPath("~/app_data/work/"));
            //PlaygroundRepository.Init(Server.MapPath("~/app_data/play/"));
            //TempDir.Init(Server.MapPath("~/app_data/temp/"));

            //HostingEnvironment.RegisterVirtualPathProvider(new RepositoryVPP());

            HttpContext.Current.Server.ScriptTimeout = 2400;
        }