changed ServerAssemblyName to ServerManagerType to optimize processing

This commit is contained in:
Shaun Walker 2020-04-16 22:27:12 -04:00
parent f5e4c1dd29
commit b9d70dd11a
12 changed files with 69 additions and 79 deletions

View File

@ -55,7 +55,7 @@
protected override void OnInitialized() protected override void OnInitialized()
{ {
AddModuleMessage("Please Note That Once You Select The Create Module Button The Application Must Restart In Order To Complete The Process.", MessageType.Info); AddModuleMessage("Please Note That Once You Select The Create Module Button The Application Must Restart In Order To Complete The Process. If You Create An External Module You Will Need To Compile The Source Code In Order To Make It Functional.", MessageType.Info);
} }
private async Task CreateModule() private async Task CreateModule()

View File

@ -11,7 +11,7 @@ namespace [Owner].[Module]s.Modules
Description = "[Module]", Description = "[Module]",
Version = "1.0.0", Version = "1.0.0",
Dependencies = "[Owner].[Module]s.Module.Shared", Dependencies = "[Owner].[Module]s.Module.Shared",
ServerAssemblyName = "[ServerAssemblyName]" ServerManagerType = "[ServerManagerType]"
}; };
} }
} }

View File

@ -6,7 +6,7 @@ using Oqtane.Models;
using [Owner].[Module]s.Models; using [Owner].[Module]s.Models;
using [Owner].[Module]s.Repository; using [Owner].[Module]s.Repository;
namespace [Owner].[Module]s.Modules namespace [Owner].[Module]s.Manager
{ {
public class [Module]Manager : IPortable public class [Module]Manager : IPortable
{ {

View File

@ -11,7 +11,7 @@ namespace [Owner].[Module]s.Modules
Description = "[Module]", Description = "[Module]",
Version = "1.0.0", Version = "1.0.0",
Dependencies = "[Owner].[Module]s.Module.Shared", Dependencies = "[Owner].[Module]s.Module.Shared",
ServerAssemblyName = "[ServerAssemblyName]" ServerManagerType = "[ServerManagerType]"
}; };
} }
} }

View File

@ -6,7 +6,7 @@ using Oqtane.Models;
using [Owner].[Module]s.Models; using [Owner].[Module]s.Models;
using [Owner].[Module]s.Repository; using [Owner].[Module]s.Repository;
namespace [Owner].[Module]s.Modules namespace [Owner].[Module]s.Manager
{ {
public class [Module]Manager : IPortable public class [Module]Manager : IPortable
{ {

View File

@ -7,9 +7,9 @@ namespace Oqtane.Modules.HtmlText
public ModuleDefinition ModuleDefinition => new ModuleDefinition public ModuleDefinition ModuleDefinition => new ModuleDefinition
{ {
Name = "HtmlText", Name = "HtmlText",
Description = "Renders HTML or Text", Description = "Renders HTML or Text Content",
Version = "1.0.0", Version = "1.0.0",
ServerAssemblyName = "Oqtane.Server" ServerManagerType = "Oqtane.Modules.HtmlText.Manager.HtmlTextManager, Oqtane.Server"
}; };
} }
} }

View File

