mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-01 08:23:42 -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:
@ -18,7 +18,7 @@ namespace Observatory.Framework
|
||||
/// </summary>
|
||||
public object journalEvent;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Provides values used as arguments for Observatory notification events.
|
||||
/// </summary>
|
||||
@ -69,4 +69,40 @@ namespace Observatory.Framework
|
||||
PluginNotifier = 4,
|
||||
All = (NativeVisual | NativeVocal | PluginNotifier)
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum LogMonitorState : uint
|
||||
{
|
||||
// These need to be multiples of 2 as they're used via masking.
|
||||
Idle = 0, // Monitoring is stopped
|
||||
Realtime = 1, // Real-time monitoring is active
|
||||
Batch = 2, // Performing a batch read of history
|
||||
PreRead = 4 // Currently pre-reading current system context (a batch read)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides information about a LogMonitor state transition.
|
||||
/// </summary>
|
||||
public class LogMonitorStateChangedEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The previous LogMonitor state.
|
||||
/// </summary>
|
||||
public LogMonitorState PreviousState;
|
||||
|
||||
/// <summary>
|
||||
/// The new, current LogMonitor state.
|
||||
/// </summary>
|
||||
public LogMonitorState NewState;
|
||||
|
||||
/// <summary>
|
||||
/// Determins if the given state is a batch read of any form.
|
||||
/// </summary>
|
||||
/// <param name="state">The state to evaluate</param>
|
||||
/// <returns>A boolean; True iff the state provided represents a batch-mode read.</returns>
|
||||
public static bool IsBatchRead(LogMonitorState state)
|
||||
{
|
||||
return (state & (LogMonitorState.Batch | LogMonitorState.PreRead)) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,11 +76,19 @@ namespace Observatory.Framework.Interfaces
|
||||
public void StatusChange(Status status)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Called when the LogMonitor changes state. Useful for suppressing output in certain situations
|
||||
/// such as batch reads (ie. "Read all") or responding to other state transitions.
|
||||
/// </summary>
|
||||
public void LogMonitorStateChanged(LogMonitorStateChangedEventArgs eventArgs)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Method called when the user begins "Read All" journal processing, before any journal events are sent.<br/>
|
||||
/// Used to track if a "Read All" operation is in progress or not to avoid unnecessary processing or notifications.<br/>
|
||||
/// Can be omitted for plugins which do not require the distinction.
|
||||
/// </summary>
|
||||
[Obsolete] // Replaced by LogMonitorStateChanged
|
||||
public void ReadAllStarted()
|
||||
{ }
|
||||
|
||||
@ -89,6 +97,7 @@ namespace Observatory.Framework.Interfaces
|
||||
/// Used to track if a "Read All" operation is in progress or not to avoid unnecessary processing or notifications.<br/>
|
||||
/// Can be omitted for plugins which do not require the distinction.
|
||||
/// </summary>
|
||||
[Obsolete] // Replaced by LogMonitorStateChanged
|
||||
public void ReadAllFinished()
|
||||
{ }
|
||||
}
|
||||
@ -175,5 +184,15 @@ namespace Observatory.Framework.Interfaces
|
||||
/// Shared application HttpClient object. Provided so that plugins can adhere to .NET recommended behaviour of a single HttpClient object per application.
|
||||
/// </summary>
|
||||
public HttpClient HttpClient { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current LogMonitor state.
|
||||
/// </summary>
|
||||
public LogMonitorState CurrentLogMonitorState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the current LogMonitor state represents a batch-read mode.
|
||||
/// </summary>
|
||||
public bool IsLogMonitorBatchReading { get; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user