remove assemblies.log logic
This commit is contained in:
@@ -22,7 +22,6 @@ namespace Oqtane.Infrastructure
|
|||||||
{
|
{
|
||||||
void InstallPackages();
|
void InstallPackages();
|
||||||
bool UninstallPackage(string PackageName);
|
bool UninstallPackage(string PackageName);
|
||||||
int RegisterAssemblies();
|
|
||||||
Task UpgradeFramework(bool backup);
|
Task UpgradeFramework(bool backup);
|
||||||
void RestartApplication();
|
void RestartApplication();
|
||||||
}
|
}
|
||||||
@@ -61,10 +60,6 @@ namespace Oqtane.Infrastructure
|
|||||||
Directory.CreateDirectory(sourceFolder);
|
Directory.CreateDirectory(sourceFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// read assembly log
|
|
||||||
var assemblyLogPath = Path.Combine(sourceFolder, "assemblies.log");
|
|
||||||
var assemblies = GetAssemblyLog(assemblyLogPath);
|
|
||||||
|
|
||||||
// install Nuget packages in secure Packages folder
|
// install Nuget packages in secure Packages folder
|
||||||
var packages = Directory.GetFiles(sourceFolder, "*.nupkg");
|
var packages = Directory.GetFiles(sourceFolder, "*.nupkg");
|
||||||
foreach (string packagename in packages)
|
foreach (string packagename in packages)
|
||||||
@@ -162,27 +157,6 @@ namespace Oqtane.Infrastructure
|
|||||||
{
|
{
|
||||||
manifest = true;
|
manifest = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// register assembly
|
|
||||||
if (Path.GetExtension(filename) == ".dll")
|
|
||||||
{
|
|
||||||
// do not register licensing assemblies
|
|
||||||
if (!Path.GetFileName(filename).StartsWith("Oqtane.Licensing."))
|
|
||||||
{
|
|
||||||
// if package version was not installed previously
|
|
||||||
if (!File.Exists(Path.Combine(sourceFolder, name + ".log")))
|
|
||||||
{
|
|
||||||
if (assemblies.ContainsKey(Path.GetFileName(filename)))
|
|
||||||
{
|
|
||||||
assemblies[Path.GetFileName(filename)] += 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assemblies.Add(Path.GetFileName(filename), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,12 +186,6 @@ namespace Oqtane.Infrastructure
|
|||||||
File.Delete(packagename);
|
File.Delete(packagename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packages.Length != 0)
|
|
||||||
{
|
|
||||||
// save assembly log
|
|
||||||
SetAssemblyLog(assemblyLogPath, assemblies);
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,10 +238,6 @@ namespace Oqtane.Infrastructure
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(PackageName))
|
if (!string.IsNullOrEmpty(PackageName))
|
||||||
{
|
{
|
||||||
// read assembly log
|
|
||||||
var assemblyLogPath = Path.Combine(Path.Combine(_environment.ContentRootPath, Constants.PackagesFolder), "assemblies.log");
|
|
||||||
var assemblies = GetAssemblyLog(assemblyLogPath);
|
|
||||||
|
|
||||||
// get manifest with highest version
|
// get manifest with highest version
|
||||||
string packagename = "";
|
string packagename = "";
|
||||||
string[] packages = Directory.GetFiles(Path.Combine(_environment.ContentRootPath, Constants.PackagesFolder), PackageName + "*.log");
|
string[] packages = Directory.GetFiles(Path.Combine(_environment.ContentRootPath, Constants.PackagesFolder), PackageName + "*.log");
|
||||||
@@ -298,23 +262,7 @@ namespace Oqtane.Infrastructure
|
|||||||
// do not remove licensing assemblies
|
// do not remove licensing assemblies
|
||||||
if (!Path.GetFileName(filepath).StartsWith("Oqtane.Licensing."))
|
if (!Path.GetFileName(filepath).StartsWith("Oqtane.Licensing."))
|
||||||
{
|
{
|
||||||
// use assembly log to determine if assembly is used in other packages
|
DeleteFile(filepath);
|
||||||
if (assemblies.ContainsKey(Path.GetFileName(filepath)))
|
|
||||||
{
|
|
||||||
if (assemblies[Path.GetFileName(filepath)] == 1)
|
|
||||||
{
|
|
||||||
DeleteFile(filepath);
|
|
||||||
assemblies.Remove(Path.GetFileName(filepath));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assemblies[Path.GetFileName(filepath)] -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // does not exist in assembly log
|
|
||||||
{
|
|
||||||
DeleteFile(filepath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // not an assembly
|
else // not an assembly
|
||||||
@@ -329,9 +277,6 @@ namespace Oqtane.Infrastructure
|
|||||||
File.Delete(asset);
|
File.Delete(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// save assembly log
|
|
||||||
SetAssemblyLog(assemblyLogPath, assemblies);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -351,64 +296,6 @@ namespace Oqtane.Infrastructure
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int RegisterAssemblies()
|
|
||||||
{
|
|
||||||
var assemblyLogPath = GetAssemblyLogPath();
|
|
||||||
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
|
||||||
|
|
||||||
var assemblies = GetAssemblyLog(assemblyLogPath);
|
|
||||||
|
|
||||||
// remove assemblies that no longer exist
|
|
||||||
foreach (var dll in assemblies)
|
|
||||||
{
|
|
||||||
if (!File.Exists(Path.Combine(binFolder, dll.Key)))
|
|
||||||
{
|
|
||||||
assemblies.Remove(dll.Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// add assemblies which are not registered
|
|
||||||
foreach (var dll in Directory.GetFiles(binFolder, "*.dll"))
|
|
||||||
{
|
|
||||||
if (!assemblies.ContainsKey(Path.GetFileName(dll)))
|
|
||||||
{
|
|
||||||
assemblies.Add(Path.GetFileName(dll), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SetAssemblyLog(assemblyLogPath, assemblies);
|
|
||||||
|
|
||||||
return assemblies.Count;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetAssemblyLogPath()
|
|
||||||
{
|
|
||||||
string packagesFolder = Path.Combine(_environment.ContentRootPath, Constants.PackagesFolder);
|
|
||||||
if (!Directory.Exists(packagesFolder))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(packagesFolder);
|
|
||||||
}
|
|
||||||
return Path.Combine(packagesFolder, "assemblies.log");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Dictionary<string, int> GetAssemblyLog(string assemblyLogPath)
|
|
||||||
{
|
|
||||||
Dictionary<string, int> assemblies = new Dictionary<string, int>();
|
|
||||||
if (File.Exists(assemblyLogPath))
|
|
||||||
{
|
|
||||||
assemblies = JsonSerializer.Deserialize<Dictionary<string, int>>(File.ReadAllText(assemblyLogPath));
|
|
||||||
}
|
|
||||||
return assemblies;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SetAssemblyLog(string assemblyLogPath, Dictionary<string, int> assemblies)
|
|
||||||
{
|
|
||||||
if (File.Exists(assemblyLogPath))
|
|
||||||
{
|
|
||||||
File.Delete(assemblyLogPath);
|
|
||||||
}
|
|
||||||
File.WriteAllText(assemblyLogPath, JsonSerializer.Serialize(assemblies, new JsonSerializerOptions { WriteIndented = true }));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpgradeFramework(bool backup)
|
public async Task UpgradeFramework(bool backup)
|
||||||
{
|
{
|
||||||
string folder = Path.Combine(_environment.ContentRootPath, Constants.PackagesFolder);
|
string folder = Path.Combine(_environment.ContentRootPath, Constants.PackagesFolder);
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ namespace Oqtane.Infrastructure
|
|||||||
var visitorRepository = provider.GetRequiredService<IVisitorRepository>();
|
var visitorRepository = provider.GetRequiredService<IVisitorRepository>();
|
||||||
var notificationRepository = provider.GetRequiredService<INotificationRepository>();
|
var notificationRepository = provider.GetRequiredService<INotificationRepository>();
|
||||||
var urlMappingRepository = provider.GetRequiredService<IUrlMappingRepository>();
|
var urlMappingRepository = provider.GetRequiredService<IUrlMappingRepository>();
|
||||||
var installationManager = provider.GetRequiredService<IInstallationManager>();
|
|
||||||
|
|
||||||
// iterate through sites for current tenant
|
// iterate through sites for current tenant
|
||||||
List<Site> sites = siteRepository.GetSites().ToList();
|
List<Site> sites = siteRepository.GetSites().ToList();
|
||||||
@@ -97,17 +96,6 @@ namespace Oqtane.Infrastructure
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// register assemblies
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var assemblies = installationManager.RegisterAssemblies();
|
|
||||||
log += "<br />" + assemblies.ToString() + " Assemblies Registered<br />";
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
log += $"<br />Error Registering Assemblies - {ex.Message}<br />";
|
|
||||||
}
|
|
||||||
|
|
||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user