mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 14:04:26 +01:00
Fix system plugins resource loading
This commit is contained in:
@@ -20,6 +20,7 @@ namespace BTCPayServer.Plugins.Test.Services
|
|||||||
await using var context = _testPluginDbContextFactory.CreateContext();
|
await using var context = _testPluginDbContextFactory.CreateContext();
|
||||||
|
|
||||||
await context.TestPluginRecords.AddAsync(new TestPluginData() {Timestamp = DateTimeOffset.UtcNow});
|
await context.TestPluginRecords.AddAsync(new TestPluginData() {Timestamp = DateTimeOffset.UtcNow});
|
||||||
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<h2>Persisted Data</h2>
|
<h2>Persisted Data</h2>
|
||||||
<p>The following is data persisted to the configured database but in an isolated DbContext. Every time you start BTCPayw with this plugin enabled, a timestamp is logged.</p>
|
<p>The following is data persisted to the configured database but in an isolated DbContext. Every time you start BTCPayw with this plugin enabled, a timestamp is logged.</p>
|
||||||
<ul class="list-group">>
|
<ul class="list-group">
|
||||||
@foreach (var item in Model.Data)
|
@foreach (var item in Model.Data)
|
||||||
{
|
{
|
||||||
<li class="list-group-item">@item.Id at @item.Timestamp.ToString("F")</li>
|
<li class="list-group-item">@item.Id at @item.Timestamp.ToString("F")</li>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace BTCPayServer.Plugins
|
|||||||
private static readonly List<PluginLoader> _plugins = new List<PluginLoader>();
|
private static readonly List<PluginLoader> _plugins = new List<PluginLoader>();
|
||||||
private static ILogger _logger;
|
private static ILogger _logger;
|
||||||
|
|
||||||
|
private static List<(PluginLoader, Assembly, IFileProvider)> loadedPlugins;
|
||||||
public static bool IsExceptionByPlugin(Exception exception)
|
public static bool IsExceptionByPlugin(Exception exception)
|
||||||
{
|
{
|
||||||
return _pluginAssemblies.Any(assembly => assembly?.FullName?.Contains(exception.Source!, StringComparison.OrdinalIgnoreCase) is true);
|
return _pluginAssemblies.Any(assembly => assembly?.FullName?.Contains(exception.Source!, StringComparison.OrdinalIgnoreCase) is true);
|
||||||
@@ -43,16 +44,24 @@ namespace BTCPayServer.Plugins
|
|||||||
_logger.LogInformation($"Loading plugins from {pluginsFolder}");
|
_logger.LogInformation($"Loading plugins from {pluginsFolder}");
|
||||||
Directory.CreateDirectory(pluginsFolder);
|
Directory.CreateDirectory(pluginsFolder);
|
||||||
ExecuteCommands(pluginsFolder);
|
ExecuteCommands(pluginsFolder);
|
||||||
List<(PluginLoader, Assembly, IFileProvider)> loadedPlugins =
|
loadedPlugins = new List<(PluginLoader, Assembly, IFileProvider)>();
|
||||||
new List<(PluginLoader, Assembly, IFileProvider)>();
|
var systemPlugins = GetDefaultLoadedPluginAssemblies();
|
||||||
var systemExtensions = GetDefaultLoadedPluginAssemblies();
|
|
||||||
plugins.AddRange(systemExtensions.SelectMany(assembly =>
|
|
||||||
GetAllPluginTypesFromAssembly(assembly).Select(GetPluginInstanceFromType)));
|
|
||||||
foreach (IBTCPayServerPlugin btcPayServerExtension in plugins)
|
|
||||||
{
|
|
||||||
btcPayServerExtension.SystemPlugin = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
foreach (Assembly systemExtension in systemPlugins)
|
||||||
|
{
|
||||||
|
var detectedPlugins = GetAllPluginTypesFromAssembly(systemExtension).Select(GetPluginInstanceFromType);
|
||||||
|
if (!detectedPlugins.Any())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
|
||||||
|
}
|
||||||
|
foreach (var btcPayServerPlugin in detectedPlugins)
|
||||||
|
{
|
||||||
|
btcPayServerPlugin.SystemPlugin = true;
|
||||||
|
loadedPlugins.Add((null,systemExtension, CreateEmbeddedFileProviderForAssembly(systemExtension)));
|
||||||
|
}
|
||||||
|
plugins.AddRange(detectedPlugins);
|
||||||
|
}
|
||||||
var orderFilePath = Path.Combine(pluginsFolder, "order");
|
var orderFilePath = Path.Combine(pluginsFolder, "order");
|
||||||
|
|
||||||
var availableDirs = Directory.GetDirectories(pluginsFolder);
|
var availableDirs = Directory.GetDirectories(pluginsFolder);
|
||||||
@@ -77,8 +86,6 @@ namespace BTCPayServer.Plugins
|
|||||||
|
|
||||||
var disabledPlugins = GetDisabledPlugins(pluginsFolder);
|
var disabledPlugins = GetDisabledPlugins(pluginsFolder);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach (var dir in orderedDirs)
|
foreach (var dir in orderedDirs)
|
||||||
{
|
{
|
||||||
var pluginName = Path.GetFileName(dir);
|
var pluginName = Path.GetFileName(dir);
|
||||||
@@ -154,9 +161,7 @@ namespace BTCPayServer.Plugins
|
|||||||
|
|
||||||
var webHostEnvironment = applicationBuilder.ApplicationServices.GetService<IWebHostEnvironment>();
|
var webHostEnvironment = applicationBuilder.ApplicationServices.GetService<IWebHostEnvironment>();
|
||||||
List<IFileProvider> providers = new List<IFileProvider>() {webHostEnvironment.WebRootFileProvider};
|
List<IFileProvider> providers = new List<IFileProvider>() {webHostEnvironment.WebRootFileProvider};
|
||||||
providers.AddRange(
|
providers.AddRange(loadedPlugins.Select(tuple => tuple.Item3));
|
||||||
_pluginAssemblies
|
|
||||||
.Select(CreateEmbeddedFileProviderForAssembly));
|
|
||||||
webHostEnvironment.WebRootFileProvider = new CompositeFileProvider(providers);
|
webHostEnvironment.WebRootFileProvider = new CompositeFileProvider(providers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user