fixed issues with client-side Blazor

This commit is contained in:
Shaun Walker
2020-03-19 15:03:11 -04:00
parent b793c56163
commit 7da2824e50
15 changed files with 73 additions and 37 deletions

View File

@ -81,8 +81,7 @@
private async Task Login()
{
var authstateprovider = (IdentityAuthenticationStateProvider)ServiceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
if (authstateprovider == null)
if (PageState.Runtime == Runtime.Server)
{
// server-side Blazor
User user = new User();
@ -116,6 +115,7 @@
if (user.IsAuthenticated)
{
await logger.LogInformation("Login Successful For Username {Username}", _username);
var authstateprovider = (IdentityAuthenticationStateProvider)ServiceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
authstateprovider.NotifyAuthenticationChanged();
NavigationManager.NavigateTo(NavigateUrl(_returnUrl, "reload"));
}

View File

@ -10,7 +10,7 @@
</RestoreAdditionalProjectSources>
<LangVersion>7.3</LangVersion>
<RazorLangVersion>3.0</RazorLangVersion>
<Configurations>Debug;Release;Wasm</Configurations>
<Configurations>Debug;Release;WebAssembly</Configurations>
<Version>0.0.9</Version>
<Product>Oqtane</Product>
<Authors>Shaun Walker</Authors>
@ -24,7 +24,7 @@
<RootNamespace>Oqtane</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Wasm|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='WebAssembly|AnyCPU'">
<DefineConstants>TRACE;WASM</DefineConstants>
</PropertyGroup>

View File

@ -1,4 +1,7 @@
namespace Oqtane
// DO NOT REMOVE - needed for client-side Blazor
using Microsoft.AspNetCore.Blazor.Hosting;
namespace Oqtane.Client
{
public class Program
{

View File

@ -1,4 +1,5 @@
using Oqtane.Models;
using Oqtane.UI;
using System.Collections.Generic;
using System.Threading.Tasks;
@ -11,6 +12,6 @@ namespace Oqtane.Services
Task UpdateModuleDefinitionAsync(ModuleDefinition moduleDefinition);
Task InstallModuleDefinitionsAsync();
Task DeleteModuleDefinitionAsync(int moduleDefinitionId, int siteId);
Task LoadModuleDefinitionsAsync(int siteId);
Task LoadModuleDefinitionsAsync(int siteId, Runtime runtime);
}
}

View File

@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Components;
using System;
using System.Reflection;
using Oqtane.Shared;
using Oqtane.Providers;
using Oqtane.UI;
namespace Oqtane.Services
{
@ -16,14 +16,12 @@ 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, IServiceProvider serviceProvider)
public ModuleDefinitionService(HttpClient http, SiteState siteState, NavigationManager navigationManager)
{
_http = http;
_siteState = siteState;
_navigationManager = navigationManager;
_serviceProvider = serviceProvider;
}
private string Apiurl
@ -57,14 +55,13 @@ namespace Oqtane.Services
await _http.DeleteAsync(Apiurl + "/" + moduleDefinitionId.ToString() + "?siteid=" + siteId.ToString());
}
public async Task LoadModuleDefinitionsAsync(int siteId)
public async Task LoadModuleDefinitionsAsync(int siteId, Runtime runtime)
{
// get list of modules from the server
List<ModuleDefinition> moduledefinitions = await GetModuleDefinitionsAsync(siteId);
// download assemblies to browser when running client-side Blazor
var authstateprovider = (IdentityAuthenticationStateProvider)_serviceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
if (authstateprovider != null)
if (runtime == Runtime.WebAssembly)
{
// 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();

View File

@ -33,8 +33,7 @@
{
await UserService.LogoutUserAsync(PageState.User);
var authstateprovider = (IdentityAuthenticationStateProvider)ServiceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
if (authstateprovider == null)
if (PageState.Runtime == Runtime.Server)
{
// server-side Blazor
var interop = new Interop(jsRuntime);
@ -45,6 +44,7 @@
else
{
// client-side Blazor
var authstateprovider = (IdentityAuthenticationStateProvider)ServiceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
authstateprovider.NotifyAuthenticationChanged();
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "reload"));
}

View File

@ -18,5 +18,6 @@ namespace Oqtane.UI
public string Action { get; set; }
public bool EditMode { get; set; }
public DateTime LastSyncDate { get; set; }
public Runtime Runtime { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace Oqtane.UI
{
public enum Runtime
{
Server,
WebAssembly
}
}

View File

@ -13,6 +13,7 @@
@inject ILogService LogService
@using System.Diagnostics.CodeAnalysis
@using Oqtane.Enums
@using System.Runtime.InteropServices
@implements IHandleAfterRender
@DynamicComponent
@ -81,6 +82,7 @@
bool editmode = false;
Reload reload = Reload.None;
DateTime lastsyncdate = DateTime.UtcNow;
Runtime runtime = GetRuntime();
// get Url path and querystring ( and remove anchors )
string path = new Uri(_absoluteUri).PathAndQuery.Substring(1);
@ -162,7 +164,7 @@
if (PageState == null || reload >= Reload.Site)
{
await ModuleDefinitionService.LoadModuleDefinitionsAsync(site.SiteId);
await ModuleDefinitionService.LoadModuleDefinitionsAsync(site.SiteId, runtime);
pages = await PageService.GetPagesAsync(site.SiteId);
}
else
@ -248,7 +250,8 @@
Uri = new Uri(_absoluteUri, UriKind.Absolute),
QueryString = querystring,
ModuleId = moduleid,
Action = action
Action = action,
Runtime = runtime
};
if (PageState != null && (PageState.ModuleId != _pagestate.ModuleId || PageState.Action != _pagestate.Action))
@ -458,4 +461,15 @@
return modules;
}
private Runtime GetRuntime()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("WEBASSEMBLY")))
{
return Runtime.WebAssembly;
}
else
{
return Runtime.Server;
}
}
}