allow module and theme dependencies setting to include .dll file extension, added testmode config setting for validating list of assemblies sent to client

This commit is contained in:
Shaun Walker 2023-04-19 08:48:52 -07:00
parent e0c2b2982f
commit e0b0156640
2 changed files with 24 additions and 9 deletions

View File

@ -103,7 +103,6 @@ namespace Oqtane.Controllers
[HttpGet("list")] [HttpGet("list")]
public List<string> List() public List<string> List()
{ {
// could check environment.EnvironmentName to return actual file names instead
return GetAssemblyList().Select(item => item.HashedName).ToList(); return GetAssemblyList().Select(item => item.HashedName).ToList();
} }
@ -121,6 +120,13 @@ namespace Oqtane.Controllers
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var assemblyList = new List<ClientAssembly>(); var assemblyList = new List<ClientAssembly>();
// testmode setting is used for validating that the API is downloading the appropriate assemblies to the client
bool hashfilename = true;
if (_configManager.GetSetting($"{SettingKeys.TestModeKey}", "false") == "true")
{
hashfilename = false;
}
// get list of assemblies which should be downloaded to client // get list of assemblies which should be downloaded to client
var assemblies = AppDomain.CurrentDomain.GetOqtaneClientAssemblies(); var assemblies = AppDomain.CurrentDomain.GetOqtaneClientAssemblies();
var list = assemblies.Select(a => a.GetName().Name).ToList(); var list = assemblies.Select(a => a.GetName().Name).ToList();
@ -128,7 +134,7 @@ namespace Oqtane.Controllers
// populate assemblies // populate assemblies
for (int i = 0; i < list.Count; i++) for (int i = 0; i < list.Count; i++)
{ {
assemblyList.Add(new ClientAssembly(Path.Combine(binFolder, list[i] + ".dll"))); assemblyList.Add(new ClientAssembly(Path.Combine(binFolder, list[i] + ".dll"), hashfilename));
} }
// insert satellite assemblies at beginning of list // insert satellite assemblies at beginning of list
@ -144,7 +150,7 @@ namespace Oqtane.Controllers
{ {
foreach (var resourceFile in Directory.EnumerateFiles(assembliesFolderPath)) foreach (var resourceFile in Directory.EnumerateFiles(assembliesFolderPath))
{ {
assemblyList.Insert(0, new ClientAssembly(resourceFile)); assemblyList.Insert(0, new ClientAssembly(resourceFile, hashfilename));
} }
} }
else else
@ -161,12 +167,12 @@ namespace Oqtane.Controllers
var instance = Activator.CreateInstance(type) as IModule; var instance = Activator.CreateInstance(type) as IModule;
foreach (string name in instance.ModuleDefinition.Dependencies.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Reverse()) foreach (string name in instance.ModuleDefinition.Dependencies.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Reverse())
{ {
var filepath = Path.Combine(binFolder, name + ".dll"); var filepath = Path.Combine(binFolder, name.ToLower().EndsWith(".dll") ? name : name + ".dll");
if (System.IO.File.Exists(filepath)) if (System.IO.File.Exists(filepath))
{ {
if (!assemblyList.Exists(item => item.FilePath == filepath)) if (!assemblyList.Exists(item => item.FilePath == filepath))
{ {
assemblyList.Insert(0, new ClientAssembly(filepath)); assemblyList.Insert(0, new ClientAssembly(filepath, hashfilename));
} }
} }
else else
@ -180,12 +186,12 @@ namespace Oqtane.Controllers
var instance = Activator.CreateInstance(type) as ITheme; var instance = Activator.CreateInstance(type) as ITheme;
foreach (string name in instance.Theme.Dependencies.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Reverse()) foreach (string name in instance.Theme.Dependencies.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Reverse())
{ {
var filepath = Path.Combine(binFolder, name + ".dll"); var filepath = Path.Combine(binFolder, name.ToLower().EndsWith(".dll") ? name : name + ".dll");
if (System.IO.File.Exists(filepath)) if (System.IO.File.Exists(filepath))
{ {
if (!assemblyList.Exists(item => item.FilePath == filepath)) if (!assemblyList.Exists(item => item.FilePath == filepath))
{ {
assemblyList.Insert(0, new ClientAssembly(filepath)); assemblyList.Insert(0, new ClientAssembly(filepath, hashfilename));
} }
} }
else else
@ -286,11 +292,18 @@ namespace Oqtane.Controllers
public struct ClientAssembly public struct ClientAssembly
{ {
public ClientAssembly(string filepath) public ClientAssembly(string filepath, bool hashfilename)
{ {
FilePath = filepath; FilePath = filepath;
DateTime lastwritetime = System.IO.File.GetLastWriteTime(filepath); DateTime lastwritetime = System.IO.File.GetLastWriteTime(filepath);
HashedName = GetDeterministicHashCode(filepath).ToString("X8") + "." + lastwritetime.ToString("yyyyMMddHHmmss") + Path.GetExtension(filepath); if (hashfilename)
{
HashedName = GetDeterministicHashCode(filepath).ToString("X8") + "." + lastwritetime.ToString("yyyyMMddHHmmss") + Path.GetExtension(filepath);
}
else
{
HashedName = Path.GetFileNameWithoutExtension(filepath) + "." + lastwritetime.ToString("yyyyMMddHHmmss") + Path.GetExtension(filepath);
}
} }
public string FilePath { get; private set; } public string FilePath { get; private set; }

View File

@ -19,5 +19,7 @@ namespace Oqtane.Shared
public const string DefaultContainerKey = "DefaultContainer"; public const string DefaultContainerKey = "DefaultContainer";
public const string AvailableDatabasesSection = "AvailableDatabases"; public const string AvailableDatabasesSection = "AvailableDatabases";
public const string TestModeKey = "TestMode"; // optional - used for testing run-time characteristics
} }
} }