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

improve user experience by delegating application restart responsibility to the host user #947

Merged
merged 2 commits into from
Nov 24, 2020
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
10 changes: 1 addition & 9 deletions Oqtane.Client/Modules/Admin/ModuleCreator/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,15 @@

public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;

protected override void OnInitialized()
{
AddModuleMessage("Please Note That Once You Select The Create Module Button The Application Must Restart In Order To Complete The Process. If You Create An External Module You Will Need To Compile The Source Code And Then Relaunch Your Site In Order To Make It Functional.", MessageType.Info);
}

private async Task CreateModule()
{
try
{
if (IsValid(_owner) && IsValid(_module) && _template != "-")
{
ShowProgressIndicator();
var interop = new Interop(JSRuntime);
await interop.RedirectBrowser(NavigateUrl(), 5);

var moduleDefinition = new ModuleDefinition { Owner = _owner, Name = _module, Description = _description, Template = _template, Version = _reference };
await ModuleDefinitionService.CreateModuleDefinitionAsync(moduleDefinition, ModuleState.ModuleId);
AddModuleMessage("The Source Code For Your Module Has Been Created And Must Be Compiled In Order To Make It Functional. Once It Has Been Compiled You Must Restart Your Application.", MessageType.Success);
}
else
{
Expand Down
6 changes: 2 additions & 4 deletions Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@
{
try
{
ShowProgressIndicator();
var interop = new Interop(JSRuntime);
await interop.RedirectBrowser(NavigateUrl(), 10);
await ModuleDefinitionService.InstallModuleDefinitionsAsync();
AddModuleMessage("Module Installed Successfully. You Must <a href=\"" + NavigateUrl("admin/system") + "\">Restart</a> Your Application To Apply These Changes.", MessageType.Success);
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Installating Module");
await logger.LogError(ex, "Error Installing Module");
}
}

Expand Down
8 changes: 2 additions & 6 deletions Oqtane.Client/Modules/Admin/ModuleDefinitions/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ else
{
await PackageService.DownloadPackageAsync(moduledefinitionname, version, "Modules");
await logger.LogInformation("Module Downloaded {ModuleDefinitionName} {Version}", moduledefinitionname, version);
ShowProgressIndicator();
var interop = new Interop(JSRuntime);
await interop.RedirectBrowser(NavigateUrl(), 10);
await ModuleDefinitionService.InstallModuleDefinitionsAsync();
AddModuleMessage("Module Installed Successfully. You Must <a href=\"" + NavigateUrl("admin/system") + "\">Restart</a> Your Application To Apply These Changes.", MessageType.Success);
}
catch (Exception ex)
{
Expand All @@ -101,10 +99,8 @@ else
{
try
{
ShowProgressIndicator();
var interop = new Interop(JSRuntime);
await interop.RedirectBrowser(NavigateUrl(), 10);
await ModuleDefinitionService.DeleteModuleDefinitionAsync(moduleDefinition.ModuleDefinitionId, moduleDefinition.SiteId);
AddModuleMessage("Module Deleted Successfully. You Must <a href=\"" + NavigateUrl("admin/system") + "\">Restart</a> Your Application To Apply These Changes.", MessageType.Success);
}
catch (Exception ex)
{
Expand Down
21 changes: 19 additions & 2 deletions Oqtane.Client/Modules/Admin/SystemInfo/Index.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@namespace Oqtane.Modules.Admin.SystemInfo
@inherits ModuleBase
@inject ISystemService SystemService
@inject IInstallationService InstallationService
@inject IStringLocalizer<Index> Localizer

<table class="table table-borderless">
Expand Down Expand Up @@ -53,7 +54,8 @@
</td>
</tr>
</table>
<a class="btn btn-primary" href="swagger/index.html" target="_new">@Localizer["Access Framework API"]</a>
<a class="btn btn-primary" href="swagger/index.html" target="_new">@Localizer["Access Framework API"]</a>&nbsp;
<ActionDialog Header="Restart Application" Message="@("Are You Sure You Wish To Restart The Application?")" Action="Restart Application" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await RestartApplication())" ResourceKey="RestartApplication" />

@code {
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
Expand All @@ -79,4 +81,19 @@
_servertime = systeminfo["servertime"];
}
}
}

private async Task RestartApplication()
{
try
{
ShowProgressIndicator();
var interop = new Interop(JSRuntime);
await interop.RedirectBrowser(NavigateUrl(""), 10);
await InstallationService.RestartAsync();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Restarting Application");
}
}
}
6 changes: 2 additions & 4 deletions Oqtane.Client/Modules/Admin/Themes/Add.razor
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@
{
try
{
ShowProgressIndicator();
var interop = new Interop(JSRuntime);
await interop.RedirectBrowser(NavigateUrl(), 10);
await ThemeService.InstallThemesAsync();
AddModuleMessage("Theme Installed Successfully. You Must <a href=\"" + NavigateUrl("admin/system") + "\">Restart</a> Your Application To Apply These Changes.", MessageType.Success);
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Installating Theme");
await logger.LogError(ex, "Error Installing Theme");
}
}

Expand Down
8 changes: 2 additions & 6 deletions Oqtane.Client/Modules/Admin/Themes/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ else
{
await PackageService.DownloadPackageAsync(themename, version, "Themes");
await logger.LogInformation("Theme Downloaded {ThemeName} {Version}", themename, version);
ShowProgressIndicator();
var interop = new Interop(JSRuntime);
await interop.RedirectBrowser(NavigateUrl(), 10);
await ThemeService.InstallThemesAsync();
AddModuleMessage("Theme Installed Successfully. You Must <a href=\"" + NavigateUrl("admin/system") + "\">Restart</a> Your Application To Apply These Changes.", MessageType.Success);
}
catch (Exception ex)
{
Expand All @@ -102,10 +100,8 @@ else
{
try
{
ShowProgressIndicator();
var interop = new Interop(JSRuntime);
await interop.RedirectBrowser(NavigateUrl(), 10);
await ThemeService.DeleteThemeAsync(Theme.ThemeName);
AddModuleMessage("Theme Deleted Successfully. You Must <a href=\"" + NavigateUrl("admin/system") + "\">Restart</a> Your Application To Apply These Changes.", MessageType.Success);
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion Oqtane.Client/Modules/Controls/ModuleMessage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@if (!string.IsNullOrEmpty(_message))
{
<div class="@_classname" role="alert">
@_message
@((MarkupString)_message)
@if (Type == MessageType.Error && PageState != null && UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
{
@((MarkupString)"&nbsp;&nbsp;")<NavLink href="@NavigateUrl("admin/log")">View Details</NavLink>
Expand Down
7 changes: 6 additions & 1 deletion Oqtane.Client/Services/InstallationService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Oqtane.Models;
using Oqtane.Models;
using System.Threading.Tasks;
using System.Net.Http;
using Oqtane.Shared;
Expand All @@ -25,5 +25,10 @@ public async Task<Installation> Upgrade()
{
return await GetJsonAsync<Installation>($"{ApiUrl}/upgrade");
}

public async Task RestartAsync()
{
await PostAsync($"{ApiUrl}/restart");
}
}
}
3 changes: 2 additions & 1 deletion Oqtane.Client/Services/Interfaces/IInstallationService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Oqtane.Models;
using Oqtane.Models;
using System.Threading.Tasks;
using Oqtane.Shared;

Expand All @@ -9,5 +9,6 @@ public interface IInstallationService
Task<Installation> IsInstalled();
Task<Installation> Install(InstallConfig config);
Task<Installation> Upgrade();
Task RestartAsync();
}
}
8 changes: 8 additions & 0 deletions Oqtane.Server/Controllers/InstallationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public Installation Upgrade()
return installation;
}

// GET api/<controller>/restart
[HttpPost("restart")]
[Authorize(Roles = RoleNames.Host)]
public void Restart()
{
_installationManager.RestartApplication();
}

// GET api/<controller>/load
[HttpGet("load")]
public IActionResult Load()
Expand Down
7 changes: 1 addition & 6 deletions Oqtane.Server/Controllers/ModuleDefinitionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void Put(int id, [FromBody] ModuleDefinition moduleDefinition)
public void InstallModules()
{
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Modules Installed");
_installationManager.InstallPackages("Modules", true);
_installationManager.InstallPackages("Modules");
}

// DELETE api/<controller>/5?siteid=x
Expand Down Expand Up @@ -159,9 +159,6 @@ public void Delete(int id, int siteid)
// remove module definition
_moduleDefinitions.DeleteModuleDefinition(id, siteid);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Definition {ModuleDefinitionName} Deleted", moduledefinition.Name);

// restart application
_installationManager.RestartApplication();
}
}
}
Expand Down Expand Up @@ -205,8 +202,6 @@ public void Post([FromBody] ModuleDefinition moduleDefinition, string moduleid)
resources.Add(Utilities.PathCombine("Modules", moduleDefinition.Owner + "." + moduleDefinition.Name, "Scripts", moduleDefinition.Owner + "." + moduleDefinition.Name + ".Uninstall.sql"));
EmbedResourceFiles(Utilities.PathCombine(rootPath, "Oqtane.Server", "Oqtane.Server.csproj"), resources);
}

