Fixed control logic.

This commit is contained in:
Michael Bucari-Tovo 2021-08-12 00:13:33 -06:00
parent 265ad3a782
commit cd67e7136b
3 changed files with 21 additions and 8 deletions

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> --> <!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>5.4.9.258</Version> <Version>5.4.9.264</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@ -14,22 +14,25 @@ namespace LibationWinForms.BookLiberation
if (Streamable is not null && Streamable is IProcessable processable) if (Streamable is not null && Streamable is IProcessable processable)
{ {
OnUnsubscribeAll(this, EventArgs.Empty); OnUnsubscribeAll(this, null);
processable.Begin += OnBegin; processable.Begin += OnBegin;
processable.Completed += OnCompleted; processable.Completed += OnCompleted;
processable.StatusUpdate += OnStatusUpdate; 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) if (Streamable is IProcessable processable)
{ {
processable.Completed -= OnUnsubscribeAll;
processable.Begin -= OnBegin; processable.Begin -= OnBegin;
processable.Completed -= OnCompleted; processable.Completed -= OnCompleted;
processable.StatusUpdate -= OnStatusUpdate; processable.StatusUpdate -= OnStatusUpdate;
@ -39,7 +42,17 @@ namespace LibationWinForms.BookLiberation
#region IProcessable event handlers #region IProcessable event handlers
public virtual void OnBegin(object sender, LibraryBook libraryBook) => LogMe.Info($"Begin: {libraryBook.Book}"); 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 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 #endregion
} }
} }

View File

@ -149,8 +149,8 @@ namespace LibationWinForms.BookLiberation
processForm.OnBegin(sender, libraryBook); processForm.OnBegin(sender, libraryBook);
}; };
if (completedAction != null) //if (completedAction != null)
strProc.Completed += completedAction; // strProc.Completed += completedAction;
return strProc; return strProc;
} }