Performance improvements, refactoring of multi-tenant support, split Alias and Tenant entities for cleaner separation of concerns, create an additional site during installation for demonstratng multitenancy
This commit is contained in:
53
Oqtane.Client/Services/AliasService.cs
Normal file
53
Oqtane.Client/Services/AliasService.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using Oqtane.Models;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class AliasService : ServiceBase, IAliasService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly IUriHelper urihelper;
|
||||
|
||||
public AliasService(HttpClient http, IUriHelper urihelper)
|
||||
{
|
||||
this.http = http;
|
||||
this.urihelper = urihelper;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(urihelper.GetAbsoluteUri(), "Alias"); }
|
||||
}
|
||||
|
||||
public async Task<List<Alias>> GetAliasesAsync()
|
||||
{
|
||||
List<Alias> aliases = await http.GetJsonAsync<List<Alias>>(apiurl);
|
||||
return aliases.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
public async Task<Alias> GetAliasAsync(int AliasId)
|
||||
{
|
||||
List<Alias> aliases = await http.GetJsonAsync<List<Alias>>(apiurl);
|
||||
return aliases.Where(item => item.AliasId == AliasId).FirstOrDefault();
|
||||
}
|
||||
|
||||
public async Task AddAliasAsync(Alias alias)
|
||||
{
|
||||
await http.PostJsonAsync(apiurl, alias);
|
||||
}
|
||||
|
||||
public async Task UpdateAliasAsync(Alias alias)
|
||||
{
|
||||
await http.PutJsonAsync(apiurl + "/" + alias.AliasId.ToString(), alias);
|
||||
}
|
||||
public async Task DeleteAliasAsync(int AliasId)
|
||||
{
|
||||
await http.DeleteAsync(apiurl + "/" + AliasId.ToString());
|
||||
}
|
||||
}
|
||||
}
|
19
Oqtane.Client/Services/IAliasService.cs
Normal file
19
Oqtane.Client/Services/IAliasService.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public interface IAliasService
|
||||
{
|
||||
Task<List<Alias>> GetAliasesAsync();
|
||||
|
||||
Task<Alias> GetAliasAsync(int AliasId);
|
||||
|
||||
Task AddAliasAsync(Alias alias);
|
||||
|
||||
Task UpdateAliasAsync(Alias alias);
|
||||
|
||||
Task DeleteAliasAsync(int AliasId);
|
||||
}
|
||||
}
|
@ -6,54 +6,56 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class ModuleDefinitionService : ServiceBase, IModuleDefinitionService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly string apiurl;
|
||||
private readonly SiteState sitestate;
|
||||
|
||||
private List<ModuleDefinition> moduledefinitions;
|
||||
|
||||
public ModuleDefinitionService(HttpClient http, IUriHelper urihelper)
|
||||
public ModuleDefinitionService(HttpClient http, SiteState sitestate)
|
||||
{
|
||||
this.http = http;
|
||||
apiurl = CreateApiUrl(urihelper.GetAbsoluteUri(), "ModuleDefinition");
|
||||
this.sitestate = sitestate;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, "ModuleDefinition"); }
|
||||
}
|
||||
|
||||
public async Task<List<ModuleDefinition>> GetModuleDefinitionsAsync()
|
||||
{
|
||||
if (moduledefinitions == null)
|
||||
List<ModuleDefinition> moduledefinitions = await http.GetJsonAsync<List<ModuleDefinition>>(apiurl);
|
||||
|
||||
// get list of loaded assemblies
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
|
||||
foreach (ModuleDefinition moduledefinition in moduledefinitions)
|
||||
{
|
||||
moduledefinitions = await http.GetJsonAsync<List<ModuleDefinition>>(apiurl);
|
||||
|
||||
// get list of loaded assemblies
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
|
||||
foreach (ModuleDefinition moduledefinition in moduledefinitions)
|
||||
if (moduledefinition.Dependencies != "")
|
||||
{
|
||||
if (moduledefinition.Dependencies != "")
|
||||
foreach (string dependency in moduledefinition.Dependencies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
foreach (string dependency in moduledefinition.Dependencies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
string assemblyname = dependency.Replace(".dll", "");
|
||||
if (assemblies.Where(item => item.FullName.StartsWith(assemblyname + ",")).FirstOrDefault() == null)
|
||||
{
|
||||
string assemblyname = dependency.Replace(".dll", "");
|
||||
if (assemblies.Where(item => item.FullName.StartsWith(assemblyname + ",")).FirstOrDefault() == null)
|
||||
{
|
||||
// download assembly from server and load
|
||||
var bytes = await http.GetByteArrayAsync("_framework/_bin/" + assemblyname + ".dll");
|
||||
Assembly.Load(bytes);
|
||||
}
|
||||
// download assembly from server and load
|
||||
var bytes = await http.GetByteArrayAsync("_framework/_bin/" + assemblyname + ".dll");
|
||||
Assembly.Load(bytes);
|
||||
}
|
||||
}
|
||||
if (assemblies.Where(item => item.FullName.StartsWith(moduledefinition.AssemblyName + ",")).FirstOrDefault() == null)
|
||||
{
|
||||
// download assembly from server and load
|
||||
var bytes = await http.GetByteArrayAsync("_framework/_bin/" + moduledefinition.AssemblyName + ".dll");
|
||||
Assembly.Load(bytes);
|
||||
}
|
||||
}
|
||||
if (assemblies.Where(item => item.FullName.StartsWith(moduledefinition.AssemblyName + ",")).FirstOrDefault() == null)
|
||||
{
|
||||
// download assembly from server and load
|
||||
var bytes = await http.GetByteArrayAsync("_framework/_bin/" + moduledefinition.AssemblyName + ".dll");
|
||||
Assembly.Load(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
return moduledefinitions.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,24 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class ModuleService : ServiceBase, IModuleService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly string apiurl;
|
||||
private readonly SiteState sitestate;
|
||||
|
||||
public ModuleService(HttpClient http, IUriHelper urihelper)
|
||||
public ModuleService(HttpClient http, SiteState sitestate)
|
||||
{
|
||||
this.http = http;
|
||||
apiurl = CreateApiUrl(urihelper.GetAbsoluteUri(), "Module");
|
||||
this.sitestate = sitestate;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, "Module"); }
|
||||
}
|
||||
|
||||
public async Task<List<Module>> GetModulesAsync(int PageId)
|
||||
|
@ -4,18 +4,24 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class PageModuleService : ServiceBase, IPageModuleService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly string apiurl;
|
||||
private readonly SiteState sitestate;
|
||||
|
||||
public PageModuleService(HttpClient http, IUriHelper urihelper)
|
||||
public PageModuleService(HttpClient http, SiteState sitestate)
|
||||
{
|
||||
this.http = http;
|
||||
apiurl = CreateApiUrl(urihelper.GetAbsoluteUri(), "PageModule");
|
||||
this.sitestate = sitestate;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, "PageModule"); }
|
||||
}
|
||||
|
||||
public async Task<List<PageModule>> GetPageModulesAsync()
|
||||
|
@ -4,18 +4,24 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class PageService : ServiceBase, IPageService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly string apiurl;
|
||||
private readonly SiteState sitestate;
|
||||
|
||||
public PageService(HttpClient http, IUriHelper urihelper)
|
||||
public PageService(HttpClient http, SiteState sitestate)
|
||||
{
|
||||
this.http = http;
|
||||
apiurl = CreateApiUrl(urihelper.GetAbsoluteUri(), "Page");
|
||||
this.sitestate = sitestate;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, "Page"); }
|
||||
}
|
||||
|
||||
public async Task<List<Page>> GetPagesAsync(int SiteId)
|
||||
|
@ -1,20 +1,24 @@
|
||||
using System;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class ServiceBase
|
||||
{
|
||||
// method for alias agnostic api call
|
||||
public string CreateApiUrl(string absoluteUri, string serviceName)
|
||||
{
|
||||
Uri uri = new Uri(absoluteUri);
|
||||
string apiurl = uri.Scheme + "://" + uri.Authority + "/";
|
||||
string alias = Utilities.GetAlias(absoluteUri);
|
||||
if (alias != "")
|
||||
{
|
||||
apiurl += alias;
|
||||
}
|
||||
else
|
||||
string apiurl = uri.Scheme + "://" + uri.Authority + "/~/api/" + serviceName;
|
||||
return apiurl;
|
||||
}
|
||||
|
||||
// method for alias specific api call
|
||||
public string CreateApiUrl(Alias alias, string serviceName)
|
||||
{
|
||||
string apiurl = alias.Url + "/";
|
||||
if (alias.Path == "")
|
||||
{
|
||||
apiurl += "~/";
|
||||
}
|
||||
|
@ -4,18 +4,24 @@ using System.Net.Http;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class SiteService : ServiceBase, ISiteService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly string apiurl;
|
||||
private readonly SiteState sitestate;
|
||||
|
||||
public SiteService(HttpClient http, IUriHelper urihelper)
|
||||
public SiteService(HttpClient http, SiteState sitestate)
|
||||
{
|
||||
this.http = http;
|
||||
apiurl = CreateApiUrl(urihelper.GetAbsoluteUri(), "Site");
|
||||
this.sitestate = sitestate;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, "Site"); }
|
||||
}
|
||||
|
||||
public async Task<List<Site>> GetSitesAsync()
|
||||
|
@ -2,18 +2,24 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class TenantService : ServiceBase, ITenantService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly string apiurl;
|
||||
private readonly SiteState sitestate;
|
||||
|
||||
public TenantService(HttpClient http, IUriHelper urihelper)
|
||||
public TenantService(HttpClient http, SiteState sitestate)
|
||||
{
|
||||
this.http = http;
|
||||
apiurl = CreateApiUrl(urihelper.GetAbsoluteUri(), "Tenant");
|
||||
this.sitestate = sitestate;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, "Tenant"); }
|
||||
}
|
||||
|
||||
public async Task<Tenant> GetTenantAsync()
|
||||
|
@ -13,48 +13,49 @@ namespace Oqtane.Services
|
||||
public class ThemeService : ServiceBase, IThemeService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly string apiurl;
|
||||
private readonly SiteState sitestate;
|
||||
|
||||
private List<Theme> themes;
|
||||
|
||||
public ThemeService(HttpClient http, IUriHelper urihelper)
|
||||
public ThemeService(HttpClient http, SiteState sitestate)
|
||||
{
|
||||
this.http = http;
|
||||
apiurl = CreateApiUrl(urihelper.GetAbsoluteUri(), "Theme");
|
||||
this.sitestate = sitestate;
|
||||
}
|
||||
//TODO: Implement Caching or otherwise on this, and other calls within this class
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, "Theme"); }
|
||||
}
|
||||
|
||||
public async Task<List<Theme>> GetThemesAsync()
|
||||
{
|
||||
if (themes == null)
|
||||
List<Theme> themes = await http.GetJsonAsync<List<Theme>>(apiurl);
|
||||
|
||||
// get list of loaded assemblies
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
|
||||
foreach (Theme theme in themes)
|
||||
{
|
||||
themes = await http.GetJsonAsync<List<Theme>>(apiurl);
|
||||
|
||||
// get list of loaded assemblies
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
|
||||
foreach (Theme theme in themes)
|
||||
if (theme.Dependencies != "")
|
||||
{
|
||||
if (theme.Dependencies != "")
|
||||
foreach (string dependency in theme.Dependencies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
foreach (string dependency in theme.Dependencies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
string assemblyname = dependency.Replace(".dll", "");
|
||||
if (assemblies.Where(item => item.FullName.StartsWith(assemblyname + ",")).FirstOrDefault() == null)
|
||||
{
|
||||
string assemblyname = dependency.Replace(".dll", "");
|
||||
if (assemblies.Where(item => item.FullName.StartsWith(assemblyname + ",")).FirstOrDefault() == null)
|
||||
{
|
||||
// download assembly from server and load
|
||||
var bytes = await http.GetByteArrayAsync("_framework/_bin/" + assemblyname + ".dll");
|
||||
Assembly.Load(bytes);
|
||||
}
|
||||
// download assembly from server and load
|
||||
var bytes = await http.GetByteArrayAsync("_framework/_bin/" + assemblyname + ".dll");
|
||||
Assembly.Load(bytes);
|
||||
}
|
||||
}
|
||||
if (assemblies.Where(item => item.FullName.StartsWith(theme.AssemblyName + ",")).FirstOrDefault() == null)
|
||||
{
|
||||
// download assembly from server and load
|
||||
var bytes = await http.GetByteArrayAsync("_framework/_bin/" + theme.AssemblyName + ".dll");
|
||||
Assembly.Load(bytes);
|
||||
}
|
||||
}
|
||||
if (assemblies.Where(item => item.FullName.StartsWith(theme.AssemblyName + ",")).FirstOrDefault() == null)
|
||||
{
|
||||
// download assembly from server and load
|
||||
var bytes = await http.GetByteArrayAsync("_framework/_bin/" + theme.AssemblyName + ".dll");
|
||||
Assembly.Load(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
return themes.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
|
@ -12,12 +12,17 @@ namespace Oqtane.Services
|
||||
public class UserService : ServiceBase, IUserService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly string apiurl;
|
||||
private readonly SiteState sitestate;
|
||||
|
||||
public UserService(HttpClient http, IUriHelper urihelper)
|
||||
public UserService(HttpClient http, SiteState sitestate)
|
||||
{
|
||||
this.http = http;
|
||||
apiurl = CreateApiUrl(urihelper.GetAbsoluteUri(), "User");
|
||||
this.sitestate = sitestate;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, "User"); }
|
||||
}
|
||||
|
||||
public async Task<List<User>> GetUsersAsync()
|
||||
|
Reference in New Issue
Block a user