_installationManager.RestartApplication();
}
}

Expand Down
6 changes: 2 additions & 4 deletions Oqtane.Server/Controllers/ThemeController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Oqtane.Models;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -45,7 +45,7 @@ public IEnumerable<Theme> Get()
public void InstallThemes()
{
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Themes Installed");
_installationManager.InstallPackages("Themes", true);
_installationManager.InstallPackages("Themes");
}

// DELETE api/<controller>/xxx
Expand Down Expand Up @@ -79,8 +79,6 @@ public void Delete(string themename)
Directory.Delete(folder, true);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Resource Folder Removed For {ThemeName}", theme.ThemeName);
}

_installationManager.RestartApplication();
}
}

Expand Down
10 changes: 3 additions & 7 deletions Oqtane.Server/Infrastructure/InstallationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ public InstallationManager(IHostApplicationLifetime hostApplicationLifetime, IWe
_cache = cache;
}

public void InstallPackages(string folders, bool restart)
public void InstallPackages(string folders)
{
var webRootPath = _environment.WebRootPath;

var install = InstallPackages(folders, webRootPath);

if (install && restart)
if (!InstallPackages(folders, _environment.WebRootPath))
{
RestartApplication();
// error installing packages
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Oqtane.Infrastructure
namespace Oqtane.Infrastructure
{
public interface IInstallationManager
{
void InstallPackages(string folders, bool restart);
void InstallPackages(string folders);
void UpgradeFramework();
void RestartApplication();
}
Expand Down