remove assemblies.log logic
This commit is contained in:
@@ -22,7 +22,6 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
void InstallPackages();
|
||||
bool UninstallPackage(string PackageName);
|
||||
int RegisterAssemblies();
|
||||
Task UpgradeFramework(bool backup);
|
||||
void RestartApplication();
|
||||
}
|
||||
@@ -61,10 +60,6 @@ namespace Oqtane.Infrastructure
|
||||
Directory.CreateDirectory(sourceFolder);
|
||||
}
|
||||
|
||||
// read assembly log
|
||||
var assemblyLogPath = Path.Combine(sourceFolder, "assemblies.log");
|
||||
var assemblies = GetAssemblyLog(assemblyLogPath);
|
||||
|
||||
// install Nuget packages in secure Packages folder
|
||||
var packages = Directory.GetFiles(sourceFolder, "*.nupkg");
|
||||
foreach (string packagename in packages)
|
||||
@@ -162,27 +157,6 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if (packages.Length != 0)
|
||||
{
|
||||
// save assembly log
|
||||
SetAssemblyLog(assemblyLogPath, assemblies);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -270,10 +238,6 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
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
|
||||
string packagename = "";
|
||||
string[] packages = Directory.GetFiles(Path.Combine(_environment.ContentRootPath, Constants.PackagesFolder), PackageName + "*.log");
|
||||
@@ -298,23 +262,7 @@ namespace Oqtane.Infrastructure
|
||||
// do not remove licensing assemblies
|
||||
if (!Path.GetFileName(filepath).StartsWith("Oqtane.Licensing."))
|
||||
{
|
||||
// use assembly log to determine if assembly is used in other packages
|
||||
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);
|
||||
}
|
||||
DeleteFile(filepath);
|
||||
}
|
||||
}
|
||||
else // not an assembly
|
||||
@@ -329,9 +277,6 @@ namespace Oqtane.Infrastructure
|
||||
File.Delete(asset);
|
||||
}
|
||||
|
||||
// save assembly log
|
||||
SetAssemblyLog(assemblyLogPath, assemblies);
|
||||
|
||||
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)
|
||||
{
|
||||
string folder = Path.Combine(_environment.ContentRootPath, Constants.PackagesFolder);
|
||||
|
||||
@@ -33,7 +33,6 @@ namespace Oqtane.Infrastructure
|
||||
var visitorRepository = provider.GetRequiredService<IVisitorRepository>();
|
||||
var notificationRepository = provider.GetRequiredService<INotificationRepository>();
|
||||
var urlMappingRepository = provider.GetRequiredService<IUrlMappingRepository>();
|
||||
var installationManager = provider.GetRequiredService<IInstallationManager>();
|
||||
|
||||
// iterate through sites for current tenant
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user