Merge pull request #362 from chlupac/PackageUnpack

Solution of warning about additional singleton of InstallManager
This commit is contained in:
Shaun Walker 2020-04-12 09:53:29 -04:00 committed by GitHub
commit f792e7e1c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 12 deletions

View File

@ -25,13 +25,25 @@ namespace Oqtane.Infrastructure
} }
public void InstallPackages(string folders, bool restart) public void InstallPackages(string folders, bool restart)
{
var webRootPath = _environment.WebRootPath;
var install = UnpackPackages(folders, webRootPath);
if (install && restart)
{
RestartApplication();
}
}
public static bool UnpackPackages(string folders, string webRootPath)
{ {
bool install = false; bool install = false;
string binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); string binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
foreach (string folder in folders.Split(',')) foreach (string folder in folders.Split(','))
{ {
string sourceFolder = Path.Combine(_environment.WebRootPath, folder); string sourceFolder = Path.Combine(webRootPath, folder);
// create folder if it does not exist // create folder if it does not exist
if (!Directory.Exists(sourceFolder)) if (!Directory.Exists(sourceFolder))
@ -66,6 +78,7 @@ namespace Oqtane.Infrastructure
{ {
frameworkversion = node.Attributes["version"].Value; frameworkversion = node.Attributes["version"].Value;
} }
reader.Close(); reader.Close();
} }
} }
@ -95,22 +108,21 @@ namespace Oqtane.Infrastructure
{ {
Directory.CreateDirectory(Path.GetDirectoryName(filename)); Directory.CreateDirectory(Path.GetDirectoryName(filename));
} }
entry.ExtractToFile(filename, true); entry.ExtractToFile(filename, true);
break; break;
} }
} }
} }
} }
// remove package // remove package
File.Delete(packagename); File.Delete(packagename);
install = true; install = true;
} }
} }
if (install && restart) return install;
{
RestartApplication();
}
} }
public void UpgradeFramework() public void UpgradeFramework()

View File

@ -25,6 +25,7 @@ namespace Oqtane
public class Startup public class Startup
{ {
public IConfigurationRoot Configuration { get; } public IConfigurationRoot Configuration { get; }
private string _webRoot;
public Startup(IWebHostEnvironment env) public Startup(IWebHostEnvironment env)
{ {
@ -32,7 +33,7 @@ namespace Oqtane
.SetBasePath(env.ContentRootPath) .SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
Configuration = builder.Build(); Configuration = builder.Build();
_webRoot = env.WebRootPath;
AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(env.ContentRootPath, "Data")); AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(env.ContentRootPath, "Data"));
} }
@ -155,11 +156,7 @@ namespace Oqtane
services.AddSingleton<DatabaseManager>(); services.AddSingleton<DatabaseManager>();
// install any modules or themes ( this needs to occur BEFORE the assemblies are loaded into the app domain ) // install any modules or themes ( this needs to occur BEFORE the assemblies are loaded into the app domain )
#pragma warning disable ASP0000 InstallationManager.UnpackPackages("Modules,Themes", _webRoot);
ServiceProvider sp = services.BuildServiceProvider();
#pragma warning restore ASP0000
var InstallationManager = sp.GetRequiredService<IInstallationManager>();
InstallationManager.InstallPackages("Modules,Themes", false);
// register transient scoped core services // register transient scoped core services
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>(); services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();