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

made RenderMode configurable #1423

Merged
merged 1 commit into from
May 30, 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
12 changes: 11 additions & 1 deletion Oqtane.Client/Modules/Admin/SystemInfo/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@
</tr>
<tr>
<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>
<input id="runtime" class="form-control" @bind="@_runtime" readonly />
</td>
</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>
<td>
<Label For="clrversion" HelpText="Common Language Runtime Version" ResourceKey="ClrVerion">CLR Version: </Label>
Expand Down Expand Up @@ -62,6 +70,7 @@

private string _version = string.Empty;
private string _runtime = string.Empty;
private string _rendermode = string.Empty;
private string _clrversion = string.Empty;
private string _osversion = string.Empty;
private string _serverpath = string.Empty;
Expand All @@ -75,6 +84,7 @@
Dictionary<string, string> systeminfo = await SystemService.GetSystemInfoAsync();
if (systeminfo != null)
{
_rendermode = systeminfo["rendermode"];
_clrversion = systeminfo["clrversion"];
_osversion = systeminfo["osversion"];
_serverpath = systeminfo["serverpath"];
Expand Down
8 changes: 7 additions & 1 deletion Oqtane.Server/Controllers/SystemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
using Oqtane.Shared;
using System;
using Microsoft.AspNetCore.Hosting;
using Oqtane.Infrastructure;

namespace Oqtane.Controllers
{
[Route(ControllerRoutes.ApiRoute)]
public class SystemController : Controller
{
private readonly IWebHostEnvironment _environment;
private readonly IConfigManager _configManager;

public SystemController(IWebHostEnvironment environment)
public SystemController(IWebHostEnvironment environment, IConfigManager configManager)
{
_environment = environment;
_configManager = configManager;
}

// GET: api/<controller>
Expand All @@ -23,11 +26,14 @@ public SystemController(IWebHostEnvironment environment)
public Dictionary<string, string> Get()
{
Dictionary<string, string> systeminfo = new Dictionary<string, string>();

systeminfo.Add("rendermode", _configManager.GetSetting("RenderMode", "Server"));
systeminfo.Add("clrversion", Environment.Version.ToString());
systeminfo.Add("osversion", Environment.OSVersion.ToString());
systeminfo.Add("machinename", Environment.MachineName);
systeminfo.Add("serverpath", _environment.ContentRootPath);
systeminfo.Add("servertime", DateTime.Now.ToString());

return systeminfo;
}

Expand Down
19 changes: 16 additions & 3 deletions Oqtane.Server/Infrastructure/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,23 @@ public IConfigurationSection GetSection(string 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);
if (string.IsNullOrEmpty(value)) value = defaultValue;
return GetSetting(sectionKey, "", 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;
}

Expand Down
2 changes: 1 addition & 1 deletion Oqtane.Server/Infrastructure/InstallationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static bool InstallPackages(string webRootPath, string contentRootPath)
{
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
File.Copy(file, destinationFile);
Expand Down
3 changes: 2 additions & 1 deletion Oqtane.Server/Infrastructure/Interfaces/IConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace Oqtane.Infrastructure
public interface IConfigManager
{
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 file, string key, T value, bool reload);
void RemoveSetting(string key, bool reload);
Expand Down
15 changes: 15 additions & 0 deletions Oqtane.Server/Infrastructure/UpgradeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public void Upgrade(Tenant tenant, string version)
case "2.0.2":
Upgrade_2_0_2(tenant, scope);
break;
case "2.1.0":
Upgrade_2_1_0(tenant, scope);
break;
}
}
}
Expand Down Expand Up @@ -113,6 +116,18 @@ private void Upgrade_2_0_2(Tenant tenant, IServiceScope scope)
}
}

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)
{
if (pageTemplates.Count != 0)
Expand Down
13 changes: 2 additions & 11 deletions Oqtane.Server/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@page "/"
@namespace Oqtane.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
@model Oqtane.Pages.HostModel
<!DOCTYPE html>
<html>
Expand All @@ -22,14 +20,7 @@
<body>
@(Html.AntiForgeryToken())
<app>
@if (Configuration.GetSection("Runtime").Value == "WebAssembly")
{
<component type="typeof(Oqtane.App)" render-mode="Server" />
}
else
{
<component type="typeof(Oqtane.App)" render-mode="ServerPrerendered" />
}
<component type="typeof(Oqtane.App)" render-mode="@Model.RenderMode" />
</app>

<div id="blazor-error-ui">
Expand All @@ -52,7 +43,7 @@

<script src="js/interop.js"></script>

@if (Configuration.GetSection("Runtime").Value == "WebAssembly")
@if (Model.Runtime == "WebAssembly")
{
<script src="_framework/blazor.webassembly.js"></script>
}
Expand Down
13 changes: 13 additions & 0 deletions Oqtane.Server/Pages/_Host.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Oqtane.Repository;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace Oqtane.Pages
{
Expand All @@ -33,12 +34,24 @@ public HostModel(
_languages = languages;
}

public string Runtime = "Server";
public RenderMode RenderMode = RenderMode.Server;
public string HeadResources = "";
public string BodyResources = "";
public string Message = "";

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();
foreach (Assembly assembly in assemblies)
{
Expand Down