Log errors when a plugin's control throws exceptions instead of just letting WPF die.

Also add some new types for Essentials
This commit is contained in:
Brant Martin
2019-06-25 16:47:54 -04:00
parent ae3d1262f5
commit 3f7e95b502
6 changed files with 450 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using NLog;
using Torch.API;
using Torch.API.Plugins;
using Torch.Server.Views;
@@ -17,13 +18,25 @@ namespace Torch.Server.ViewModels
public string Name { get; }
public ITorchPlugin Plugin { get; }
private static Logger _log = LogManager.GetCurrentClassLogger();
public PluginViewModel(ITorchPlugin plugin)
{
Plugin = plugin;
if (Plugin is IWpfPlugin p)
Control = p.GetControl();
{
try
{
Control = p.GetControl();
}
catch (Exception ex)
{
_log.Error(ex, $"Exception loading interface for plugin {Plugin.Name}! Plugin interface will not be available!");
Control = null;
}
}
Name = $"{plugin.Name} ({plugin.Version})";
ThemeControl.UpdateDynamicControls += UpdateResourceDict;