fixes for client-side Blazor

This commit is contained in:
Shaun Walker
2020-03-10 14:44:50 -04:00
parent 155c4e12d9
commit 2436f74830
7 changed files with 56 additions and 54 deletions

View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Components;
using System;
using System.Reflection;
using Oqtane.Shared;
using Oqtane.Providers;
namespace Oqtane.Services
{
@ -15,12 +16,14 @@ namespace Oqtane.Services
private readonly HttpClient _http;
private readonly SiteState _siteState;
private readonly NavigationManager _navigationManager;
private readonly IServiceProvider _serviceProvider;
public ModuleDefinitionService(HttpClient http, SiteState siteState, NavigationManager navigationManager)
public ModuleDefinitionService(HttpClient http, SiteState siteState, NavigationManager navigationManager, IServiceProvider serviceProvider)
{
_http = http;
_siteState = siteState;
_navigationManager = navigationManager;
_serviceProvider = serviceProvider;
}
private string apiurl
@ -56,34 +59,39 @@ namespace Oqtane.Services
public async Task LoadModuleDefinitionsAsync(int SiteId)
{
// get list of modules from the server
List<ModuleDefinition> moduledefinitions = await GetModuleDefinitionsAsync(SiteId);
// get list of loaded assemblies on the client ( in the client-side hosting module the browser client has its own app domain )
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (ModuleDefinition moduledefinition in moduledefinitions)
// download assemblies to browser when running client-side Blazor
var authstateprovider = (IdentityAuthenticationStateProvider)_serviceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
if (authstateprovider != null)
{
// if a module has dependencies, check if they are loaded
if (moduledefinition.Dependencies != "")
// get list of modules from the server
List<ModuleDefinition> moduledefinitions = await GetModuleDefinitionsAsync(SiteId);
// get list of loaded assemblies on the client ( in the client-side hosting module the browser client has its own app domain )
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (ModuleDefinition moduledefinition in moduledefinitions)
{
foreach (string dependency in moduledefinition.Dependencies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
// if a module has dependencies, check if they are loaded
if (moduledefinition.Dependencies != "")
{
string assemblyname = dependency.Replace(".dll", "");
if (assemblies.Where(item => item.FullName.StartsWith(assemblyname + ",")).FirstOrDefault() == null)
foreach (string dependency in moduledefinition.Dependencies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
// download assembly from server and load
var bytes = await _http.GetByteArrayAsync(apiurl + "/load/" + assemblyname + ".dll");
Assembly.Load(bytes);
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(apiurl + "/load/" + assemblyname + ".dll");
Assembly.Load(bytes);
}
}
}
}
// check if the module assembly is loaded
if (assemblies.Where(item => item.FullName.StartsWith(moduledefinition.AssemblyName + ",")).FirstOrDefault() == null)
{
// download assembly from server and load
var bytes = await _http.GetByteArrayAsync(apiurl + "/load/" + moduledefinition.AssemblyName + ".dll");
Assembly.Load(bytes);
// check if the module assembly is loaded
if (assemblies.Where(item => item.FullName.StartsWith(moduledefinition.AssemblyName + ",")).FirstOrDefault() == null)
{
// download assembly from server and load
var bytes = await _http.GetByteArrayAsync(apiurl + "/load/" + moduledefinition.AssemblyName + ".dll");
Assembly.Load(bytes);
}
}
}
}