Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability for Runtime and RenderMode to be set per Site - enabling the framework to support multiple hosting models concurrently in the same installation. Fixed WebAssembly Prerendering issue (this also resolved the issue where the component taghelper was not passing parameters correctly to the app when running on WebAssembly). Fix #1702 - remove web,config from upgrade package. #1708

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions Oqtane.Client/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,10 @@
_initialized = true;
}

protected override async Task OnAfterRenderAsync(bool firstRender)
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
if (string.IsNullOrEmpty(AntiForgeryToken))
{
// parameter values are not set when running on WebAssembly (seems to be a .NET 5 bug) - need to retrieve using JSInterop
var interop = new Interop(JSRuntime);

SiteState.AntiForgeryToken = await interop.GetElementByName(Constants.RequestVerificationToken);
InstallationService.SetAntiForgeryTokenHeader(SiteState.AntiForgeryToken);

Runtime = await interop.GetElementByName("app_runtime");
RenderMode = await interop.GetElementByName("app_rendermode");
}
_display = "";
StateHasChanged();
}
Expand Down
43 changes: 38 additions & 5 deletions Oqtane.Client/Modules/Admin/Site/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
</select>
</div>
</div>

</div>
</Section>
<Section Name="SMTP" Heading="SMTP Settings" ResourceKey="SMTPSettings">
Expand Down Expand Up @@ -157,10 +156,7 @@
</div>
<button type="button" class="btn btn-secondary" @onclick="SendEmail">@Localizer["Smtp.TestConfig"]</button>
<br /><br />

</div>