@ -32,7 +32,7 @@
actions = new List<ActionViewModel>(); actions = new List<ActionViewModel>();
actions.Add(new ActionViewModel { Action = "settings", Name = "Manage Settings" }); actions.Add(new ActionViewModel { Action = "settings", Name = "Manage Settings" });
if (ModuleState.ModuleDefinition != null && ModuleState.ModuleDefinition.ServerAssemblyName != "") if (ModuleState.ModuleDefinition != null && ModuleState.ModuleDefinition.ServerManagerType != "")
{ {
actions.Add(new ActionViewModel { Action = "import", Name = "Import Content" }); actions.Add(new ActionViewModel { Action = "import", Name = "Import Content" });
actions.Add(new ActionViewModel { Action = "export", Name = "Export Content" }); actions.Add(new ActionViewModel { Action = "export", Name = "Export Content" });

View File

@ -104,13 +104,14 @@ namespace Oqtane.Controllers
ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionId == id).FirstOrDefault(); ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionId == id).FirstOrDefault();
if (moduledefinition != null) if (moduledefinition != null)
{ {
if (!string.IsNullOrEmpty(moduledefinition.ServerAssemblyName)) // server assembly name should follow client naming convention
{ string assemblyname = Utilities.GetAssemblyName(moduledefinition.ModuleDefinitionName).Replace(".Client",".Server");
string uninstallScript = ""; string uninstallScript = "";
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(a => a.GetName().Name == moduledefinition.ServerAssemblyName); Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(a => a.GetName().Name == assemblyname);
if (assembly != null) if (assembly != null)
{ {
Stream resourceStream = assembly.GetManifestResourceStream(moduledefinition.ServerAssemblyName + ".Scripts.Uninstall.sql"); Stream resourceStream = assembly.GetManifestResourceStream(assemblyname + ".Scripts.Uninstall.sql");
if (resourceStream != null) if (resourceStream != null)
{ {
using (var reader = new StreamReader(resourceStream)) using (var reader = new StreamReader(resourceStream))
@ -126,30 +127,30 @@ namespace Oqtane.Controllers
if (!string.IsNullOrEmpty(uninstallScript)) if (!string.IsNullOrEmpty(uninstallScript))
{ {
_sql.ExecuteScript(tenant, uninstallScript); _sql.ExecuteScript(tenant, uninstallScript);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Uninstall Script Executed For {ServerAssemblyName}", moduledefinition.ServerAssemblyName); _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Uninstall Script Executed For {AssemblyName}", assemblyname);
} }
// clean up module schema versions // clean up module schema versions
_sql.ExecuteNonQuery(tenant, "DELETE FROM [dbo].[SchemaVersions] WHERE ScriptName LIKE '" + moduledefinition.ServerAssemblyName + "%'"); _sql.ExecuteNonQuery(tenant, "DELETE FROM [dbo].[SchemaVersions] WHERE ScriptName LIKE '" + assemblyname + "%'");
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Schema Versions Removed For {ServerAssemblyName}", moduledefinition.ServerAssemblyName); _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Schema Versions Removed For {AssemblyName}", assemblyname);
}
} }
string moduledefinitionname = moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(",")); // format root assembly name
assemblyname = assemblyname.Replace(".Server", "");
// clean up module static resource folder // clean up module static resource folder
string folder = Path.Combine(_environment.WebRootPath, "Modules\\" + moduledefinitionname); string folder = Path.Combine(_environment.WebRootPath, "Modules\\" + assemblyname);
if (Directory.Exists(folder)) if (Directory.Exists(folder))
{ {
Directory.Delete(folder, true); Directory.Delete(folder, true);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Static Resources Removed For {ModuleDefinitionName}", moduledefinitionname); _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Static Resources Removed For {AssemblynName}", assemblyname);
} }
// remove module assembly from /bin // remove module assembly from /bin
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
foreach (string file in Directory.EnumerateFiles(binfolder, moduledefinitionname + "*.*")) foreach (string file in Directory.EnumerateFiles(binfolder, assemblyname + "*.*"))
{ {
System.IO.File.Delete(file); System.IO.File.Delete(file);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Assemblies Removed For {ModuleDefinitionName}", moduledefinitionname); _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Assembly Removed {Filename}", file);
} }
// remove module definition // remove module definition
@ -194,13 +195,13 @@ namespace Oqtane.Controllers
{ {
rootPath = rootFolder.FullName + "\\"; rootPath = rootFolder.FullName + "\\";
moduleDefinition.ModuleDefinitionName = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Modules, Oqtane.Client"; moduleDefinition.ModuleDefinitionName = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Modules, Oqtane.Client";
moduleDefinition.ServerAssemblyName = "Oqtane.Server"; moduleDefinition.ServerManagerType = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Manager." + moduleDefinition.Name + "Manager, Oqtane.Server";
} }
else else
{ {
rootPath = rootFolder.Parent.FullName + "\\" + moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module\\"; rootPath = rootFolder.Parent.FullName + "\\" + moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module\\";
moduleDefinition.ModuleDefinitionName = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Modules, " + moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module.Client"; moduleDefinition.ModuleDefinitionName = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Modules, " + moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module.Client";
moduleDefinition.ServerAssemblyName = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module.Server"; moduleDefinition.ServerManagerType = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Manager." + moduleDefinition.Name + "Manager, " + moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module.Server";
} }
ProcessTemplatesRecursively(new DirectoryInfo(templatePath), rootPath, rootFolder.Name, templatePath, moduleDefinition); ProcessTemplatesRecursively(new DirectoryInfo(templatePath), rootPath, rootFolder.Name, templatePath, moduleDefinition);
@ -241,7 +242,7 @@ namespace Oqtane.Controllers
text = text.Replace("[Description]", moduleDefinition.Description); text = text.Replace("[Description]", moduleDefinition.Description);
text = text.Replace("[RootPath]", rootPath); text = text.Replace("[RootPath]", rootPath);
text = text.Replace("[RootFolder]", rootFolder); text = text.Replace("[RootFolder]", rootFolder);
text = text.Replace("[ServerAssemblyName]", moduleDefinition.ServerAssemblyName); text = text.Replace("[ServerManagerType]", moduleDefinition.ServerManagerType);
text = text.Replace("[Folder]", folderPath); text = text.Replace("[Folder]", folderPath);
text = text.Replace("[File]", Path.GetFileName(filePath)); text = text.Replace("[File]", Path.GetFileName(filePath));
text = text.Replace("[FrameworkVersion]", Constants.Version); text = text.Replace("[FrameworkVersion]", Constants.Version);

View File

@ -83,23 +83,15 @@ namespace Oqtane.Repository
modulecontent.Version = moduledefinition.Version; modulecontent.Version = moduledefinition.Version;
modulecontent.Content = ""; modulecontent.Content = "";
if (moduledefinition.ServerAssemblyName != "") if (moduledefinition.ServerManagerType != "")
{ {
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies() Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
.Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault(); if (moduletype != null && moduletype.GetInterface("IPortable") != null)
if (assembly != null)
{
Type moduletype = assembly.GetTypes()
.Where(item => item.Namespace != null)
.Where(item => item.Namespace.StartsWith(moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(","))))
.Where(item => item.GetInterfaces().Contains(typeof(IPortable))).FirstOrDefault();
if (moduletype != null)
{ {
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype); var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
modulecontent.Content = ((IPortable)moduleobject).ExportModule(module); modulecontent.Content = ((IPortable)moduleobject).ExportModule(module);
} }
} }
}
content = JsonSerializer.Serialize(modulecontent); content = JsonSerializer.Serialize(modulecontent);
} }
} }
@ -126,17 +118,10 @@ namespace Oqtane.Repository
ModuleContent modulecontent = JsonSerializer.Deserialize<ModuleContent>(content); ModuleContent modulecontent = JsonSerializer.Deserialize<ModuleContent>(content);
if (modulecontent.ModuleDefinitionName == moduledefinition.ModuleDefinitionName) if (modulecontent.ModuleDefinitionName == moduledefinition.ModuleDefinitionName)
{ {
if (moduledefinition.ServerAssemblyName != "") if (moduledefinition.ServerManagerType != "")
{ {
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies() Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
.Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault(); if (moduletype != null && moduletype.GetInterface("IPortable") != null)
if (assembly != null)
{
Type moduletype = assembly.GetTypes()
.Where(item => item.Namespace != null)
.Where(item => item.Namespace.StartsWith(moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(","))))
.Where(item => item.GetInterfaces().Contains(typeof(IPortable))).FirstOrDefault();
if (moduletype != null)
{ {
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype); var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
((IPortable)moduleobject).ImportModule(module, modulecontent.Content, modulecontent.Version); ((IPortable)moduleobject).ImportModule(module, modulecontent.Content, modulecontent.Version);
@ -147,7 +132,6 @@ namespace Oqtane.Repository
} }
} }
} }
}
catch catch
{ {
// error occurred during import // error occurred during import

View File

@ -670,23 +670,15 @@ namespace Oqtane.Repository
}; };
module = _moduleRepository.AddModule(module); module = _moduleRepository.AddModule(module);
if (pagetemplatemodule.Content != "" && moduledefinition.ServerAssemblyName != "") if (pagetemplatemodule.Content != "" && moduledefinition.ServerManagerType!= "")
{ {
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies() Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
.Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault(); if (moduletype != null && moduletype.GetInterface("IPortable") != null)
if (assembly != null)
{
Type moduletype = assembly.GetTypes()
.Where(item => item.Namespace != null)
.Where(item => item.Namespace.StartsWith(moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(","))))
.Where(item => item.GetInterfaces().Contains(typeof(IPortable))).FirstOrDefault();
if (moduletype != null)
{ {
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype); var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
((IPortable) moduleobject).ImportModule(module, pagetemplatemodule.Content, moduledefinition.Version); ((IPortable) moduleobject).ImportModule(module, pagetemplatemodule.Content, moduledefinition.Version);
} }
} }
}
PageModule pagemodule = new PageModule PageModule pagemodule = new PageModule
{ {

View File

@ -17,7 +17,7 @@ namespace Oqtane.Models
License = ""; License = "";
Dependencies = ""; Dependencies = "";
PermissionNames = ""; PermissionNames = "";
ServerAssemblyName = ""; ServerManagerType = "";
ControlTypeRoutes = ""; ControlTypeRoutes = "";
Template = ""; Template = "";
} }
@ -53,7 +53,7 @@ namespace Oqtane.Models
[NotMapped] [NotMapped]
public string PermissionNames { get; set; } public string PermissionNames { get; set; }
[NotMapped] [NotMapped]
public string ServerAssemblyName { get; set; } public string ServerManagerType { get; set; }
[NotMapped] [NotMapped]
public string ControlTypeRoutes { get; set; } public string ControlTypeRoutes { get; set; }
[NotMapped] [NotMapped]

View File

@ -74,6 +74,19 @@ namespace Oqtane.Shared
} }
} }
public static string GetAssemblyName(string fullyqualifiedtypename)
{
fullyqualifiedtypename = GetFullTypeName(fullyqualifiedtypename);
if (fullyqualifiedtypename.Contains(","))
{
return fullyqualifiedtypename.Substring(fullyqualifiedtypename.IndexOf(",") + 1).Trim();
}
else
{
return "";
}
}
public static string GetTypeNameLastSegment(string typename, int segment) public static string GetTypeNameLastSegment(string typename, int segment)
{ {
if (typename.Contains(",")) if (typename.Contains(","))