mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-01 16:33:43 -04:00
Add event-based LogMonitor state changes to better handle batch reads (#59)
* Add event-based LogMonitor state changes to better handle batch reads Pre-reading hackily used read-all to suppress notifications. But that broke some assumptions about what read-all meant. Furthermore, the Core UI told plugins about read-all rather than the log monitor telling them -- which is really what should be telling them. To address these concerns, LogMonitor now provides an event that both the PluginCore and PluginEventHandler listens to or tracking logging state allowing more granular information about the activities of LogMonitor, including distinguishing between ReadAll and Pre-read batches. Plugins no longer need to track if LogMonitor is in batch-read mode or not -- PluginCore now provides it. I've also converted all built-in plugins to use the new event-based system. The old system is marked deprecated and will go away once other known contributed plugins have converted to the new system. * Change LogMonitorState enum to [Flags], drop 'None' state As requested, and did associated simplifications and cleanup that followed.
This commit is contained in:
@ -11,6 +11,7 @@ namespace Observatory.PluginManagement
|
||||
|
||||
private readonly NativeVoice NativeVoice;
|
||||
private readonly NativePopup NativePopup;
|
||||
private LogMonitorState currentLogMonitorState = LogMonitorState.Idle;
|
||||
|
||||
public PluginCore()
|
||||
{
|
||||
@ -18,6 +19,11 @@ namespace Observatory.PluginManagement
|
||||
NativePopup = new();
|
||||
}
|
||||
|
||||
internal void OnLogMonitorStateChanged(object sender, LogMonitorStateChangedEventArgs e)
|
||||
{
|
||||
currentLogMonitorState = e.NewState;
|
||||
}
|
||||
|
||||
public string Version => System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString();
|
||||
|
||||
public Status GetStatus()
|
||||
@ -34,7 +40,7 @@ namespace Observatory.PluginManagement
|
||||
{
|
||||
var guid = Guid.Empty;
|
||||
|
||||
if (!LogMonitor.GetInstance.ReadAllInProgress())
|
||||
if (!IsLogMonitorBatchReading)
|
||||
{
|
||||
if (notificationArgs.Rendering.HasFlag(NotificationRendering.PluginNotifier))
|
||||
{
|
||||
@ -63,7 +69,7 @@ namespace Observatory.PluginManagement
|
||||
|
||||
public void UpdateNotification(Guid id, NotificationArgs notificationArgs)
|
||||
{
|
||||
if (!LogMonitor.GetInstance.ReadAllInProgress())
|
||||
if (!IsLogMonitorBatchReading)
|
||||
{
|
||||
|
||||
if (notificationArgs.Rendering.HasFlag(NotificationRendering.PluginNotifier))
|
||||
@ -134,6 +140,16 @@ namespace Observatory.PluginManagement
|
||||
get => Observatory.HttpClient.Client;
|
||||
}
|
||||
|
||||
public LogMonitorState CurrentLogMonitorState
|
||||
{
|
||||
get => currentLogMonitorState;
|
||||
}
|
||||
|
||||
public bool IsLogMonitorBatchReading
|
||||
{
|
||||
get => LogMonitorStateChangedEventArgs.IsBatchRead(currentLogMonitorState);
|
||||
}
|
||||
|
||||
public event EventHandler<NotificationArgs> Notification;
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,21 @@ namespace Observatory.PluginManagement
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnLogMonitorStateChanged(object sender, LogMonitorStateChangedEventArgs e)
|
||||
{
|
||||
foreach (var worker in observatoryWorkers)
|
||||
{
|
||||
try
|
||||
{
|
||||
worker.LogMonitorStateChanged(e);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RecordError(ex, worker.Name, "LogMonitorStateChanged event");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNotificationEvent(object source, NotificationArgs notificationArgs)
|
||||
{
|
||||
foreach (var notifier in observatoryNotifiers)
|
||||
|
@ -46,8 +46,10 @@ namespace Observatory.PluginManagement
|
||||
|
||||
logMonitor.JournalEntry += pluginHandler.OnJournalEvent;
|
||||
logMonitor.StatusUpdate += pluginHandler.OnStatusUpdate;
|
||||
logMonitor.LogMonitorStateChanged += pluginHandler.OnLogMonitorStateChanged;
|
||||
|
||||
var core = new PluginCore();
|
||||
logMonitor.LogMonitorStateChanged += core.OnLogMonitorStateChanged;
|
||||
|
||||
List<IObservatoryPlugin> errorPlugins = new();
|
||||
|
||||
|
Reference in New Issue
Block a user