Merge branch 'oqtane:dev' into FileExtentions
This commit is contained in:
commit
9cc7ba1d82
|
@ -30,11 +30,12 @@ namespace Oqtane.Controllers
|
||||||
private readonly IMemoryCache _cache;
|
private readonly IMemoryCache _cache;
|
||||||
private readonly IHttpContextAccessor _accessor;
|
private readonly IHttpContextAccessor _accessor;
|
||||||
private readonly IAliasRepository _aliases;
|
private readonly IAliasRepository _aliases;
|
||||||
|
private readonly ISiteRepository _sites;
|
||||||
private readonly ILogger<InstallationController> _filelogger;
|
private readonly ILogger<InstallationController> _filelogger;
|
||||||
private readonly ITenantManager _tenantManager;
|
private readonly ITenantManager _tenantManager;
|
||||||
private readonly IServerStateManager _serverState;
|
private readonly IServerStateManager _serverState;
|
||||||
|
|
||||||
public InstallationController(IConfigManager configManager, IInstallationManager installationManager, IDatabaseManager databaseManager, ILocalizationManager localizationManager, IMemoryCache cache, IHttpContextAccessor accessor, IAliasRepository aliases, ILogger<InstallationController> filelogger, ITenantManager tenantManager, IServerStateManager serverState)
|
public InstallationController(IConfigManager configManager, IInstallationManager installationManager, IDatabaseManager databaseManager, ILocalizationManager localizationManager, IMemoryCache cache, IHttpContextAccessor accessor, IAliasRepository aliases, ISiteRepository sites, ILogger<InstallationController> filelogger, ITenantManager tenantManager, IServerStateManager serverState)
|
||||||
{
|
{
|
||||||
_configManager = configManager;
|
_configManager = configManager;
|
||||||
_installationManager = installationManager;
|
_installationManager = installationManager;
|
||||||
|
@ -43,6 +44,7 @@ namespace Oqtane.Controllers
|
||||||
_cache = cache;
|
_cache = cache;
|
||||||
_accessor = accessor;
|
_accessor = accessor;
|
||||||
_aliases = aliases;
|
_aliases = aliases;
|
||||||
|
_sites = sites;
|
||||||
_filelogger = filelogger;
|
_filelogger = filelogger;
|
||||||
_tenantManager = tenantManager;
|
_tenantManager = tenantManager;
|
||||||
_serverState = serverState;
|
_serverState = serverState;
|
||||||
|
@ -108,21 +110,18 @@ namespace Oqtane.Controllers
|
||||||
return GetAssemblyList().Select(item => item.HashedName).ToList();
|
return GetAssemblyList().Select(item => item.HashedName).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET api/<controller>/load?list=x,y
|
|
||||||
[HttpGet("load")]
|
|
||||||
public IActionResult Load(string list = "*")
|
|
||||||
{
|
|
||||||
return File(GetAssemblies(list), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ClientAssembly> GetAssemblyList()
|
private List<ClientAssembly> GetAssemblyList()
|
||||||
{
|
{
|
||||||
var siteKey = _tenantManager.GetAlias().SiteKey;
|
var alias = _tenantManager.GetAlias();
|
||||||
|
|
||||||
return _cache.GetOrCreate($"assemblieslist:{siteKey}", entry =>
|
return _cache.GetOrCreate($"assemblieslist:{alias.SiteKey}", entry =>
|
||||||
|
{
|
||||||
|
var assemblyList = new List<ClientAssembly>();
|
||||||
|
|
||||||
|
var site = _sites.GetSite(alias.SiteId);
|
||||||
|
if (site != null && site.Runtime == "WebAssembly")
|
||||||
{
|
{
|
||||||
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
var assemblyList = new List<ClientAssembly>();
|
|
||||||
|
|
||||||
// testmode setting is used for validating that the API is downloading the appropriate assemblies to the client
|
// testmode setting is used for validating that the API is downloading the appropriate assemblies to the client
|
||||||
bool hashfilename = true;
|
bool hashfilename = true;
|
||||||
|
@ -132,7 +131,7 @@ namespace Oqtane.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// get site assemblies which should be downloaded to client
|
// get site assemblies which should be downloaded to client
|
||||||
var assemblies = _serverState.GetServerState(siteKey).Assemblies;
|
var assemblies = _serverState.GetServerState(alias.SiteKey).Assemblies;
|
||||||
|
|
||||||
// populate assembly list
|
// populate assembly list
|
||||||
foreach (var assembly in assemblies)
|
foreach (var assembly in assemblies)
|
||||||
|
@ -170,29 +169,39 @@ namespace Oqtane.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return assemblyList;
|
return assemblyList;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET api/<controller>/load?list=x,y
|
||||||
|
[HttpGet("load")]
|
||||||
|
public IActionResult Load(string list = "*")
|
||||||
|
{
|
||||||
|
return File(GetAssemblies(list), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] GetAssemblies(string list)
|
private byte[] GetAssemblies(string list)
|
||||||
{
|
{
|
||||||
var siteKey = _tenantManager.GetAlias().SiteKey;
|
var alias = _tenantManager.GetAlias();
|
||||||
|
|
||||||
if (list == "*")
|
if (list == "*")
|
||||||
{
|
{
|
||||||
return _cache.GetOrCreate($"assemblies:{siteKey}", entry =>
|
return _cache.GetOrCreate($"assemblies:{alias.SiteKey}", entry =>
|
||||||
{
|
{
|
||||||
return GetZIP(list);
|
return GetZIP(list, alias);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return GetZIP(list);
|
return GetZIP(list, alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] GetZIP(string list)
|
private byte[] GetZIP(string list, Alias alias)
|
||||||
|
{
|
||||||
|
var site = _sites.GetSite(alias.SiteId);
|
||||||
|
if (site != null && site.Runtime == "WebAssembly")
|
||||||
{
|
{
|
||||||
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
|
|
||||||
|
@ -237,6 +246,16 @@ namespace Oqtane.Controllers
|
||||||
return memoryStream.ToArray();
|
return memoryStream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// return empty zip
|
||||||
|
using (var memoryStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Create)) {}
|
||||||
|
return memoryStream.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task RegisterContact(string email)
|
private async Task RegisterContact(string email)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,10 +15,18 @@ namespace Oqtane.Infrastructure.EventSubscribers
|
||||||
|
|
||||||
public void EntityChanged(SyncEvent syncEvent)
|
public void EntityChanged(SyncEvent syncEvent)
|
||||||
{
|
{
|
||||||
|
// when site entities change (ie. site, pages, modules, etc...) a site refresh event is raised and the site cache item needs to be refreshed
|
||||||
if (syncEvent.EntityName == EntityNames.Site && syncEvent.Action == SyncEventActions.Refresh)
|
if (syncEvent.EntityName == EntityNames.Site && syncEvent.Action == SyncEventActions.Refresh)
|
||||||
{
|
{
|
||||||
_cache.Remove($"site:{syncEvent.TenantId}:{syncEvent.EntityId}");
|
_cache.Remove($"site:{syncEvent.TenantId}:{syncEvent.EntityId}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when a site entity is updated the hosting model may have changed, so the client assemblies cache items need to be refreshed
|
||||||
|
if (syncEvent.EntityName == EntityNames.Site && syncEvent.Action == SyncEventActions.Update)
|
||||||
|
{
|
||||||
|
_cache.Remove($"assemblieslist:{syncEvent.TenantId}:{syncEvent.EntityId}");
|
||||||
|
_cache.Remove($"assemblies:{syncEvent.TenantId}:{syncEvent.EntityId}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user