consolidated package installation so that it always occurs during startup and added logging in case of errors
This commit is contained in:
@ -103,6 +103,7 @@ namespace Oqtane.Controllers
|
||||
[HttpGet("list")]
|
||||
public List<string> List()
|
||||
{
|
||||
// could check environment.EnvironmentName to return actual file names instead
|
||||
return GetAssemblyList().Select(item => item.HashedName).ToList();
|
||||
}
|
||||
|
||||
|
@ -268,14 +268,6 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("install")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public void InstallModules()
|
||||
{
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Modules Installed");
|
||||
_installationManager.InstallPackages();
|
||||
}
|
||||
|
||||
// GET: api/<controller>/templates
|
||||
[HttpGet("templates")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
|
@ -41,14 +41,6 @@ namespace Oqtane.Controllers
|
||||
return _themes.GetThemes();
|
||||
}
|
||||
|
||||
[HttpGet("install")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public void InstallThemes()
|
||||
{
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Themes Installed");
|
||||
_installationManager.InstallPackages();
|
||||
}
|
||||
|
||||
// DELETE api/<controller>/xxx
|
||||
[HttpDelete("{themename}")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
|
@ -12,6 +12,8 @@ using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Oqtane.Controllers;
|
||||
using Oqtane.Shared;
|
||||
// ReSharper disable AssignNullToNotNullAttribute
|
||||
|
||||
@ -21,21 +23,27 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
private readonly IHostApplicationLifetime _hostApplicationLifetime;
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
private readonly ILogger<InstallationManager> _filelogger;
|
||||
|
||||
public InstallationManager(IHostApplicationLifetime hostApplicationLifetime, IWebHostEnvironment environment)
|
||||
public InstallationManager(IHostApplicationLifetime hostApplicationLifetime, IWebHostEnvironment environment, ILogger<InstallationManager> filelogger)
|
||||
{
|
||||
_hostApplicationLifetime = hostApplicationLifetime;
|
||||
_environment = environment;
|
||||
_filelogger = filelogger;
|
||||
}
|
||||
|
||||
public void InstallPackages()
|
||||
{
|
||||
InstallPackages(_environment.WebRootPath, _environment.ContentRootPath);
|
||||
var errors = InstallPackages(_environment.WebRootPath, _environment.ContentRootPath);
|
||||
if (!string.IsNullOrEmpty(errors))
|
||||
{
|
||||
_filelogger.LogError(errors);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool InstallPackages(string webRootPath, string contentRootPath)
|
||||
public static string InstallPackages(string webRootPath, string contentRootPath)
|
||||
{
|
||||
bool install = true;
|
||||
string errors = "";
|
||||
string binPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||
|
||||
string sourceFolder = Path.Combine(contentRootPath, "Packages");
|
||||
@ -172,16 +180,14 @@ namespace Oqtane.Infrastructure
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// problem installing package - logging is not possible as this is a static method
|
||||
Debug.WriteLine($"Oqtane Error: Installing Package {packagename} - {ex}");
|
||||
install = false;
|
||||
errors += $"Error Installing Package {packagename} - {ex.Message}. ";
|
||||
}
|
||||
|
||||
// remove package
|
||||
File.Delete(packagename);
|
||||
}
|
||||
|
||||
return install;
|
||||
return errors;
|
||||
}
|
||||
|
||||
private static string ExtractFile(ZipArchiveEntry entry, string folder, int ignoreLeadingSegments)
|
||||
@ -300,7 +306,7 @@ namespace Oqtane.Infrastructure
|
||||
if (packageversion != "" && Version.Parse(Constants.Version).CompareTo(Version.Parse(packageversion)) <= 0 && packageurl != "")
|
||||
{
|
||||
// install Oqtane.Framework and Oqtane.Updater nuget packages
|
||||
InstallPackages();
|
||||
InstallPackages(_environment.WebRootPath, _environment.ContentRootPath);
|
||||
// download upgrade zip package
|
||||
Uri uri = new Uri(packageurl);
|
||||
string upgradepackage = Path.Combine(folder, uri.Segments[uri.Segments.Length - 1]);
|
||||
|
@ -16,6 +16,7 @@ using Oqtane.Repository;
|
||||
using Oqtane.Security;
|
||||
using Oqtane.Shared;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Oqtane
|
||||
{
|
||||
@ -24,6 +25,7 @@ namespace Oqtane
|
||||
private readonly bool _useSwagger;
|
||||
private readonly IWebHostEnvironment _env;
|
||||
private readonly string[] _installedCultures;
|
||||
private string _configureServicesErrors;
|
||||
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
|
||||
@ -85,7 +87,7 @@ namespace Oqtane
|
||||
.AddOqtaneSingletonServices();
|
||||
|
||||
// install any modules or themes ( this needs to occur BEFORE the assemblies are loaded into the app domain )
|
||||
InstallationManager.InstallPackages(_env.WebRootPath, _env.ContentRootPath);
|
||||
_configureServicesErrors += InstallationManager.InstallPackages(_env.WebRootPath, _env.ContentRootPath);
|
||||
|
||||
// register transient scoped core services
|
||||
services.AddOqtaneTransientServices();
|
||||
@ -142,8 +144,13 @@ namespace Oqtane
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISyncManager sync)
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISyncManager sync, ILogger<Startup> logger)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_configureServicesErrors))
|
||||
{
|
||||
logger.LogError(_configureServicesErrors);
|
||||
}
|
||||
|
||||
ServiceActivator.Configure(app.ApplicationServices);
|
||||
|
||||
if (env.IsDevelopment())
|
||||
|
Reference in New Issue
Block a user