From fa5c978b34c6c347aa8edc7e1afa050d264dccf8 Mon Sep 17 00:00:00 2001 From: F K <54195004+fredjk-gh@users.noreply.github.com> Date: Tue, 15 Mar 2022 09:44:20 -0400 Subject: [PATCH] Revert PluginCore use of event listening for current LogMonitor state (#64) The order that listeners get notified isn't deterministic and as a result plugins which read the current state from PluginCore during the handling of a state change event may read a stale state resulting in unexpected results. PluginCore now reads a property directly from LogMonitor to avoid such inconsistencies. --- ObservatoryCore/LogMonitor.cs | 7 +++++++ ObservatoryCore/PluginManagement/PluginCore.cs | 10 ++-------- ObservatoryCore/PluginManagement/PluginManager.cs | 1 - 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ObservatoryCore/LogMonitor.cs b/ObservatoryCore/LogMonitor.cs index 63997e7..4bf1b6b 100644 --- a/ObservatoryCore/LogMonitor.cs +++ b/ObservatoryCore/LogMonitor.cs @@ -38,6 +38,13 @@ namespace Observatory #endregion + #region Public properties + public LogMonitorState CurrentState + { + get => currentState; + } + #endregion + #region Public Methods public void Start() diff --git a/ObservatoryCore/PluginManagement/PluginCore.cs b/ObservatoryCore/PluginManagement/PluginCore.cs index 75c55da..c7b046a 100644 --- a/ObservatoryCore/PluginManagement/PluginCore.cs +++ b/ObservatoryCore/PluginManagement/PluginCore.cs @@ -11,7 +11,6 @@ namespace Observatory.PluginManagement private readonly NativeVoice NativeVoice; private readonly NativePopup NativePopup; - private LogMonitorState currentLogMonitorState = LogMonitorState.Idle; public PluginCore() { @@ -19,11 +18,6 @@ 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() @@ -142,12 +136,12 @@ namespace Observatory.PluginManagement public LogMonitorState CurrentLogMonitorState { - get => currentLogMonitorState; + get => LogMonitor.GetInstance.CurrentState; } public bool IsLogMonitorBatchReading { - get => LogMonitorStateChangedEventArgs.IsBatchRead(currentLogMonitorState); + get => LogMonitorStateChangedEventArgs.IsBatchRead(LogMonitor.GetInstance.CurrentState); } public event EventHandler Notification; diff --git a/ObservatoryCore/PluginManagement/PluginManager.cs b/ObservatoryCore/PluginManagement/PluginManager.cs index 9da4ab1..fac30c0 100644 --- a/ObservatoryCore/PluginManagement/PluginManager.cs +++ b/ObservatoryCore/PluginManagement/PluginManager.cs @@ -49,7 +49,6 @@ namespace Observatory.PluginManagement logMonitor.LogMonitorStateChanged += pluginHandler.OnLogMonitorStateChanged; var core = new PluginCore(); - logMonitor.LogMonitorStateChanged += core.OnLogMonitorStateChanged; List errorPlugins = new();