refactor a good bit of stuff for better dependency injection
fix regular expression for T6 log parsing
This commit is contained in:
@ -11,11 +11,8 @@ namespace WebfrontCore.Controllers
|
||||
{
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
private readonly IPluginImporter _pluginImporter;
|
||||
|
||||
public HomeController(IManager manager, IPluginImporter importer) : base(manager)
|
||||
public HomeController(IManager manager) : base(manager)
|
||||
{
|
||||
_pluginImporter = importer;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Index()
|
||||
@ -68,7 +65,7 @@ namespace WebfrontCore.Controllers
|
||||
var pluginType = _cmd.GetType().Assembly.GetTypes().FirstOrDefault(_type => _type.Assembly != excludedAssembly && typeof(IPlugin).IsAssignableFrom(_type));
|
||||
return pluginType == null ?
|
||||
Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_HELP_COMMAND_NATIVE"] :
|
||||
_pluginImporter.ActivePlugins.First(_plugin => _plugin.GetType() == pluginType).Name; // for now we're just returning the name of the plugin, maybe later we'll include more info
|
||||
Manager.Plugins.First(_plugin => _plugin.GetType() == pluginType).Name; // for now we're just returning the name of the plugin, maybe later we'll include more info
|
||||
})
|
||||
.Select(_grp => (_grp.Key, _grp.AsEnumerable()));
|
||||
|
||||
|
@ -7,9 +7,14 @@ using Microsoft.AspNetCore.Mvc.Razor;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Database;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using WebfrontCore.Middleware;
|
||||
|
||||
@ -32,20 +37,33 @@ namespace WebfrontCore
|
||||
});
|
||||
});
|
||||
|
||||
IEnumerable<Assembly> pluginAssemblies()
|
||||
{
|
||||
string pluginDir = $"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}";
|
||||
|
||||
if (Directory.Exists(pluginDir))
|
||||
{
|
||||
var dllFileNames = Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}", "*.dll");
|
||||
return dllFileNames.Select(_file => Assembly.LoadFrom(_file));
|
||||
}
|
||||
|
||||
return Enumerable.Empty<Assembly>();
|
||||
}
|
||||
|
||||
// Add framework services.
|
||||
var mvcBuilder = services.AddMvc(_options => _options.SuppressAsyncSuffixInActionNames = false)
|
||||
.ConfigureApplicationPartManager(_ =>
|
||||
.ConfigureApplicationPartManager(_partManager =>
|
||||
{
|
||||
foreach (var assembly in Program.Manager.GetPluginAssemblies())
|
||||
foreach (var assembly in pluginAssemblies())
|
||||
{
|
||||
if (assembly.FullName.Contains("Views"))
|
||||
{
|
||||
_.ApplicationParts.Add(new CompiledRazorAssemblyPart(assembly));
|
||||
_partManager.ApplicationParts.Add(new CompiledRazorAssemblyPart(assembly));
|
||||
}
|
||||
|
||||
else if (assembly.FullName.Contains("Web"))
|
||||
{
|
||||
_.ApplicationParts.Add(new AssemblyPart(assembly));
|
||||
_partManager.ApplicationParts.Add(new AssemblyPart(assembly));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -58,7 +76,7 @@ namespace WebfrontCore
|
||||
});
|
||||
#endif
|
||||
|
||||
foreach (var asm in Program.Manager.GetPluginAssemblies())
|
||||
foreach (var asm in pluginAssemblies())
|
||||
{
|
||||
mvcBuilder.AddApplicationPart(asm);
|
||||
}
|
||||
@ -83,7 +101,7 @@ namespace WebfrontCore
|
||||
#endif
|
||||
|
||||
services.AddSingleton(Program.Manager);
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetService(typeof(IPluginImporter)) as IPluginImporter);
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetService<IConfigurationHandlerFactory>());
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
Reference in New Issue
Block a user