From cd67e7136b7e161b61e5e168fac273792fdababc Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Thu, 12 Aug 2021 00:13:33 -0600 Subject: [PATCH] Fixed control logic. --- LibationLauncher/LibationLauncher.csproj | 2 +- .../BaseForms/ProcessBaseForm.cs | 23 +++++++++++++++---- .../ProcessorAutomationController.cs | 4 ++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 390110a8..7f4ef331 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 5.4.9.258 + 5.4.9.264 diff --git a/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs b/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs index f97825c6..e078c03a 100644 --- a/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs +++ b/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs @@ -14,22 +14,25 @@ namespace LibationWinForms.BookLiberation if (Streamable is not null && Streamable is IProcessable processable) { - OnUnsubscribeAll(this, EventArgs.Empty); + OnUnsubscribeAll(this, null); processable.Begin += OnBegin; processable.Completed += OnCompleted; processable.StatusUpdate += OnStatusUpdate; - Disposed += OnUnsubscribeAll; + //Don't unsubscribe from Dispose because it fires on + //IStreamable.StreamingCompleted, and the IProcessable + //events need to live past that. + processable.Completed += OnUnsubscribeAll; } } - private void OnUnsubscribeAll(object sender, EventArgs e) + private void OnUnsubscribeAll(object sender, LibraryBook e) { - Disposed -= OnUnsubscribeAll; if (Streamable is IProcessable processable) { + processable.Completed -= OnUnsubscribeAll; processable.Begin -= OnBegin; processable.Completed -= OnCompleted; processable.StatusUpdate -= OnStatusUpdate; @@ -39,7 +42,17 @@ namespace LibationWinForms.BookLiberation #region IProcessable event handlers public virtual void OnBegin(object sender, LibraryBook libraryBook) => LogMe.Info($"Begin: {libraryBook.Book}"); public virtual void OnStatusUpdate(object sender, string statusUpdate) => LogMe.Info("- " + statusUpdate); - public virtual void OnCompleted(object sender, LibraryBook libraryBook) => LogMe.Info($"Completed: {libraryBook.Book}{Environment.NewLine}"); + public virtual void OnCompleted(object sender, LibraryBook libraryBook) + { + LogMe.Info($"Completed: {libraryBook.Book}{Environment.NewLine}"); + + if (Streamable is IProcessable processable) + { + processable.Begin -= OnBegin; + processable.Completed -= OnCompleted; + processable.StatusUpdate -= OnStatusUpdate; + } + } #endregion } } diff --git a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs index 1575be89..c095a92a 100644 --- a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs +++ b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs @@ -149,8 +149,8 @@ namespace LibationWinForms.BookLiberation processForm.OnBegin(sender, libraryBook); }; - if (completedAction != null) - strProc.Completed += completedAction; + //if (completedAction != null) + // strProc.Completed += completedAction; return strProc; }