mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Integrates the plugin system into the host and the media library scan pipeline
This commit is contained in:
1 parent
f71e72a948
commit
6f501a51f3
45 files changed
+1268
-370
No files matched your search
-21
@@ -1,21 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Hooks;
|
||||
|
||||
/// <summary>
|
||||
/// Registry of the media library scan jobs that are injected by plugins at the defined hook points of the media library scan job graph.
|
||||
/// </summary>
|
||||
public interface IScanJobRegistry
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the media library scan jobs registered for the provided <paramref name="hookName"/>.
|
||||
/// </summary>
|
||||
/// <param name="hookName">The name of the hook point at which the media library scan jobs were injected.</param>
|
||||
/// <param name="libraryId">The unique identifier of the media library upon which the scan is performed.</param>
|
||||
/// <returns>The collection of media library scan jobs registered at the provided hook point.</returns>
|
||||
IEnumerable<IMediaLibraryScanJob> GetJobsForHook(string hookName, LibraryId libraryId);
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Hooks;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the named junction points of the media library scan job graph where plugin jobs can be injected.
|
||||
/// </summary>
|
||||
public static class ScanJobHooks
|
||||
{
|
||||
/// <summary>
|
||||
/// The hook that runs after the file system discovery job, and before the scan diff job.
|
||||
/// </summary>
|
||||
public const string AFTER_FILE_SYSTEM_DISCOVERY = "AfterFileSystemDiscovery";
|
||||
|
||||
/// <summary>
|
||||
/// The hook that runs after the scan diff job, and before the scan hash job.
|
||||
/// </summary>
|
||||
public const string AFTER_SCAN_DIFF = "AfterScanDiff";
|
||||
|
||||
/// <summary>
|
||||
/// The hook that runs after the scan hash job, and before any metadata enrichment jobs.
|
||||
/// </summary>
|
||||
public const string BEFORE_METADATA_ENRICHMENT = "BeforeMetadataEnrichment";
|
||||
|
||||
/// <summary>
|
||||
/// The hook that runs after any metadata enrichment jobs, and before the scan results save job.
|
||||
/// </summary>
|
||||
public const string AFTER_METADATA_ENRICHMENT = "AfterMetadataEnrichment";
|
||||
|
||||
/// <summary>
|
||||
/// The hook that runs before the scan results save job, which should always be the last job in the directed acyclic job graph.
|
||||
/// </summary>
|
||||
public const string BEFORE_SCAN_RESULTS_SAVE = "BeforeScanResultsSave";
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the media library scan job for enriching the metadata of the media library items.
|
||||
/// </summary>
|
||||
public interface IMediaLibraryScanMetadataEnrichmentJob : IMediaLibraryScanJob
|
||||
{
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,7 +15,7 @@ public interface IMediaTypeScanner
|
||||
/// <summary>
|
||||
/// The media library type that this media library scanner supports.
|
||||
/// </summary>
|
||||
LibraryType SupportedType { get; }
|
||||
LibraryType SupportedLibraryType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates the media library scan jobs for the provided media library.
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the media library scan job for retrieving written content metadata from GoodReads.
|
||||
/// </summary>
|
||||
public interface IGoodReadsMetadataScrapJob : IMediaLibraryScanJob
|
||||
{
|
||||
}
|
||||
+16
-43
@@ -1,9 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Hooks;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
@@ -15,22 +14,19 @@ namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext
|
||||
internal class BookLibraryTypeScanner : IBookLibraryTypeScanner
|
||||
{
|
||||
private readonly IMediaLibraryScanJobFactory _mediaScanJobFactory;
|
||||
private readonly IScanJobRegistry _scanJobRegistry;
|
||||
|
||||
/// <summary>
|
||||
/// The media library type that this media library scanner supports.
|
||||
/// </summary>
|
||||
public LibraryType SupportedType { get; } = LibraryType.Book;
|
||||
public LibraryType SupportedLibraryType { get; } = LibraryType.Book;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookLibraryTypeScanner"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediaScanJobFactory">Injected factory for creating media library scan jobs.</param>
|
||||
/// <param name="scanJobRegistry">Injected registry of the media library scan jobs injected by plugins at the defined hook points.</param>
|
||||
public BookLibraryTypeScanner(IMediaLibraryScanJobFactory mediaScanJobFactory, IScanJobRegistry scanJobRegistry)
|
||||
public BookLibraryTypeScanner(IMediaLibraryScanJobFactory mediaScanJobFactory)
|
||||
{
|
||||
_mediaScanJobFactory = mediaScanJobFactory;
|
||||
_scanJobRegistry = scanJobRegistry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,51 +41,28 @@ internal class BookLibraryTypeScanner : IBookLibraryTypeScanner
|
||||
IBooksFileSystemDiscoveryJob fileSystemDiscoveryJob = _mediaScanJobFactory.CreateJob<IBooksFileSystemDiscoveryJob>(libraryId);
|
||||
IMediaLibraryScanDiffJob mediaLibraryScanDiffJob = _mediaScanJobFactory.CreateJob<IMediaLibraryScanDiffJob>(libraryId);
|
||||
IMediaLibraryScanHashJob mediaLibraryScanHashJob = _mediaScanJobFactory.CreateJob<IMediaLibraryScanHashJob>(libraryId);
|
||||
IGoodReadsMetadataScrapJob goodReadsMetadataScrapJob = _mediaScanJobFactory.CreateJob<IGoodReadsMetadataScrapJob>(libraryId);
|
||||
IMediaLibraryScanResultsSaveJob mediaLibraryScanResultsSaveJob = _mediaScanJobFactory.CreateJob<IMediaLibraryScanResultsSaveJob>(libraryId);
|
||||
|
||||
// establish the hierarchical relationships between jobs, splicing the plugin jobs at the defined hook points
|
||||
IMediaLibraryScanJob previousJob = fileSystemDiscoveryJob;
|
||||
previousJob = SpliceJobsAtHook(previousJob, ScanJobHooks.AFTER_FILE_SYSTEM_DISCOVERY, libraryId);
|
||||
previousJob.AddChild(mediaLibraryScanDiffJob);
|
||||
mediaLibraryScanDiffJob.AddParent(previousJob);
|
||||
// establish the hierarchical relationships between jobs
|
||||
fileSystemDiscoveryJob.AddChild(mediaLibraryScanDiffJob);
|
||||
mediaLibraryScanDiffJob.AddParent(fileSystemDiscoveryJob);
|
||||
|
||||
previousJob = SpliceJobsAtHook(mediaLibraryScanDiffJob, ScanJobHooks.AFTER_SCAN_DIFF, libraryId);
|
||||
previousJob.AddChild(mediaLibraryScanHashJob);
|
||||
mediaLibraryScanHashJob.AddParent(previousJob);
|
||||
mediaLibraryScanDiffJob.AddChild(mediaLibraryScanHashJob);
|
||||
mediaLibraryScanHashJob.AddParent(mediaLibraryScanDiffJob);
|
||||
|
||||
previousJob = SpliceJobsAtHook(mediaLibraryScanHashJob, ScanJobHooks.BEFORE_METADATA_ENRICHMENT, libraryId);
|
||||
mediaLibraryScanHashJob.AddChild(mediaLibraryScanResultsSaveJob);
|
||||
mediaLibraryScanResultsSaveJob.AddParent(mediaLibraryScanHashJob);
|
||||
|
||||
// when the library permits downloading data from the web, the metadata enrichment job is the last job in the directed acyclic job graph,
|
||||
// running after the scan results save job, so that the books are materialized before their metadata is enriched
|
||||
if (downloadMetadataFromWeb)
|
||||
{
|
||||
previousJob.AddChild(goodReadsMetadataScrapJob);
|
||||
goodReadsMetadataScrapJob.AddParent(previousJob);
|
||||
previousJob = goodReadsMetadataScrapJob;
|
||||
IMediaLibraryScanMetadataEnrichmentJob mediaLibraryScanMetadataEnrichmentJob = _mediaScanJobFactory.CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(libraryId);
|
||||
mediaLibraryScanResultsSaveJob.AddChild(mediaLibraryScanMetadataEnrichmentJob);
|
||||
mediaLibraryScanMetadataEnrichmentJob.AddParent(mediaLibraryScanResultsSaveJob);
|
||||
}
|
||||
previousJob = SpliceJobsAtHook(previousJob, ScanJobHooks.AFTER_METADATA_ENRICHMENT, libraryId);
|
||||
previousJob = SpliceJobsAtHook(previousJob, ScanJobHooks.BEFORE_SCAN_RESULTS_SAVE, libraryId);
|
||||
previousJob.AddChild(mediaLibraryScanResultsSaveJob);
|
||||
mediaLibraryScanResultsSaveJob.AddParent(previousJob);
|
||||
|
||||
// return the top level jobs that will be triggered when the scan will be started
|
||||
yield return fileSystemDiscoveryJob;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Splices the plugin jobs registered at the provided <paramref name="hookName"/> after the <paramref name="previousJob"/>, and returns the last job of the extended chain.
|
||||
/// </summary>
|
||||
/// <param name="previousJob">The job after which the plugin jobs are spliced.</param>
|
||||
/// <param name="hookName">The name of the hook point at which the plugin jobs are injected.</param>
|
||||
/// <param name="libraryId">The unique identifier of the media library upon which the scan is performed.</param>
|
||||
/// <returns>The last job of the extended chain, which can be used as the parent for the next job.</returns>
|
||||
private IMediaLibraryScanJob SpliceJobsAtHook(IMediaLibraryScanJob previousJob, string hookName, LibraryId libraryId)
|
||||
{
|
||||
IMediaLibraryScanJob currentJob = previousJob;
|
||||
foreach (IMediaLibraryScanJob pluginJob in _scanJobRegistry.GetJobsForHook(hookName, libraryId))
|
||||
{
|
||||
currentJob.AddChild(pluginJob);
|
||||
pluginJob.AddParent(currentJob);
|
||||
currentJob = pluginJob;
|
||||
}
|
||||
return currentJob;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user