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 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); }