add stuff

This commit is contained in:
Matt Parker [SSW]
2025-01-10 19:52:28 +10:00
parent 5230fedfd0
commit 614893bf1a
3 changed files with 58 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
namespace SharpIDE.Application.Features.SolutionDiscovery;
public class Folder
{
public required string Name { get; set; }
public List<Folder> Folders { get; set; } = [];
public List<MyFile> Files { get; set; } = [];
}
public class MyFile
{
public required string Name { get; set; }
}

View File

@@ -1,12 +1,40 @@
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Globbing;
namespace SharpIDE.Application.Features.SolutionDiscovery;
public static class GetNodesInSolution
{
private static readonly ProjectCollection _projectCollection = new();
public static SolutionFile? ParseSolutionFileFromPath(string solutionFilePath)
{
var solutionFile = SolutionFile.Parse(solutionFilePath);
return solutionFile;
}
public static List<ProjectRootElement> GetCSharpProjectObjectsFromSolutionFile(SolutionFile solutionFile)
{
var projectList = solutionFile
.ProjectsByGuid.Where(x => x.Value.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat)
.Select(s => ProjectRootElement.Open(s.Value.AbsolutePath))
.ToList();
return projectList;
}
public static List<FileInfo> GetFilesInProject(string projectPath)
{
var project = _projectCollection.LoadProject(projectPath);
var compositeGlob = new CompositeGlob(project.GetAllGlobs().Select(s => s.MsBuildGlob));
var directory = new DirectoryInfo(Path.GetDirectoryName(projectPath)!);
var files = directory.EnumerateFiles("*", SearchOption.AllDirectories)
.Where(f =>
{
var relativeDirectory = Path.GetRelativePath(directory.FullName, f.FullName);
return compositeGlob.IsMatch(relativeDirectory);
})
.ToList();
return files;
}
}

View File

@@ -1,5 +1,9 @@
@page "/"
@using Microsoft.Build.Construction
@using Microsoft.Build.Evaluation
@using Microsoft.Build.Execution
@using Microsoft.Build.Globbing
@using Microsoft.Build.Globbing.Extensions
@using SharpIDE.Application.Features.SolutionDiscovery
<MudText>Welcome to a new Photino Blazor app!</MudText>
@@ -21,6 +25,7 @@
private SolutionFile _solutionFile = null!;
private List<ProjectInSolution> _rootNodes = [];
private Dictionary<string, List<Folder>> _folders = new();
private RenderFragment GetProjectFragment(ProjectInSolution project) =>
@<text>
@@ -29,9 +34,19 @@
{
@GetProjectFragment(child)
}
@GetFolderFragment(project)
</MudTreeViewItem>
</text>;
private RenderFragment GetFolderFragment(ProjectInSolution project) =>
@<text>
@foreach (var folder in _folders.GetValueOrDefault(project.ProjectGuid, []))
{
<MudTreeViewItem Value="folder" Text="@folder.Name">
</MudTreeViewItem>
}
</text>;
protected override async Task OnInitializedAsync()
{
var solutionFile = GetNodesInSolution.ParseSolutionFileFromPath("D:/matth/Documents/Git/amazon/ClientPortal.sln");
@@ -39,7 +54,8 @@
_solutionFile = solutionFile;
var rootNodes = solutionFile.ProjectsByGuid.Values.Where(p => p.ParentProjectGuid == null).OrderBy(s => s.ProjectName).ToList();
_rootNodes = rootNodes;
Console.WriteLine();
}
}