mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-01 16:33:43 -04:00
observatory herald (#30)
* WIP: initial commit for observatory herald * Plugin error handling refactor * make error window non-modal * tidy up plugin error handling * first pass for basic herald functionality * corrections for linux env * Use FNV hash directly instead of managing through dictionary/index file * resolve audio queuing issue, switch to personal NetCoreAudio fork * merge cleanup * add enable setting, populate defaults * framework xml doc update * Adjust settings, add style selection, replace locale with demonym in dropdown list. * Test is position is on screen before saving/loading. * use a default that's actually in the list
This commit is contained in:
@ -14,18 +14,32 @@ namespace Observatory.PluginManagement
|
||||
{
|
||||
private IEnumerable<IObservatoryWorker> observatoryWorkers;
|
||||
private IEnumerable<IObservatoryNotifier> observatoryNotifiers;
|
||||
private List<string> errorList;
|
||||
|
||||
public PluginEventHandler(IEnumerable<IObservatoryWorker> observatoryWorkers, IEnumerable<IObservatoryNotifier> observatoryNotifiers)
|
||||
{
|
||||
this.observatoryWorkers = observatoryWorkers;
|
||||
this.observatoryNotifiers = observatoryNotifiers;
|
||||
errorList = new();
|
||||
}
|
||||
|
||||
public void OnJournalEvent(object source, JournalEventArgs journalEventArgs)
|
||||
{
|
||||
foreach (var worker in observatoryWorkers)
|
||||
{
|
||||
worker.JournalEvent((JournalBase)journalEventArgs.journalEvent);
|
||||
try
|
||||
{
|
||||
worker.JournalEvent((JournalBase)journalEventArgs.journalEvent);
|
||||
}
|
||||
catch (PluginException ex)
|
||||
{
|
||||
RecordError(ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RecordError(ex, worker.Name, journalEventArgs.journalType.Name);
|
||||
}
|
||||
ReportErrorsIfAny();
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +47,19 @@ namespace Observatory.PluginManagement
|
||||
{
|
||||
foreach (var worker in observatoryWorkers)
|
||||
{
|
||||
worker.StatusChange((Status)journalEventArgs.journalEvent);
|
||||
try
|
||||
{
|
||||
worker.StatusChange((Status)journalEventArgs.journalEvent);
|
||||
}
|
||||
catch (PluginException ex)
|
||||
{
|
||||
RecordError(ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RecordError(ex, worker.Name, journalEventArgs.journalType.Name);
|
||||
}
|
||||
ReportErrorsIfAny();
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +67,39 @@ namespace Observatory.PluginManagement
|
||||
{
|
||||
foreach (var notifier in observatoryNotifiers)
|
||||
{
|
||||
notifier.OnNotificationEvent(notificationArgs);
|
||||
try
|
||||
{
|
||||
notifier.OnNotificationEvent(notificationArgs);
|
||||
}
|
||||
catch (PluginException ex)
|
||||
{
|
||||
RecordError(ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RecordError(ex, notifier.Name, notificationArgs.Title);
|
||||
}
|
||||
ReportErrorsIfAny();
|
||||
}
|
||||
}
|
||||
|
||||
private void RecordError(PluginException ex)
|
||||
{
|
||||
errorList.Add($"Error in {ex.PluginName}: {ex.Message}");
|
||||
}
|
||||
|
||||
private void RecordError(Exception ex, string plugin, string eventType)
|
||||
{
|
||||
errorList.Add($"Error in {plugin} while handling {eventType}: {ex.Message}");
|
||||
}
|
||||
|
||||
private void ReportErrorsIfAny()
|
||||
{
|
||||
if (errorList.Any())
|
||||
{
|
||||
ErrorReporter.ShowErrorPopup($"Plugin Error{(errorList.Count > 1 ? "s" : "")}", string.Join(Environment.NewLine, errorList));
|
||||
|
||||
errorList.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Reflection;
|
||||
using System.Data;
|
||||
using Observatory.Framework.Interfaces;
|
||||
using System.IO;
|
||||
using System.Configuration;
|
||||
using Observatory.Framework;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Observatory.PluginManagement
|
||||
@ -39,11 +39,6 @@ namespace Observatory.PluginManagement
|
||||
{
|
||||
errorList = LoadPlugins(out workerPlugins, out notifyPlugins);
|
||||
|
||||
foreach (var error in errorList)
|
||||
{
|
||||
Console.WriteLine(error);
|
||||
}
|
||||
|
||||
var pluginHandler = new PluginEventHandler(workerPlugins.Select(p => p.plugin), notifyPlugins.Select(p => p.plugin));
|
||||
var logMonitor = LogMonitor.GetInstance;
|
||||
pluginPanels = new();
|
||||
@ -54,24 +49,53 @@ namespace Observatory.PluginManagement
|
||||
|
||||
var core = new PluginCore();
|
||||
|
||||
List<IObservatoryPlugin> errorPlugins = new();
|
||||
|
||||
foreach (var plugin in workerPlugins.Select(p => p.plugin))
|
||||
{
|
||||
LoadSettings(plugin);
|
||||
plugin.Load(core);
|
||||
try
|
||||
{
|
||||
LoadSettings(plugin);
|
||||
plugin.Load(core);
|
||||
}
|
||||
catch (PluginException ex)
|
||||
{
|
||||
errorList.Add(FormatErrorMessage(ex));
|
||||
errorPlugins.Add(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
workerPlugins.RemoveAll(w => errorPlugins.Contains(w.plugin));
|
||||
errorPlugins.Clear();
|
||||
|
||||
foreach (var plugin in notifyPlugins.Select(p => p.plugin))
|
||||
{
|
||||
// Notifiers which are also workers need not be loaded again (they are the same instance).
|
||||
if (!plugin.GetType().IsAssignableTo(typeof(IObservatoryWorker)))
|
||||
{
|
||||
LoadSettings(plugin);
|
||||
plugin.Load(core);
|
||||
try
|
||||
{
|
||||
LoadSettings(plugin);
|
||||
plugin.Load(core);
|
||||
}
|
||||
catch (PluginException ex)
|
||||
{
|
||||
errorList.Add(FormatErrorMessage(ex));
|
||||
errorPlugins.Add(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notifyPlugins.RemoveAll(n => errorPlugins.Contains(n.plugin));
|
||||
|
||||
core.Notification += pluginHandler.OnNotificationEvent;
|
||||
}
|
||||
|
||||
private static string FormatErrorMessage(PluginException ex)
|
||||
{
|
||||
return $"{ex.PluginName}: {ex.UserMessage}";
|
||||
}
|
||||
|
||||
private void LoadSettings(IObservatoryPlugin plugin)
|
||||
{
|
||||
string savedSettings = Properties.Core.Default.PluginSettings;
|
||||
|
Reference in New Issue
Block a user