Fix concurrency
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
|
||||
namespace SharpIDE.Application.Features.SolutionDiscovery;
|
||||
@@ -10,7 +11,7 @@ public class SharpIdeFile : ISharpIdeNode, IChildSharpIdeNode
|
||||
public required string Name { get; set; }
|
||||
|
||||
[SetsRequiredMembers]
|
||||
internal SharpIdeFile(string fullPath, string name, IExpandableSharpIdeNode parent, HashSet<SharpIdeFile> allFiles)
|
||||
internal SharpIdeFile(string fullPath, string name, IExpandableSharpIdeNode parent, ConcurrentBag<SharpIdeFile> allFiles)
|
||||
{
|
||||
Path = fullPath;
|
||||
Name = name;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
|
||||
namespace SharpIDE.Application.Features.SolutionDiscovery;
|
||||
@@ -13,7 +14,7 @@ public class SharpIdeFolder : ISharpIdeNode, IExpandableSharpIdeNode, IChildShar
|
||||
public bool Expanded { get; set; }
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public SharpIdeFolder(DirectoryInfo folderInfo, IExpandableSharpIdeNode parent, HashSet<SharpIdeFile> allFiles)
|
||||
public SharpIdeFolder(DirectoryInfo folderInfo, IExpandableSharpIdeNode parent, ConcurrentBag<SharpIdeFile> allFiles)
|
||||
{
|
||||
Parent = parent;
|
||||
Path = folderInfo.FullName;
|
||||
|
||||
@@ -10,7 +10,7 @@ public static class TreeMapperV2
|
||||
return folder.Files
|
||||
.Concat(folder.Folders.SelectMany(sub => sub.GetAllFiles()));
|
||||
}
|
||||
public static List<SharpIdeFolder> GetSubFolders(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, HashSet<SharpIdeFile> allFiles)
|
||||
public static List<SharpIdeFolder> GetSubFolders(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, ConcurrentBag<SharpIdeFile> allFiles)
|
||||
{
|
||||
var projectDirectory = Path.GetDirectoryName(csprojectPath)!;
|
||||
var rootFolder = new SharpIdeFolder
|
||||
@@ -26,7 +26,7 @@ public static class TreeMapperV2
|
||||
}
|
||||
|
||||
private static readonly string[] _excludedFolders = ["bin", "obj", "node_modules"];
|
||||
public static List<SharpIdeFolder> GetSubFolders(this SharpIdeFolder folder, IExpandableSharpIdeNode parent, HashSet<SharpIdeFile> allFiles)
|
||||
public static List<SharpIdeFolder> GetSubFolders(this SharpIdeFolder folder, IExpandableSharpIdeNode parent, ConcurrentBag<SharpIdeFile> allFiles)
|
||||
{
|
||||
var directoryInfo = new DirectoryInfo(folder.Path);
|
||||
ConcurrentBag<SharpIdeFolder> subFolders = [];
|
||||
@@ -54,13 +54,13 @@ public static class TreeMapperV2
|
||||
return subFolders.ToList();
|
||||
}
|
||||
|
||||
public static List<SharpIdeFile> GetFiles(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, HashSet<SharpIdeFile> allFiles)
|
||||
public static List<SharpIdeFile> GetFiles(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, ConcurrentBag<SharpIdeFile> allFiles)
|
||||
{
|
||||
var projectDirectory = Path.GetDirectoryName(csprojectPath)!;
|
||||
var directoryInfo = new DirectoryInfo(projectDirectory);
|
||||
return GetFiles(directoryInfo, sharpIdeProjectModel, allFiles);
|
||||
}
|
||||
public static List<SharpIdeFile> GetFiles(this DirectoryInfo directoryInfo, IExpandableSharpIdeNode parent, HashSet<SharpIdeFile> allFiles)
|
||||
public static List<SharpIdeFile> GetFiles(this DirectoryInfo directoryInfo, IExpandableSharpIdeNode parent, ConcurrentBag<SharpIdeFile> allFiles)
|
||||
{
|
||||
List<FileInfo> fileInfos;
|
||||
try
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Channels;
|
||||
using Microsoft.Build.Evaluation;
|
||||
using SharpIDE.Application.Features.Evaluation;
|
||||
@@ -41,12 +42,14 @@ public class SharpIdeSolutionModel : ISharpIdeNode, IExpandableSharpIdeNode
|
||||
internal SharpIdeSolutionModel(string solutionFilePath, IntermediateSolutionModel intermediateModel)
|
||||
{
|
||||
var solutionName = Path.GetFileName(solutionFilePath);
|
||||
AllProjects = [];
|
||||
AllFiles = [];
|
||||
var allProjects = new ConcurrentBag<SharpIdeProjectModel>();
|
||||
var allFiles = new ConcurrentBag<SharpIdeFile>();
|
||||
Name = solutionName;
|
||||
FilePath = solutionFilePath;
|
||||
Projects = intermediateModel.Projects.Select(s => new SharpIdeProjectModel(s, AllProjects, AllFiles, this)).ToList();
|
||||
Folders = intermediateModel.SolutionFolders.Select(s => new SharpIdeSolutionFolder(s, AllProjects, AllFiles, this)).ToList();
|
||||
Projects = intermediateModel.Projects.Select(s => new SharpIdeProjectModel(s, allProjects, allFiles, this)).ToList();
|
||||
Folders = intermediateModel.SolutionFolders.Select(s => new SharpIdeSolutionFolder(s, allProjects, allFiles, this)).ToList();
|
||||
AllProjects = allProjects.ToHashSet();
|
||||
AllFiles = allFiles.ToHashSet();
|
||||
}
|
||||
}
|
||||
public class SharpIdeSolutionFolder : ISharpIdeNode, IExpandableSharpIdeNode, IChildSharpIdeNode
|
||||
@@ -59,7 +62,7 @@ public class SharpIdeSolutionFolder : ISharpIdeNode, IExpandableSharpIdeNode, IC
|
||||
public required IExpandableSharpIdeNode Parent { get; set; }
|
||||
|
||||
[SetsRequiredMembers]
|
||||
internal SharpIdeSolutionFolder(IntermediateSlnFolderModel intermediateModel, HashSet<SharpIdeProjectModel> allProjects, HashSet<SharpIdeFile> allFiles, IExpandableSharpIdeNode parent)
|
||||
internal SharpIdeSolutionFolder(IntermediateSlnFolderModel intermediateModel, ConcurrentBag<SharpIdeProjectModel> allProjects, ConcurrentBag<SharpIdeFile> allFiles, IExpandableSharpIdeNode parent)
|
||||
{
|
||||
Name = intermediateModel.Model.Name;
|
||||
Parent = parent;
|
||||
@@ -81,7 +84,7 @@ public class SharpIdeProjectModel : ISharpIdeNode, IExpandableSharpIdeNode, IChi
|
||||
public required Task<Project> MsBuildEvaluationProjectTask { get; set; }
|
||||
|
||||
[SetsRequiredMembers]
|
||||
internal SharpIdeProjectModel(IntermediateProjectModel projectModel, HashSet<SharpIdeProjectModel> allProjects, HashSet<SharpIdeFile> allFiles, IExpandableSharpIdeNode parent)
|
||||
internal SharpIdeProjectModel(IntermediateProjectModel projectModel, ConcurrentBag<SharpIdeProjectModel> allProjects, ConcurrentBag<SharpIdeFile> allFiles, IExpandableSharpIdeNode parent)
|
||||
{
|
||||
Parent = parent;
|
||||
Name = projectModel.Model.ActualDisplayName;
|
||||
|
||||
Reference in New Issue
Block a user