Optimized page reloading
This commit is contained in:
@ -2,6 +2,13 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Oqtane.Shared;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.Reflection;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
@ -9,10 +16,14 @@ namespace Oqtane.Controllers
|
||||
public class ThemeController : Controller
|
||||
{
|
||||
private readonly IThemeRepository Themes;
|
||||
private readonly IHostApplicationLifetime HostApplicationLifetime;
|
||||
private readonly IWebHostEnvironment environment;
|
||||
|
||||
public ThemeController(IThemeRepository Themes)
|
||||
public ThemeController(IThemeRepository Themes, IHostApplicationLifetime HostApplicationLifetime, IWebHostEnvironment environment)
|
||||
{
|
||||
this.Themes = Themes;
|
||||
this.HostApplicationLifetime = HostApplicationLifetime;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
// GET: api/<controller>
|
||||
@ -21,5 +32,42 @@ namespace Oqtane.Controllers
|
||||
{
|
||||
return Themes.GetThemes();
|
||||
}
|
||||
|
||||
[HttpGet("install")]
|
||||
[Authorize(Roles = Constants.HostRole)]
|
||||
public void InstallThemes()
|
||||
{
|
||||
bool install = false;
|
||||
string themefolder = Path.Combine(environment.WebRootPath, "Themes");
|
||||
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
|
||||
// iterate through theme packages
|
||||
foreach (string packagename in Directory.GetFiles(themefolder, "*.nupkg"))
|
||||
{
|
||||
// iterate through files and deploy to appropriate locations
|
||||
using (ZipArchive archive = ZipFile.OpenRead(packagename))
|
||||
{
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
{
|
||||
string filename = Path.GetFileName(entry.FullName);
|
||||
switch (Path.GetExtension(filename))
|
||||
{
|
||||
case ".dll":
|
||||
entry.ExtractToFile(Path.Combine(binfolder, filename));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove theme package
|
||||
System.IO.File.Delete(packagename);
|
||||
install = true;
|
||||
}
|
||||
|
||||
if (install)
|
||||
{
|
||||
// restart application
|
||||
HostApplicationLifetime.StopApplication();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace Oqtane.Repository
|
||||
// iterate through Oqtane theme assemblies
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Theme.")).ToArray();
|
||||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
foreach (Assembly assembly in assemblies)
|
||||
{
|
||||
Themes = LoadThemesFromAssembly(Themes, assembly);
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ CREATE TABLE [dbo].[Role](
|
||||
[Name] [nvarchar](256) NOT NULL,
|
||||
[Description] [nvarchar](50) NOT NULL,
|
||||
[IsAutoAssigned] [bit] NOT NULL,
|
||||
[IsSystem] [bit] NOT NULL,
|
||||
[CreatedBy] [nvarchar](256) NOT NULL,
|
||||
[CreatedOn] [datetime] NOT NULL,
|
||||
[ModifiedBy] [nvarchar](256) NOT NULL,
|
||||
@ -361,23 +362,23 @@ GO
|
||||
|
||||
SET IDENTITY_INSERT [dbo].[Role] ON
|
||||
GO
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (-1, null, N'All Users', N'All Users', 0, '', getdate(), '', getdate())
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [IsSystem], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (-1, null, N'All Users', N'All Users', 0, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (0, null, N'Host Users', N'Host Users', 0, '', getdate(), '', getdate())
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [IsSystem], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (0, null, N'Host Users', N'Host Users', 0, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (1, 1, N'Administrators', N'Site Administrators', 0, '', getdate(), '', getdate())
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [IsSystem], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (1, 1, N'Administrators', N'Site Administrators', 0, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (2, 1, N'Registered Users', N'Registered Users', 1, '', getdate(), '', getdate())
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [IsSystem], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (2, 1, N'Registered Users', N'Registered Users', 1, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (3, 2, N'Administrators', N'Site Administrators', 0, '', getdate(), '', getdate())
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [IsSystem], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (3, 2, N'Administrators', N'Site Administrators', 0, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (4, 2, N'Registered Users', N'Registered Users', 1, '', getdate(), '', getdate())
|
||||
INSERT [dbo].[Role] ([RoleId], [SiteId], [Name], [Description], [IsAutoAssigned], [IsSystem], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (4, 2, N'Registered Users', N'Registered Users', 1, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
SET IDENTITY_INSERT [dbo].[Role] OFF
|
||||
GO
|
||||
|
@ -146,11 +146,11 @@ namespace Oqtane.Server
|
||||
|
||||
// get list of loaded assemblies
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
|
||||
// iterate through Oqtane module assemblies in /bin ( filter is narrow to optimize loading process )
|
||||
string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
DirectoryInfo folder = new DirectoryInfo(path);
|
||||
List<Assembly> moduleassemblies = new List<Assembly>();
|
||||
|
||||
// iterate through Oqtane module assemblies in /bin ( filter is narrow to optimize loading process )
|
||||
foreach (FileInfo file in folder.EnumerateFiles("*.Module.*.dll"))
|
||||
{
|
||||
// check if assembly is already loaded
|
||||
@ -163,6 +163,18 @@ namespace Oqtane.Server
|
||||
}
|
||||
}
|
||||
|
||||
// iterate through Oqtane theme assemblies in /bin ( filter is narrow to optimize loading process )
|
||||
foreach (FileInfo file in folder.EnumerateFiles("*.Theme.*.dll"))
|
||||
{
|
||||
// check if assembly is already loaded
|
||||
Assembly assembly = assemblies.Where(item => item.Location == file.FullName).FirstOrDefault();
|
||||
if (assembly == null)
|
||||
{
|
||||
// load assembly ( as long as dependencies are in /bin they will load as well )
|
||||
assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(file.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
services.AddMvc().AddModuleAssemblies(moduleassemblies).AddNewtonsoftJson();
|
||||
|
||||
// register singleton scoped core services
|
||||
@ -313,11 +325,11 @@ namespace Oqtane.Server
|
||||
|
||||
// get list of loaded assemblies
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
|
||||
// iterate through Oqtane module assemblies in /bin ( filter is narrow to optimize loading process )
|
||||
string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
DirectoryInfo folder = new DirectoryInfo(path);
|
||||
List<Assembly> moduleassemblies = new List<Assembly>();
|
||||
|
||||
// iterate through Oqtane module assemblies in /bin ( filter is narrow to optimize loading process )
|
||||
foreach (FileInfo file in folder.EnumerateFiles("*.Module.*.dll"))
|
||||
{
|
||||
// check if assembly is already loaded
|
||||
@ -330,6 +342,18 @@ namespace Oqtane.Server
|
||||
}
|
||||
}
|
||||
|
||||
// iterate through Oqtane theme assemblies in /bin ( filter is narrow to optimize loading process )
|
||||
foreach (FileInfo file in folder.EnumerateFiles("*.Theme.*.dll"))
|
||||
{
|
||||
// check if assembly is already loaded
|
||||
Assembly assembly = assemblies.Where(item => item.Location == file.FullName).FirstOrDefault();
|
||||
if (assembly == null)
|
||||
{
|
||||
// load assembly ( as long as dependencies are in /bin they will load as well )
|
||||
assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(file.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
services.AddMvc().AddModuleAssemblies(moduleassemblies).AddNewtonsoftJson();
|
||||
|
||||
// register singleton scoped core services
|
||||
@ -399,6 +423,7 @@ namespace Oqtane.Server
|
||||
}
|
||||
|
||||
app.UseClientSideBlazorFiles<Client.Startup>();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
|
Reference in New Issue
Block a user