fix for #525 when running locally without a network connection

This commit is contained in:
Shaun Walker 2020-05-28 16:24:22 -04:00
parent 0f09df13b5
commit 3a5b6954e3
3 changed files with 96 additions and 35 deletions

View File

@ -55,20 +55,26 @@ else
} }
catch (Exception ex) catch (Exception ex)
{ {
await logger.LogError(ex, "Error Loading Modules {Error}", ex.Message); if (_moduleDefinitions == null)
AddModuleMessage("Error Loading Modules", MessageType.Error); {
await logger.LogError(ex, "Error Loading Modules {Error}", ex.Message);
AddModuleMessage("Error Loading Modules", MessageType.Error);
}
} }
} }
private bool UpgradeAvailable(string moduledefinitionname, string version) private bool UpgradeAvailable(string moduledefinitionname, string version)
{ {
var upgradeavailable = false; var upgradeavailable = false;
var package = _packages.Where(item => item.PackageId == Utilities.GetTypeName(moduledefinitionname)).FirstOrDefault(); if (_packages != null)
if (package != null)
{ {
upgradeavailable = (Version.Parse(package.Version).CompareTo(Version.Parse(version)) > 0); var package = _packages.Where(item => item.PackageId == Utilities.GetTypeName(moduledefinitionname)).FirstOrDefault();
} if (package != null)
{
upgradeavailable = (Version.Parse(package.Version).CompareTo(Version.Parse(version)) > 0);
}
}
return upgradeavailable; return upgradeavailable;
} }
@ -86,7 +92,7 @@ else
await logger.LogError(ex, "Error Downloading Module {ModuleDefinitionName} {Version} {Error}", moduledefinitionname, version, ex.Message); await logger.LogError(ex, "Error Downloading Module {ModuleDefinitionName} {Version} {Error}", moduledefinitionname, version, ex.Message);
AddModuleMessage("Error Downloading Module", MessageType.Error); AddModuleMessage("Error Downloading Module", MessageType.Error);
} }
} }
private async Task DeleteModule(ModuleDefinition moduleDefinition) private async Task DeleteModule(ModuleDefinition moduleDefinition)
{ {

View File

@ -4,7 +4,7 @@
@inject IThemeService ThemeService @inject IThemeService ThemeService
@inject IPackageService PackageService @inject IPackageService PackageService
@if (themes == null) @if (_themes == null)
{ {
<p><em>Loading...</em></p> <p><em>Loading...</em></p>
} }
@ -12,7 +12,7 @@ else
{ {
<ActionLink Action="Add" Text="Install Theme" /> <ActionLink Action="Add" Text="Install Theme" />
<Pager Items="@themes"> <Pager Items="@_themes">
<Header> <Header>
<th>&nbsp;</th> <th>&nbsp;</th>
<th>Name</th> <th>Name</th>
@ -39,41 +39,70 @@ else
} }
@code { @code {
private List<Theme> themes; private List<Theme> _themes;
private List<Package> packages; private List<Package> _packages;
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
themes = await ThemeService.GetThemesAsync(); try
packages = await PackageService.GetPackagesAsync("module"); {
_themes = await ThemeService.GetThemesAsync();
_packages = await PackageService.GetPackagesAsync("theme");
}
catch (Exception ex)
{
if (_themes == null)
{
await logger.LogError(ex, "Error Loading Themes {Error}", ex.Message);
AddModuleMessage("Error Loading Themes", MessageType.Error);
}
}
} }
private bool UpgradeAvailable(string themename, string version) private bool UpgradeAvailable(string themename, string version)
{ {
var upgradeavailable = false; var upgradeavailable = false;
var package = packages.Where(item => item.PackageId == Utilities.GetTypeName(themename)).FirstOrDefault(); if (_packages != null)
if (package != null)
{ {
upgradeavailable = (Version.Parse(package.Version).CompareTo(Version.Parse(version)) > 0); var package = _packages.Where(item => item.PackageId == Utilities.GetTypeName(themename)).FirstOrDefault();
if (package != null)
{
upgradeavailable = (Version.Parse(package.Version).CompareTo(Version.Parse(version)) > 0);
}
} }
return upgradeavailable; return upgradeavailable;
} }
private async Task DownloadTheme(string themename, string version) private async Task DownloadTheme(string themename, string version)
{ {
await PackageService.DownloadPackageAsync(themename, version, "Themes"); try
await logger.LogInformation("Theme Downloaded {ThemeName} {Version}", themename, version); {
await ThemeService.InstallThemesAsync(); await PackageService.DownloadPackageAsync(themename, version, "Themes");
NavigationManager.NavigateTo(NavigateUrl()); await ThemeService.InstallThemesAsync();
await logger.LogInformation("Theme Downloaded {ThemeName} {Version}", themename, version);
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Downloading Theme {ThemeName} {Version} {Error}", themename, version, ex.Message);
AddModuleMessage("Error Downloading Theme", MessageType.Error);
}
} }
private async Task DeleteTheme(Theme Theme) private async Task DeleteTheme(Theme Theme)
{ {
await ThemeService.DeleteThemeAsync(Theme.ThemeName); try
await logger.LogInformation("Theme Deleted {Theme}", Theme); {
NavigationManager.NavigateTo(NavigateUrl()); await ThemeService.DeleteThemeAsync(Theme.ThemeName);
await logger.LogInformation("Theme Deleted {Theme}", Theme);
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Deleting Theme {Theme} {Error}", Theme, ex.Message);
AddModuleMessage("Error Deleting Theme", MessageType.Error);
}
} }
} }

View File

@ -43,28 +43,54 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
List<Package> packages = await PackageService.GetPackagesAsync("framework"); try
_package = packages.FirstOrDefault();
if (_package != null)
{ {
_upgradeavailable = (Version.Parse(_package.Version).CompareTo(Version.Parse(Constants.Version)) > 0); List<Package> packages = await PackageService.GetPackagesAsync("framework");
if (packages != null)
{
_package = packages.FirstOrDefault();
if (_package != null)
{
_upgradeavailable = (Version.Parse(_package.Version).CompareTo(Version.Parse(Constants.Version)) > 0);
}
else
{
_package = new Package { Name = Constants.PackageId, Version = Constants.Version };
}
}
} }
else catch
{ {
_package = new Package { Name = Constants.PackageId, Version = Constants.Version }; // can be caused by no network connection
} }
} }
private async Task Upgrade() private async Task Upgrade()
{ {
await InstallationService.Upgrade(); try
NavigationManager.NavigateTo(NavigateUrl()); {
await InstallationService.Upgrade();
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Executing Upgrade {Error}", ex.Message);
AddModuleMessage("Error Executing Upgrade", MessageType.Error);
}
} }
private async Task Download(string packageid, string version) private async Task Download(string packageid, string version)
{ {
await PackageService.DownloadPackageAsync(packageid, version, "Framework"); try
await InstallationService.Upgrade(); {
NavigationManager.NavigateTo(NavigateUrl()); await PackageService.DownloadPackageAsync(packageid, version, "Framework");
await InstallationService.Upgrade();
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Downloading Framework {Error}", ex.Message);
AddModuleMessage("Error Downloading Framework", MessageType.Error);
}
} }
} }