changed ServerAssemblyName to ServerManagerType to optimize processing
This commit is contained in:
parent
f5e4c1dd29
commit
b9d70dd11a
|
@ -55,7 +55,7 @@
|
|||
|
||||
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()
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace [Owner].[Module]s.Modules
|
|||
Description = "[Module]",
|
||||
Version = "1.0.0",
|
||||
Dependencies = "[Owner].[Module]s.Module.Shared",
|
||||
ServerAssemblyName = "[ServerAssemblyName]"
|
||||
ServerManagerType = "[ServerManagerType]"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ using Oqtane.Models;
|
|||
using [Owner].[Module]s.Models;
|
||||
using [Owner].[Module]s.Repository;
|
||||
|
||||
namespace [Owner].[Module]s.Modules
|
||||
namespace [Owner].[Module]s.Manager
|
||||
{
|
||||
public class [Module]Manager : IPortable
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace [Owner].[Module]s.Modules
|
|||
Description = "[Module]",
|
||||
Version = "1.0.0",
|
||||
Dependencies = "[Owner].[Module]s.Module.Shared",
|
||||
ServerAssemblyName = "[ServerAssemblyName]"
|
||||
ServerManagerType = "[ServerManagerType]"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ using Oqtane.Models;
|
|||
using [Owner].[Module]s.Models;
|
||||
using [Owner].[Module]s.Repository;
|
||||
|
||||
namespace [Owner].[Module]s.Modules
|
||||
namespace [Owner].[Module]s.Manager
|
||||
{
|
||||
public class [Module]Manager : IPortable
|
||||
{
|
||||
|
|
|
@ -7,9 +7,9 @@ namespace Oqtane.Modules.HtmlText
|
|||
public ModuleDefinition ModuleDefinition => new ModuleDefinition
|
||||
{
|
||||
Name = "HtmlText",
|
||||
Description = "Renders HTML or Text",
|
||||
Description = "Renders HTML or Text Content",
|
||||
Version = "1.0.0",
|
||||
ServerAssemblyName = "Oqtane.Server"
|
||||
ServerManagerType = "Oqtane.Modules.HtmlText.Manager.HtmlTextManager, Oqtane.Server"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
actions = new List<ActionViewModel>();
|
||||
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 = "export", Name = "Export Content" });
|
||||
|
|
|
@ -104,13 +104,14 @@ namespace Oqtane.Controllers
|
|||
ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionId == id).FirstOrDefault();
|
||||
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 = "";
|
||||
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)
|
||||
{
|
||||
Stream resourceStream = assembly.GetManifestResourceStream(moduledefinition.ServerAssemblyName + ".Scripts.Uninstall.sql");
|
||||
Stream resourceStream = assembly.GetManifestResourceStream(assemblyname + ".Scripts.Uninstall.sql");
|
||||
if (resourceStream != null)
|
||||
{
|
||||
using (var reader = new StreamReader(resourceStream))
|
||||
|
@ -126,30 +127,30 @@ namespace Oqtane.Controllers
|
|||
if (!string.IsNullOrEmpty(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
|
||||
_sql.ExecuteNonQuery(tenant, "DELETE FROM [dbo].[SchemaVersions] WHERE ScriptName LIKE '" + moduledefinition.ServerAssemblyName + "%'");
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Schema Versions Removed For {ServerAssemblyName}", 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 {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
|
||||
string folder = Path.Combine(_environment.WebRootPath, "Modules\\" + moduledefinitionname);
|
||||
string folder = Path.Combine(_environment.WebRootPath, "Modules\\" + assemblyname);
|
||||
if (Directory.Exists(folder))
|
||||
{
|
||||
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
|
||||
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);
|
||||
_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
|
||||
|
@ -194,13 +195,13 @@ namespace Oqtane.Controllers
|
|||
{
|
||||
rootPath = rootFolder.FullName + "\\";
|
||||
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
|
||||
{
|
||||
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.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);
|
||||
|
@ -241,7 +242,7 @@ namespace Oqtane.Controllers
|
|||
text = text.Replace("[Description]", moduleDefinition.Description);
|
||||
text = text.Replace("[RootPath]", rootPath);
|
||||
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("[File]", Path.GetFileName(filePath));
|
||||
text = text.Replace("[FrameworkVersion]", Constants.Version);
|
||||
|
|
|
@ -83,23 +83,15 @@ namespace Oqtane.Repository
|
|||
modulecontent.Version = moduledefinition.Version;
|
||||
modulecontent.Content = "";
|
||||
|
||||
if (moduledefinition.ServerAssemblyName != "")
|
||||
if (moduledefinition.ServerManagerType != "")
|
||||
{
|
||||
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault();
|
||||
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)
|
||||
Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
|
||||
if (moduletype != null && moduletype.GetInterface("IPortable") != null)
|
||||
{
|
||||
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
|
||||
modulecontent.Content = ((IPortable)moduleobject).ExportModule(module);
|
||||
}
|
||||
}
|
||||
}
|
||||
content = JsonSerializer.Serialize(modulecontent);
|
||||
}
|
||||
}
|
||||
|
@ -126,17 +118,10 @@ namespace Oqtane.Repository
|
|||
ModuleContent modulecontent = JsonSerializer.Deserialize<ModuleContent>(content);
|
||||
if (modulecontent.ModuleDefinitionName == moduledefinition.ModuleDefinitionName)
|
||||
{
|
||||
if (moduledefinition.ServerAssemblyName != "")
|
||||
if (moduledefinition.ServerManagerType != "")
|
||||
{
|
||||
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault();
|
||||
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)
|
||||
Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
|
||||
if (moduletype != null && moduletype.GetInterface("IPortable") != null)
|
||||
{
|
||||
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
|
||||
((IPortable)moduleobject).ImportModule(module, modulecontent.Content, modulecontent.Version);
|
||||
|
@ -147,7 +132,6 @@ namespace Oqtane.Repository
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// error occurred during import
|
||||
|
|
|
@ -670,23 +670,15 @@ namespace Oqtane.Repository
|
|||
};
|
||||
module = _moduleRepository.AddModule(module);
|
||||
|
||||
if (pagetemplatemodule.Content != "" && moduledefinition.ServerAssemblyName != "")
|
||||
if (pagetemplatemodule.Content != "" && moduledefinition.ServerManagerType!= "")
|
||||
{
|
||||
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault();
|
||||
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)
|
||||
Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
|
||||
if (moduletype != null && moduletype.GetInterface("IPortable") != null)
|
||||
{
|
||||
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
|
||||
((IPortable) moduleobject).ImportModule(module, pagetemplatemodule.Content, moduledefinition.Version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PageModule pagemodule = new PageModule
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Oqtane.Models
|
|||
License = "";
|
||||
Dependencies = "";
|
||||
PermissionNames = "";
|
||||
ServerAssemblyName = "";
|
||||
ServerManagerType = "";
|
||||
ControlTypeRoutes = "";
|
||||
Template = "";
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ namespace Oqtane.Models
|
|||
[NotMapped]
|
||||
public string PermissionNames { get; set; }
|
||||
[NotMapped]
|
||||
public string ServerAssemblyName { get; set; }
|
||||
public string ServerManagerType { get; set; }
|
||||
[NotMapped]
|
||||
public string ControlTypeRoutes { get; set; }
|
||||
[NotMapped]
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
if (typename.Contains(","))
|
||||
|
|
Loading…
Reference in New Issue
Block a user