</Section>
<Section Name="PWA" Heading="Progressive Web Application Settings" ResourceKey="PWASettings">
<div class="container">
Expand Down Expand Up @@ -189,6 +185,28 @@
</Section>
@if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
{
<Section Name="Hosting" Heading="Hosting Model" ResourceKey="Hosting">
<div class="container">
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="runtime" HelpText="The Blazor runtime hosting model" ResourceKey="Runtime">Runtime: </Label>
<div class="col-sm-9">
<select id="runtime" class="form-select" @bind="@_runtime" required>
<option value="Server">@SharedLocalizer["BlazorServer"]</option>
<option value="WebAssembly">@SharedLocalizer["BlazorWebAssembly"]</option>
</select>
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="prerender" HelpText="Specifies if the site should be prerendered (for search crawlers, etc...)" ResourceKey="Prerender">Prerender? </Label>
<div class="col-sm-9">
<select id="prerender" class="form-select" @bind="@_prerender" required>
<option value="Prerendered">@SharedLocalizer["Yes"]</option>
<option value="">@SharedLocalizer["No"]</option>
</select>
</div>
</div>
</div>
</Section>
<Section Name="TenantInformation" Heading="Tenant Information" ResourceKey="TenantInformation">
<div class="container">
<div class="row mb-1 align-items-center">
Expand Down Expand Up @@ -231,6 +249,8 @@
private string _name = string.Empty;
private List<Alias> _aliasList;
private string _urls = string.Empty;
private string _runtime = "";
private string _prerender = "";
private int _logofileid = -1;
private FileManager _logofilemanager;
private int _faviconfileid = -1;
Expand Down Expand Up @@ -272,6 +292,8 @@
if (site != null)
{
_name = site.Name;
_runtime = site.Runtime;
_prerender = site.RenderMode.Replace(_runtime, "");
_allowregistration = site.AllowRegistration.ToString();
_isdeleted = site.IsDeleted.ToString();

Expand Down Expand Up @@ -413,9 +435,20 @@
var site = await SiteService.GetSiteAsync(PageState.Site.SiteId);
if (site != null)
{
bool reload = false;
bool refresh = (site.DefaultThemeType != _themetype || site.DefaultContainerType != _containertype);

site.Name = _name;
if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
{
if (site.Runtime != _runtime || site.RenderMode != _runtime + _prerender)
{
site.Runtime = _runtime;
site.RenderMode = _runtime + _prerender;
refresh = true;
reload = true;
}
}
site.AllowRegistration = (_allowregistration == null ? true : Boolean.Parse(_allowregistration));
site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted));

Expand Down Expand Up @@ -485,7 +518,7 @@

if (refresh)
{
NavigationManager.NavigateTo(NavigateUrl()); // refresh to show new theme or container
NavigationManager.NavigateTo(NavigateUrl(), reload); // refresh to show new theme or container
}
else
{
Expand Down
22 changes: 22 additions & 0 deletions Oqtane.Client/Modules/Admin/Sites/Add.razor
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ else
</select>
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="runtime" HelpText="The runtime hosting model" ResourceKey="Runtime">Runtime: </Label>
<div class="col-sm-9">
<select id="runtime" class="form-select" @bind="@_runtime" required>
<option value="Server">@SharedLocalizer["BlazorServer"]</option>
<option value="WebAssembly">@SharedLocalizer["BlazorWebAssembly"]</option>
</select>
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="prerender" HelpText="Specifies if the site should be prerendered (for search crawlers, etc...)" ResourceKey="Prerender">Prerender? </Label>
<div class="col-sm-9">
<select id="prerender" class="form-select" @bind="@_prerender" required>
<option value="Prerendered">@SharedLocalizer["Yes"]</option>
<option value="">@SharedLocalizer["No"]</option>
</select>
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="tenant" HelpText="Select the tenant for the site" ResourceKey="Tenant">Tenant: </Label>
<div class="col-sm-9">
Expand Down Expand Up @@ -177,6 +195,8 @@ else
private string _containertype = "-";
private string _admincontainertype = "";
private string _sitetemplatetype = "-";
private string _runtime = "Server";
private string _prerender = "Prerendered";

public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;

Expand Down Expand Up @@ -340,6 +360,8 @@ else
config.DefaultContainer = _containertype;
config.DefaultAdminContainer = _admincontainertype;
config.SiteTemplate = _sitetemplatetype;
config.Runtime = _runtime;
config.RenderMode = _runtime + _prerender;

ShowProgressIndicator();

Expand Down
24 changes: 0 additions & 24 deletions Oqtane.Client/Modules/Admin/SystemInfo/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,6 @@
</TabPanel>
<TabPanel Name="Options" Heading="Options" ResourceKey="Options">
<div class="container">
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="runtime" HelpText="Blazor Runtime (Server or WebAssembly)" ResourceKey="BlazorRuntime">Blazor Runtime: </Label>
<div class="col-sm-9">
<select id="runtime" class="form-select" @bind="@_runtime">
<option value="Server">@Localizer["Server"]</option>
<option value="WebAssembly">@Localizer["WebAssembly"]</option>
</select>
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="rendermode" HelpText="Blazor Server Render Mode" ResourceKey="RenderMode">Render Mode: </Label>
<div class="col-sm-9">
<select id="rendermode" class="form-select" @bind="@_rendermode">
<option value="Server">@Localizer["Server"]</option>
<option value="ServerPrerendered">@Localizer["ServerPrerendered"]</option>
</select>
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="detailederrors" HelpText="Specify If Detailed Errors Are Enabled For Blazor. This Option Should Not Not Be Enabled In Production." ResourceKey="DetailedErrors">Detailed Errors? </Label>
<div class="col-sm-9">
Expand Down Expand Up @@ -126,8 +108,6 @@
private string _servertime = string.Empty;
private string _installationid = string.Empty;

private string _runtime = string.Empty;
private string _rendermode = string.Empty;
private string _detailederrors = string.Empty;
private string _logginglevel = string.Empty;
private string _swagger = string.Empty;
Expand All @@ -146,8 +126,6 @@
_servertime = systeminfo["servertime"];
_installationid = systeminfo["installationid"];

_runtime = systeminfo["runtime"];
_rendermode = systeminfo["rendermode"];
_detailederrors = systeminfo["detailederrors"];
_logginglevel = systeminfo["logginglevel"];
_swagger = systeminfo["swagger"];
Expand All @@ -160,8 +138,6 @@
try
{
var settings = new Dictionary<string, string>();
settings.Add("runtime", _runtime);
settings.Add("rendermode", _rendermode);
settings.Add("detailederrors", _detailederrors);
settings.Add("logginglevel", _logginglevel);
settings.Add("swagger", _swagger);
Expand Down
1 change: 0 additions & 1 deletion Oqtane.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class Program
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");

var httpClient = new HttpClient {BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)};

Expand Down
15 changes: 15 additions & 0 deletions Oqtane.Client/Resources/Modules/Admin/Site/Index.resx
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,19 @@
<data name="Theme.Select" xml:space="preserve">
<value>Select Theme</value>
</data>
<data name="Hosting" xml:space="preserve">
<value>Hosting Model</value>
</data>
<data name="Prerender.HelpText" xml:space="preserve">
<value>Specifies if the site should be prerendered (for search crawlers, etc...)</value>
</data>
<data name="Prerender.Text" xml:space="preserve">
<value>Prerender? </value>
</data>
<data name="Runtime.HelpText" xml:space="preserve">
<value>The Blazor runtime hosting model</value>
</data>
<data name="Runtime.Text" xml:space="preserve">
<value>Runtime: </value>
</data>
</root>
12 changes: 12 additions & 0 deletions Oqtane.Client/Resources/Modules/Admin/Sites/Add.resx
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,16 @@
<data name="Error.Database.LoadConfig" xml:space="preserve">
<value>Error loading Database Configuration Control</value>
</data>
<data name="Prerender.HelpText" xml:space="preserve">
<value>Specifies if the site should be prerendered (for search crawlers, etc...)</value>
</data>
<data name="Prerender.Text" xml:space="preserve">
<value>Prerender? </value>
</data>
<data name="Runtime.HelpText" xml:space="preserve">
<value>The Blazor runtime hosting model</value>
</data>
<data name="Runtime.Text" xml:space="preserve">
<value>Runtime: </value>
</data>
</root>
15 changes: 0 additions & 15 deletions Oqtane.Client/Resources/Modules/Admin/SystemInfo/Index.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@
<data name="FrameworkVersion.HelpText" xml:space="preserve">
<value>Framework Version</value>
</data>
<data name="BlazorRuntime.HelpText" xml:space="preserve">
<value>Blazor Runtime (Server or WebAssembly)</value>
</data>
<data name="CLRVersion.HelpText" xml:space="preserve">
<value>Common Language Runtime Version</value>
</data>
Expand All @@ -141,9 +138,6 @@
<data name="FrameworkVersion.Text" xml:space="preserve">
<value>Framework Version: </value>
</data>
<data name="BlazorRuntime.Text" xml:space="preserve">
<value>Blazor Runtime: </value>
</data>
<data name="CLRVersion.Text" xml:space="preserve">
<value>CLR Version: </value>
</data>
Expand All @@ -165,18 +159,9 @@
<data name="Error.UpdateConfig" xml:space="preserve">
<value>An Error Occurred Updating The Configuration</value>
</data>
<data name="Server" xml:space="preserve">
<value>Server</value>
</data>
<data name="ServerPrerendered" xml:space="preserve">
<value>ServerPrerendered</value>
</data>
<data name="Success.UpdateConfig.Restart" xml:space="preserve">
<value>Configuration Updated. Please Select Restart Application For These Changes To Be Activated.</value>
</data>
<data name="WebAssembly" xml:space="preserve">
<value>WebAssembly</value>
</data>
<data name="InstallationId.Text" xml:space="preserve">
<value>Installation ID: </value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions Oqtane.Client/Resources/SharedResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,10 @@
<data name="Not Specified" xml:space="preserve">
<value>Not Specified</value>
</data>
<data name="BlazorServer" xml:space="preserve">
<value>Blazor Server</value>
</data>
<data name="BlazorWebAssembly" xml:space="preserve">
<value>Blazor WebAssembly</value>
</data>
</root>
20 changes: 10 additions & 10 deletions Oqtane.Client/UI/SiteRouter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@
// parse querystring
var querystring = ParseQueryString(uri.Query);

// the refresh parameter is used to refresh the PageState
if (querystring.ContainsKey("refresh"))
// reload the client application if there is a forced reload or the user navigated to a site with a different alias
if (querystring.ContainsKey("reload") || (!path.ToLower().StartsWith(SiteState.Alias.Path.ToLower()) && !string.IsNullOrEmpty(SiteState.Alias.Path)))
{
refresh = UI.Refresh.Site;
NavigationManager.NavigateTo(_absoluteUri.Replace("?reload", ""), true);
return;
}
else
{
// reload the client application if the user navigated to a site with a different alias or there is a forced reload
if ((!path.ToLower().StartsWith(SiteState.Alias.Path.ToLower()) && !string.IsNullOrEmpty(SiteState.Alias.Path)) || querystring.ContainsKey("reload"))
// the refresh parameter is used to refresh the PageState
if (querystring.ContainsKey("refresh"))
{
NavigationManager.NavigateTo(_absoluteUri.Replace("?reload", ""), true);
return;
refresh = UI.Refresh.Site;
}
}

Expand All @@ -109,10 +109,10 @@
// process any sync events
var sync = await SyncService.GetSyncAsync(lastsyncdate);
lastsyncdate = sync.SyncDate;
if (refresh != UI.Refresh.Site && sync.SyncEvents.Any())
if (sync.SyncEvents.Any())
{
// if running on WebAssembly reload the client application if the server application was restarted
if (runtime == Shared.Runtime.WebAssembly && PageState != null && sync.SyncEvents.Exists(item => item.TenantId == -1))
// reload client application if server was restarted or site runtime/rendermode was modified
if (PageState != null && sync.SyncEvents.Exists(item => (item.TenantId == -1 || item.EntityName == EntityNames.Site && item.EntityId == SiteState.Alias.SiteId) && item.Reload))
{
NavigationManager.NavigateTo(_absoluteUri, true);
return;
Expand Down
1 change: 1 addition & 0 deletions Oqtane.Package/release.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ del "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.json"
ren "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.release.json" "appsettings.json"
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ".\install.ps1"
del "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.json"
del "..\Oqtane.Server\bin\Release\net5.0\publish\web.config"
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ".\upgrade.ps1"
dotnet clean -c Release ..\Oqtane.Updater.sln
dotnet build -c Release ..\Oqtane.Updater.sln
Expand Down
10 changes: 1 addition & 9 deletions Oqtane.Server/Controllers/InstallationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,7 @@ public void Restart()
[HttpGet("load")]
public IActionResult Load()
{
if (_configManager.GetSection("Runtime").Value == "WebAssembly")
{
return File(GetAssemblies(), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
}
else
{
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return null;
}
return File(GetAssemblies(), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
}

private byte[] GetAssemblies()
Expand Down
10 changes: 8 additions & 2 deletions Oqtane.Server/Controllers/SiteController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ public Site Post([FromBody] Site site)
[Authorize(Roles = RoleNames.Admin)]
public Site Put(int id, [FromBody] Site site)
{
if (ModelState.IsValid && site.SiteId == _alias.SiteId && site.TenantId == _alias.TenantId && _sites.GetSite(site.SiteId, false) != null)
var current = _sites.GetSite(site.SiteId, false);
if (ModelState.IsValid && site.SiteId == _alias.SiteId && site.TenantId == _alias.TenantId && current != null)
{
site = _sites.UpdateSite(site);
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, site.SiteId);
bool reload = false;
if (current.Runtime != site.Runtime || current.RenderMode != site.RenderMode)
{
reload = true;
}
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, site.SiteId, reload);
_logger.Log(site.SiteId, LogLevel.Information, this, LogFunction.Update, "Site Updated {Site}", site);
}
else
Expand Down
Loading