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;
}
}
}

View File

@ -8,7 +8,7 @@
https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;
</RestoreAdditionalProjectSources>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<Configurations>Debug;Release;Wasm</Configurations>
<Configurations>Debug;Release;WebAssembly</Configurations>
<Version>0.0.9</Version>
<Product>Oqtane</Product>
<Authors>Shaun Walker</Authors>
@ -22,7 +22,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,9 +1,11 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
// DO NOT REMOVE - needed for client-side Blazor
using Microsoft.AspNetCore.Blazor.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore;
// used by client-side Blazor
namespace Oqtane
namespace Oqtane.Server
{
public class Program
{

View File

@ -243,12 +243,14 @@ namespace Oqtane.Repository
_pageTemplates.Add(new PageTemplate { Name = "Login", Parent = "", Path = "login", Icon = "lock-locked", IsNavigation = false, IsPersonalizable = false, EditMode = false,
PagePermissions = _permissionRepository.EncodePermissions(new List<Permission> {
new Permission(PermissionNames.View, Constants.AdminRole, true),
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
}),
PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Login, Oqtane.Client", Title = "User Login", Pane = "Content",
ModulePermissions = _permissionRepository.EncodePermissions( new List<Permission> {
new Permission(PermissionNames.View, Constants.AdminRole, true),
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
}), Content = "" }
}
@ -256,12 +258,14 @@ namespace Oqtane.Repository
_pageTemplates.Add(new PageTemplate { Name = "Register", Parent = "", Path = "register", Icon = "person", IsNavigation = false, IsPersonalizable = false, EditMode = false,
PagePermissions = _permissionRepository.EncodePermissions(new List<Permission> {
new Permission(PermissionNames.View, Constants.AdminRole, true),
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
}),
PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Register, Oqtane.Client", Title = "User Registration", Pane = "Content",
ModulePermissions = _permissionRepository.EncodePermissions( new List<Permission> {
new Permission(PermissionNames.View, Constants.AdminRole, true),
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
}), Content = "" }
}
@ -270,12 +274,14 @@ namespace Oqtane.Repository
_pageTemplates.Add(new PageTemplate { Name = "Reset", Parent = "", Path = "reset", Icon = "person", IsNavigation = false, IsPersonalizable = false, EditMode = false,
PagePermissions = _permissionRepository.EncodePermissions(new List<Permission> {
new Permission(PermissionNames.View, Constants.AdminRole, true),
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
}),
PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Reset, Oqtane.Client", Title = "Password Reset", Pane = "Content",
ModulePermissions = _permissionRepository.EncodePermissions( new List<Permission> {
new Permission(PermissionNames.View, Constants.AdminRole, true),
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
}), Content = "" }
}
@ -283,12 +289,14 @@ namespace Oqtane.Repository
_pageTemplates.Add(new PageTemplate { Name = "Profile", Parent = "", Path = "profile", Icon = "person", IsNavigation = false, IsPersonalizable = false, EditMode = false,
PagePermissions = _permissionRepository.EncodePermissions(new List<Permission> {
new Permission(PermissionNames.View, Constants.AdminRole, true),
new Permission(PermissionNames.View, Constants.RegisteredRole, true),
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
}),
PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.UserProfile, Oqtane.Client", Title = "User Profile", Pane = "Content",
ModulePermissions = _permissionRepository.EncodePermissions( new List<Permission> {
new Permission(PermissionNames.View, Constants.AdminRole, true),
new Permission(PermissionNames.View, Constants.RegisteredRole, true),
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
}), Content = "" }
}

View File

@ -19,7 +19,9 @@ using Oqtane.Infrastructure.Interfaces;
using Oqtane.Repository;
using Oqtane.Security;
using Oqtane.Services;
using Oqtane.Shared; // needed for WASM
// DO NOT REMOVE - needed for client-side Blazor
using Oqtane.Shared;
using Microsoft.AspNetCore.ResponseCompression;
namespace Oqtane
{

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>7.3</LangVersion>
<Configurations>Debug;Release;Wasm</Configurations>
<Configurations>Debug;Release;WebAssembly</Configurations>
<Version>0.0.9</Version>
<Product>Oqtane</Product>
<Authors>Shaun Walker</Authors>
@ -17,7 +17,7 @@
<RootNamespace>Oqtane</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Wasm|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='WebAssembly|AnyCPU'">
<DefineConstants>TRACE;WASM</DefineConstants>
</PropertyGroup>

View File

@ -11,45 +11,45 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Shared", "Oqtane.Sha
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Upgrade", "Oqtane.Upgrade\Oqtane.Upgrade.csproj", "{2E8C6889-37CF-4C8D-88B1-505547F25098}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Oqtane.Test", "Oqtane.Test\Oqtane.Test.csproj", "{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Test", "Oqtane.Test\Oqtane.Test.csproj", "{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Wasm|Any CPU = Wasm|Any CPU
WebAssembly|Any CPU = WebAssembly|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{083BB22D-DF24-43A2-95E5-8F385CCB3318}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{083BB22D-DF24-43A2-95E5-8F385CCB3318}.Debug|Any CPU.Build.0 = Debug|Any CPU
{083BB22D-DF24-43A2-95E5-8F385CCB3318}.Release|Any CPU.ActiveCfg = Release|Any CPU
{083BB22D-DF24-43A2-95E5-8F385CCB3318}.Release|Any CPU.Build.0 = Release|Any CPU
{083BB22D-DF24-43A2-95E5-8F385CCB3318}.Wasm|Any CPU.ActiveCfg = Wasm|Any CPU
{083BB22D-DF24-43A2-95E5-8F385CCB3318}.Wasm|Any CPU.Build.0 = Wasm|Any CPU
{083BB22D-DF24-43A2-95E5-8F385CCB3318}.WebAssembly|Any CPU.ActiveCfg = WebAssembly|Any CPU
{083BB22D-DF24-43A2-95E5-8F385CCB3318}.WebAssembly|Any CPU.Build.0 = WebAssembly|Any CPU
{FD15B24A-7F6A-4830-9CA2-9C621771C330}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD15B24A-7F6A-4830-9CA2-9C621771C330}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD15B24A-7F6A-4830-9CA2-9C621771C330}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD15B24A-7F6A-4830-9CA2-9C621771C330}.Release|Any CPU.Build.0 = Release|Any CPU
{FD15B24A-7F6A-4830-9CA2-9C621771C330}.Wasm|Any CPU.ActiveCfg = Wasm|Any CPU
{FD15B24A-7F6A-4830-9CA2-9C621771C330}.Wasm|Any CPU.Build.0 = Wasm|Any CPU
{FD15B24A-7F6A-4830-9CA2-9C621771C330}.WebAssembly|Any CPU.ActiveCfg = WebAssembly|Any CPU
{FD15B24A-7F6A-4830-9CA2-9C621771C330}.WebAssembly|Any CPU.Build.0 = WebAssembly|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Release|Any CPU.Build.0 = Release|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Wasm|Any CPU.ActiveCfg = Wasm|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Wasm|Any CPU.Build.0 = Wasm|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.WebAssembly|Any CPU.ActiveCfg = WebAssembly|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.WebAssembly|Any CPU.Build.0 = WebAssembly|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Release|Any CPU.Build.0 = Release|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Wasm|Any CPU.ActiveCfg = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Wasm|Any CPU.Build.0 = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.WebAssembly|Any CPU.ActiveCfg = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.WebAssembly|Any CPU.Build.0 = Debug|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Debug|Any CPU.Build.0 = Debug|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Release|Any CPU.ActiveCfg = Release|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Release|Any CPU.Build.0 = Release|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Wasm|Any CPU.ActiveCfg = Debug|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Wasm|Any CPU.Build.0 = Debug|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.WebAssembly|Any CPU.ActiveCfg = Debug|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.WebAssembly|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE