Merge pull request #1423 from sbwalker/dev

made RenderMode configurable
This commit is contained in:
Shaun Walker 2021-05-30 15:34:04 -04:00 committed by GitHub
commit c402113df3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 18 deletions

View File

@ -15,12 +15,20 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<Label For="runtime" HelpText="Blazor Runtime (Server or WebAssembly)" ResourceKey="BlazorRunime">Blazor Runtime: </Label> <Label For="runtime" HelpText="Blazor Runtime (Server or WebAssembly)" ResourceKey="BlazorRuntime">Blazor Runtime: </Label>
</td> </td>
<td> <td>
<input id="runtime" class="form-control" @bind="@_runtime" readonly /> <input id="runtime" class="form-control" @bind="@_runtime" readonly />
</td> </td>
</tr> </tr>
<tr>
<td>
<Label For="rendermode" HelpText="Blazor Render Mode" ResourceKey="RenderMode">Render Mode: </Label>
</td>
<td>
<input id="rendermode" class="form-control" @bind="@_rendermode" readonly />
</td>
</tr>
<tr> <tr>
<td> <td>
<Label For="clrversion" HelpText="Common Language Runtime Version" ResourceKey="ClrVerion">CLR Version: </Label> <Label For="clrversion" HelpText="Common Language Runtime Version" ResourceKey="ClrVerion">CLR Version: </Label>
@ -62,6 +70,7 @@
private string _version = string.Empty; private string _version = string.Empty;
private string _runtime = string.Empty; private string _runtime = string.Empty;
private string _rendermode = string.Empty;
private string _clrversion = string.Empty; private string _clrversion = string.Empty;
private string _osversion = string.Empty; private string _osversion = string.Empty;
private string _serverpath = string.Empty; private string _serverpath = string.Empty;
@ -75,6 +84,7 @@
Dictionary<string, string> systeminfo = await SystemService.GetSystemInfoAsync(); Dictionary<string, string> systeminfo = await SystemService.GetSystemInfoAsync();
if (systeminfo != null) if (systeminfo != null)
{ {
_rendermode = systeminfo["rendermode"];
_clrversion = systeminfo["clrversion"]; _clrversion = systeminfo["clrversion"];
_osversion = systeminfo["osversion"]; _osversion = systeminfo["osversion"];
_serverpath = systeminfo["serverpath"]; _serverpath = systeminfo["serverpath"];

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using Oqtane.Shared; using Oqtane.Shared;
using System; using System;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers namespace Oqtane.Controllers
{ {
@ -11,10 +12,12 @@ namespace Oqtane.Controllers
public class SystemController : Controller public class SystemController : Controller
{ {
private readonly IWebHostEnvironment _environment; private readonly IWebHostEnvironment _environment;
private readonly IConfigManager _configManager;
public SystemController(IWebHostEnvironment environment) public SystemController(IWebHostEnvironment environment, IConfigManager configManager)
{ {
_environment = environment; _environment = environment;
_configManager = configManager;
} }
// GET: api/<controller> // GET: api/<controller>
@ -23,11 +26,14 @@ namespace Oqtane.Controllers
public Dictionary<string, string> Get() public Dictionary<string, string> Get()
{ {
Dictionary<string, string> systeminfo = new Dictionary<string, string>(); Dictionary<string, string> systeminfo = new Dictionary<string, string>();
systeminfo.Add("rendermode", _configManager.GetSetting("RenderMode", "Server"));
systeminfo.Add("clrversion", Environment.Version.ToString()); systeminfo.Add("clrversion", Environment.Version.ToString());
systeminfo.Add("osversion", Environment.OSVersion.ToString()); systeminfo.Add("osversion", Environment.OSVersion.ToString());
systeminfo.Add("machinename", Environment.MachineName); systeminfo.Add("machinename", Environment.MachineName);
systeminfo.Add("serverpath", _environment.ContentRootPath); systeminfo.Add("serverpath", _environment.ContentRootPath);
systeminfo.Add("servertime", DateTime.Now.ToString()); systeminfo.Add("servertime", DateTime.Now.ToString());
return systeminfo; return systeminfo;
} }

View File

@ -20,10 +20,23 @@ namespace Oqtane.Infrastructure
return _config.GetSection(key); return _config.GetSection(key);
} }
public string GetSetting(string sectionKey, string settingKey, string defaultValue) public T GetSetting<T>(string sectionKey, T defaultValue)
{ {
var value = _config.GetSection(sectionKey).GetValue(settingKey, defaultValue); return GetSetting(sectionKey, "", defaultValue);
if (string.IsNullOrEmpty(value)) value = defaultValue; }
public T GetSetting<T>(string sectionKey, string settingKey, T defaultValue)
{
T value;
if (!string.IsNullOrEmpty(settingKey))
{
value = _config.GetSection(sectionKey).GetValue(settingKey, defaultValue);
}
else
{
value = _config.GetValue(sectionKey, defaultValue);
}
if (value == null) value = defaultValue;
return value; return value;
} }

View File

@ -55,7 +55,7 @@ namespace Oqtane.Infrastructure
{ {
File.Delete(destinationFile); File.Delete(destinationFile);
} }
if (Path.GetExtension(destinationFile) == ".nupkg.bak") if (destinationFile.ToLower().EndsWith(".nupkg.bak"))
{ {
// leave a copy in the current folder as it is distributed with the core framework // leave a copy in the current folder as it is distributed with the core framework
File.Copy(file, destinationFile); File.Copy(file, destinationFile);

View File

@ -5,7 +5,8 @@ namespace Oqtane.Infrastructure
public interface IConfigManager public interface IConfigManager
{ {
public IConfigurationSection GetSection(string sectionKey); public IConfigurationSection GetSection(string sectionKey);
public string GetSetting(string sectionKey, string settingKey, string defaultValue); public T GetSetting<T>(string settingKey, T defaultValue);
public T GetSetting<T>(string sectionKey, string settingKey, T defaultValue);
void AddOrUpdateSetting<T>(string key, T value, bool reload); void AddOrUpdateSetting<T>(string key, T value, bool reload);
void AddOrUpdateSetting<T>(string file, string key, T value, bool reload); void AddOrUpdateSetting<T>(string file, string key, T value, bool reload);
void RemoveSetting(string key, bool reload); void RemoveSetting(string key, bool reload);

View File

@ -41,6 +41,9 @@ namespace Oqtane.Infrastructure
case "2.0.2": case "2.0.2":
Upgrade_2_0_2(tenant, scope); Upgrade_2_0_2(tenant, scope);
break; break;
case "2.1.0":
Upgrade_2_1_0(tenant, scope);
break;
} }
} }
} }
@ -113,6 +116,18 @@ namespace Oqtane.Infrastructure
} }
} }
private void Upgrade_2_1_0(Tenant tenant, IServiceScope scope)
{
if (tenant.Name == TenantNames.Master)
{
_configManager.RemoveSetting("Localization:SupportedCultures", true);
if (_configManager.GetSetting("RenderMode", "") == "")
{
_configManager.AddOrUpdateSetting("RenderMode", "ServerPrerendered", true);
}
}
}
private void CreateSitePages(IServiceScope scope, List<PageTemplate> pageTemplates) private void CreateSitePages(IServiceScope scope, List<PageTemplate> pageTemplates)
{ {
if (pageTemplates.Count != 0) if (pageTemplates.Count != 0)

View File

@ -1,8 +1,6 @@
@page "/" @page "/"
@namespace Oqtane.Pages @namespace Oqtane.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
@model Oqtane.Pages.HostModel @model Oqtane.Pages.HostModel
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -22,14 +20,7 @@
<body> <body>
@(Html.AntiForgeryToken()) @(Html.AntiForgeryToken())
<app> <app>
@if (Configuration.GetSection("Runtime").Value == "WebAssembly") <component type="typeof(Oqtane.App)" render-mode="@Model.RenderMode" />
{
<component type="typeof(Oqtane.App)" render-mode="Server" />
}
else
{
<component type="typeof(Oqtane.App)" render-mode="ServerPrerendered" />
}
</app> </app>
<div id="blazor-error-ui"> <div id="blazor-error-ui">
@ -52,7 +43,7 @@
<script src="js/interop.js"></script> <script src="js/interop.js"></script>
@if (Configuration.GetSection("Runtime").Value == "WebAssembly") @if (Model.Runtime == "WebAssembly")
{ {
<script src="_framework/blazor.webassembly.js"></script> <script src="_framework/blazor.webassembly.js"></script>
} }

View File

@ -11,6 +11,7 @@ using System.Reflection;
using Oqtane.Repository; using Oqtane.Repository;
using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace Oqtane.Pages namespace Oqtane.Pages
{ {
@ -33,12 +34,24 @@ namespace Oqtane.Pages
_languages = languages; _languages = languages;
} }
public string Runtime = "Server";
public RenderMode RenderMode = RenderMode.Server;
public string HeadResources = ""; public string HeadResources = "";
public string BodyResources = ""; public string BodyResources = "";
public string Message = ""; public string Message = "";
public void OnGet() public void OnGet()
{ {
if (_configuration.GetSection("Runtime").Exists())
{
Runtime = _configuration.GetSection("Runtime").Value;
}
if (Runtime != "WebAssembly" && _configuration.GetSection("RenderMode").Exists())
{
RenderMode = (RenderMode)Enum.Parse(typeof(RenderMode), _configuration.GetSection("RenderMode").Value, true);
}
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies(); var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
foreach (Assembly assembly in assemblies) foreach (Assembly assembly in assemblies)
{ {