improved error handling, improved consistency of console error messages, added ability to add a Decimal column in Migrations

This commit is contained in:
Shaun Walker 2021-06-18 13:01:42 -04:00
parent 32c49f74d3
commit 3bc5744007
10 changed files with 53 additions and 23 deletions

View File

@ -15,6 +15,7 @@ using Microsoft.Extensions.Caching.Memory;
using System.Net; using System.Net;
using Oqtane.Repository; using Oqtane.Repository;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using System.Diagnostics;
namespace Oqtane.Controllers namespace Oqtane.Controllers
{ {
@ -130,7 +131,7 @@ namespace Oqtane.Controllers
} }
else else
{ {
Console.WriteLine($"The satellite assemblies folder named '{culture}' is not found."); Debug.WriteLine($"Oqtane Error: The Satellite Assembly Folder For {culture} Does Not Exist");
} }
} }
@ -148,7 +149,7 @@ namespace Oqtane.Controllers
} }
else else
{ {
Console.WriteLine("Module " + instance.ModuleDefinition.ModuleDefinitionName + " dependency " + name + ".dll does not exist"); Debug.WriteLine($"Oqtane Error: Module {instance.ModuleDefinition.ModuleDefinitionName} Dependency {name}.dll Does Not Exist");
} }
} }
} }
@ -163,7 +164,7 @@ namespace Oqtane.Controllers
} }
else else
{ {
Console.WriteLine("Theme " + instance.Theme.ThemeName + " dependency " + name + ".dll does not exist" ); Debug.WriteLine($"Oqtane Error: Theme {instance.Theme.ThemeName} Dependency {name}.dll Does Not Exist");
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
@ -257,7 +258,7 @@ namespace Microsoft.Extensions.DependencyInjection
} }
catch catch
{ {
Console.WriteLine($"Not Assembly : {dll.Name}"); Debug.WriteLine($"Oqtane Error: Cannot Get Assembly Name For {dll.Name}");
continue; continue;
} }
@ -298,24 +299,24 @@ namespace Microsoft.Extensions.DependencyInjection
} }
catch catch
{ {
Console.WriteLine($"Not Satellite Assembly : {assemblyFile.Name}"); Debug.WriteLine($"Oqtane Error: Cannot Get Satellite Assembly Name For {assemblyFile.Name}");
continue; continue;
} }
try try
{ {
Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(assemblyFile.FullName))); Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(assemblyFile.FullName)));
Console.WriteLine($"Loaded : {assemblyName}"); Debug.WriteLine($"Oqtane Info: Loaded Assembly {assemblyName}");
} }
catch (Exception e) catch (Exception ex)
{ {
Console.WriteLine($"Failed : {assemblyName}\n{e}"); Debug.WriteLine($"Oqtane Error: Unable To Load Assembly {assemblyName} - {ex}");
} }
} }
} }
else else
{ {
Console.WriteLine($"The satellite assemblies folder named '{culture}' is not found."); Debug.WriteLine($"Oqtane Error: The Satellite Assembly Folder For {culture} Does Not Exist");
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -57,7 +58,7 @@ namespace Oqtane.Infrastructure
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine("Error modifying app settings {0}", ex); Debug.WriteLine($"Oqtane Error: Error Updating App Setting {key} - {ex}");
} }
} }
@ -78,7 +79,7 @@ namespace Oqtane.Infrastructure
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine("Error modifying app settings {0}", ex); Debug.WriteLine($"Oqtane Error: Error Removing App Setting {key} - {ex}");
} }
} }

View File

