lots of tidying up

This commit is contained in:
TheXamlGuy
2024-01-25 20:33:55 +00:00
parent 5e26e97f6b
commit a322893166
20 changed files with 115 additions and 123 deletions
+33
View File
@@ -0,0 +1,33 @@
using Microsoft.Extensions.Hosting;
using System.Reflection;
using System.Runtime.Loader;
namespace Hyperbar.Widget;
public class WidgetEnumerator(IHostEnvironment hostEnvironment,
IMediator mediator) :
INotificationHandler<Enumerate<IWidget>>
{
public Task Handle(Enumerate<IWidget> notification,
CancellationToken cancellationToken)
{
string extensionsDirectory = Path.Combine(hostEnvironment.ContentRootPath, "Extensions");
if (Directory.Exists(extensionsDirectory))
{
List<string> assemblyPaths =
[
.. Directory.GetDirectories(extensionsDirectory)
.AsParallel()
.SelectMany(assemblyDirectory => Directory.GetFiles(assemblyDirectory, "*.dll"))
];
Parallel.ForEach(assemblyPaths, (string assemblyPath) =>
{
Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);
mediator.PublishAsync(new Created<Assembly>(assembly));
});
}
return Task.CompletedTask;
}
}