private ProjectItem GetDirectoryContent(string path, DirectoryInfo applicationRoot, string currentDirectoryName) { var rootDirectory = new ProjectItem(); rootDirectory.Type = ProjectItemType.Directory; rootDirectory.Name = currentDirectoryName; rootDirectory.Path = path; foreach (var directory in applicationRoot.GetDirectories()) { var repositoryItem = new ProjectItem(); repositoryItem.Name = directory.Name; repositoryItem.Path = Path.Combine(path, directory.Name).Replace(@"\", "/"); repositoryItem.Type = ProjectItemType.Directory; rootDirectory.Items.Add(repositoryItem); } foreach (var file in applicationRoot.GetFiles()) { var repositoryItem = new ProjectItem(); repositoryItem.Name = file.Name; repositoryItem.Path = Path.Combine(path, file.Name).Replace(@"\", "/"); ; repositoryItem.Type = ProjectItemType.File; rootDirectory.Items.Add(repositoryItem); } return rootDirectory; }
private ProjectItem GetContentFromPath(string username, string project, string projectSourceCodePath, string path) { var repositoryDirectory = new DirectoryInfo(projectSourceCodePath); DirectoryInfo applicationRoot = repositoryDirectory.GetDirectories()[0]; string currentDirectoryName = "root"; if (!string.IsNullOrEmpty(path)) { // Remove the trailing slash to support *.cs files if (path.EndsWith("/")) { path = path.Substring(0, path.Length - 1); } if (Path.IsPathRooted(path)) { return GetDirectoryContent(string.Empty, applicationRoot, currentDirectoryName); } else { var fullPath = Path.Combine(applicationRoot.FullName, path); if (fullPath.IsFilePath()) { // Get the file content var fileItem = new ProjectItem { Type = ProjectItemType.File }; fileItem.Path = path; fileItem.Name = Path.GetFileName(fullPath); fileItem.Content = this.editorService.BuildNavigatableSourceCodeFromFile(username, project, path); return fileItem; } else { applicationRoot = new DirectoryInfo(fullPath); currentDirectoryName = applicationRoot.Name; return GetDirectoryContent(path, applicationRoot, currentDirectoryName); } } } else { return GetDirectoryContent(string.Empty, applicationRoot, currentDirectoryName); } }