@ -483,11 +483,17 @@ namespace Oqtane.Infrastructure
{ {
tenantManager.SetTenant(tenant.TenantId); tenantManager.SetTenant(tenant.TenantId);
var moduleObject = ActivatorUtilities.CreateInstance(scope.ServiceProvider, moduleType) as IInstallable; var moduleObject = ActivatorUtilities.CreateInstance(scope.ServiceProvider, moduleType) as IInstallable;
moduleObject?.Install(tenant, versions[i]); if (moduleObject == null || !moduleObject.Install(tenant, versions[i]))
{
result.Message = "An Error Occurred Executing IInstallable Interface For " + moduleDefinition.ServerManagerType;
}
} }
else else
{ {
sql.ExecuteScript(tenant, moduleType.Assembly, Utilities.GetTypeName(moduleDefinition.ModuleDefinitionName) + "." + versions[i] + ".sql"); if (!sql.ExecuteScript(tenant, moduleType.Assembly, Utilities.GetTypeName(moduleDefinition.ModuleDefinitionName) + "." + versions[i] + ".sql"))
{
result.Message = "An Error Occurred Executing Database Script " + Utilities.GetTypeName(moduleDefinition.ModuleDefinitionName) + "." + versions[i] + ".sql";
}
} }
} }
catch (Exception ex) catch (Exception ex)

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.NetworkInformation;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations;
using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders;
@ -109,6 +110,16 @@ namespace Oqtane.Migrations.EntityBuilders
_migrationBuilder.AlterColumn<string>(RewriteName(name), RewriteName(EntityTableName), maxLength: length, nullable: nullable, unicode: unicode); _migrationBuilder.AlterColumn<string>(RewriteName(name), RewriteName(EntityTableName), maxLength: length, nullable: nullable, unicode: unicode);
} }
public void AddDecimalColumn(string name, int precision, int scale, bool nullable = false)
{
_migrationBuilder.AddColumn<decimal>(RewriteName(name), RewriteName(EntityTableName), nullable: nullable, precision: precision, scale: scale);
}
protected OperationBuilder<AddColumnOperation> AddDecimalColumn(ColumnsBuilder table, string name, int precision, int scale, bool nullable = false)
{
return table.Column<decimal>(name: RewriteName(name), nullable: nullable, precision: precision, scale: scale);
}
public void DropColumn(string name) public void DropColumn(string name)
{ {
_migrationBuilder.DropColumn(RewriteName(name), RewriteName(EntityTableName)); _migrationBuilder.DropColumn(RewriteName(name), RewriteName(EntityTableName));

View File

@ -1,10 +1,10 @@
using System; using System;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Oqtane.Enums; using Oqtane.Enums;
using Oqtane.Models; using Oqtane.Models;
using Oqtane.Repository; using Oqtane.Repository;
using Oqtane.Shared;
namespace Oqtane.Modules namespace Oqtane.Modules
{ {
@ -28,9 +28,9 @@ namespace Oqtane.Modules
migrator.Migrate(); migrator.Migrate();
} }
} }
catch (Exception e) catch (Exception ex)
{ {
Console.WriteLine(e); Debug.WriteLine($"Oqtane Error: Error Executing Migration - {ex}");
result = false; result = false;
} }

View File

@ -1,9 +1,10 @@
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore; using Microsoft.AspNetCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Oqtane.Infrastructure; using Oqtane.Infrastructure;
using System.Diagnostics;
namespace Oqtane.Server namespace Oqtane.Server
{ {
@ -15,7 +16,11 @@ namespace Oqtane.Server
using (var serviceScope = host.Services.GetRequiredService<IServiceScopeFactory>().CreateScope()) using (var serviceScope = host.Services.GetRequiredService<IServiceScopeFactory>().CreateScope())
{ {
var databaseManager = serviceScope.ServiceProvider.GetService<IDatabaseManager>(); var databaseManager = serviceScope.ServiceProvider.GetService<IDatabaseManager>();
databaseManager.Install(); var install = databaseManager.Install();
if (!string.IsNullOrEmpty(install.Message))
{
Debug.WriteLine($"Oqtane Error: {install.Message}");
}
} }
host.Run(); host.Run();
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -264,7 +265,7 @@ namespace Oqtane.Repository
}.EncodePermissions(); }.EncodePermissions();
} }
Console.WriteLine($"Registering module: {moduledefinition.ModuleDefinitionName}"); Debug.WriteLine($"Oqtane Info: Registering Module {moduledefinition.ModuleDefinitionName}");
moduledefinitions.Add(moduledefinition); moduledefinitions.Add(moduledefinition);
index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType); index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -104,6 +105,8 @@ namespace Oqtane.Repository
{ {
theme.PackageName = Utilities.GetTypeName(theme.ThemeName); theme.PackageName = Utilities.GetTypeName(theme.ThemeName);
} }
Debug.WriteLine($"Oqtane Info: Registering Theme {theme.ThemeName}");
themes.Add(theme); themes.Add(theme);
index = themes.FindIndex(item => item.ThemeName == qualifiedThemeType); index = themes.FindIndex(item => item.ThemeName == qualifiedThemeType);
} }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.Loader; using System.Runtime.Loader;
@ -100,7 +101,7 @@ namespace System.Reflection
} }
catch catch
{ {
Console.WriteLine($"Not Assembly : {dll.Name}"); Debug.WriteLine($"Oqtane Error: Cannot Get Assembly Name For {dll.Name}");
} }
loadContext.LoadOqtaneAssembly(dll, assemblyName); loadContext.LoadOqtaneAssembly(dll, assemblyName);
@ -122,11 +123,11 @@ namespace System.Reflection
{ {
assembly = loadContext.LoadFromStream(new MemoryStream(File.ReadAllBytes(dll.FullName))); assembly = loadContext.LoadFromStream(new MemoryStream(File.ReadAllBytes(dll.FullName)));
} }
Console.WriteLine($"Loaded : {assemblyName}"); Debug.WriteLine($"Oqtane Info: Loaded Assembly {assemblyName}");
} }
catch (Exception e) catch (Exception ex)
{ {
Console.WriteLine($"Failed : {assemblyName}\n{e}"); Debug.WriteLine($"Oqtane Error: Unable To Load Assembly {assemblyName} - {ex}");
} }
} }
} }