From 44bb192ce0e286ced703394f733ca033b489ebc5 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 9 Feb 2014 18:08:01 -0500 Subject: update wizard function of enable/disable local metadata saving --- .../Library/LibraryManager.cs | 92 ++++------------------ .../Library/Validators/PeopleValidator.cs | 62 +-------------- 2 files changed, 15 insertions(+), 139 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library') diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 49b2ad562..92d7a4a90 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -38,24 +38,13 @@ namespace MediaBrowser.Server.Implementations.Library /// Gets or sets the postscan tasks. /// /// The postscan tasks. - private IEnumerable PostscanTasks { get; set; } - /// - /// Gets or sets the prescan tasks. - /// - /// The prescan tasks. - private IEnumerable PrescanTasks { get; set; } - - /// - /// Gets or sets the people prescan tasks. - /// - /// The people prescan tasks. - private IEnumerable PeoplePrescanTasks { get; set; } + private ILibraryPostScanTask[] PostscanTasks { get; set; } /// /// Gets the intro providers. /// /// The intro providers. - private IEnumerable IntroProviders { get; set; } + private IIntroProvider[] IntroProviders { get; set; } /// /// Gets the list of entity resolution ignore rules @@ -205,26 +194,27 @@ namespace MediaBrowser.Server.Implementations.Library /// The resolvers. /// The intro providers. /// The item comparers. - /// The prescan tasks. /// The postscan tasks. - /// The people prescan tasks. public void AddParts(IEnumerable rules, IEnumerable pluginFolders, IEnumerable resolvers, IEnumerable introProviders, IEnumerable itemComparers, - IEnumerable prescanTasks, - IEnumerable postscanTasks, - IEnumerable peoplePrescanTasks) + IEnumerable postscanTasks) { EntityResolutionIgnoreRules = rules.ToArray(); PluginFolderCreators = pluginFolders.ToArray(); EntityResolvers = resolvers.OrderBy(i => i.Priority).ToArray(); - IntroProviders = introProviders; + IntroProviders = introProviders.ToArray(); Comparers = itemComparers.ToArray(); - PrescanTasks = prescanTasks; - PostscanTasks = postscanTasks; - PeoplePrescanTasks = peoplePrescanTasks; + + PostscanTasks = postscanTasks.OrderBy(i => + { + var hasOrder = i as IHasOrder; + + return hasOrder == null ? 0 : hasOrder.Order; + + }).ToArray(); } /// @@ -845,7 +835,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Task. public Task ValidatePeople(CancellationToken cancellationToken, IProgress progress) { - return new PeopleValidator(this, PeoplePrescanTasks, _logger).ValidatePeople(cancellationToken, progress); + return new PeopleValidator(this, _logger).ValidatePeople(cancellationToken, progress); } /// @@ -970,14 +960,9 @@ namespace MediaBrowser.Server.Implementations.Library innerProgress.RegisterAction(pct => progress.Report(2 + pct * .13)); - // Run prescan tasks - await RunPrescanTasks(innerProgress, cancellationToken).ConfigureAwait(false); - - progress.Report(15); - innerProgress = new ActionableProgress(); - innerProgress.RegisterAction(pct => progress.Report(15 + pct * .6)); + innerProgress.RegisterAction(pct => progress.Report(2 + pct * .73)); // Now validate the entire media library await RootFolder.ValidateChildren(innerProgress, cancellationToken, new MetadataRefreshOptions(), recursive: true).ConfigureAwait(false); @@ -998,55 +983,6 @@ namespace MediaBrowser.Server.Implementations.Library GC.Collect(2, GCCollectionMode.Forced, true); } - /// - /// Runs the prescan tasks. - /// - /// The progress. - /// The cancellation token. - /// Task. - private async Task RunPrescanTasks(IProgress progress, CancellationToken cancellationToken) - { - var tasks = PrescanTasks.ToList(); - - var numComplete = 0; - var numTasks = tasks.Count; - - foreach (var task in tasks) - { - var innerProgress = new ActionableProgress(); - - // Prevent access to modified closure - var currentNumComplete = numComplete; - - innerProgress.RegisterAction(pct => - { - double innerPercent = (currentNumComplete * 100) + pct; - innerPercent /= numTasks; - progress.Report(innerPercent); - }); - - try - { - await task.Run(innerProgress, cancellationToken); - } - catch (OperationCanceledException) - { - _logger.Info("Pre-scan task cancelled: {0}", task.GetType().Name); - } - catch (Exception ex) - { - _logger.ErrorException("Error running pre-scan task", ex); - } - - numComplete++; - double percent = numComplete; - percent /= numTasks; - progress.Report(percent * 100); - } - - progress.Report(100); - } - /// /// Runs the post scan tasks. /// diff --git a/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs index 26e9a23e9..268bccd7a 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs @@ -3,7 +3,6 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; using MoreLinq; using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -24,19 +23,15 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// private readonly ILogger _logger; - private readonly IEnumerable _prescanTasks; - /// /// Initializes a new instance of the class. /// /// The library manager. - /// The prescan tasks. /// The logger. - public PeopleValidator(ILibraryManager libraryManager, IEnumerable prescanTasks, ILogger logger) + public PeopleValidator(ILibraryManager libraryManager, ILogger logger) { _libraryManager = libraryManager; _logger = logger; - _prescanTasks = prescanTasks; } /// @@ -51,11 +46,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators innerProgress.RegisterAction(pct => progress.Report(pct * .15)); - // Run prescan tasks - await RunPrescanTasks(innerProgress, cancellationToken).ConfigureAwait(false); - - progress.Report(15); - var people = _libraryManager.RootFolder.GetRecursiveChildren() .SelectMany(c => c.People) .DistinctBy(p => p.Name, StringComparer.OrdinalIgnoreCase) @@ -94,55 +84,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators GC.Collect(2, GCCollectionMode.Forced, true); GC.Collect(2, GCCollectionMode.Forced, true); } - - /// - /// Runs the prescan tasks. - /// - /// The progress. - /// The cancellation token. - /// Task. - private async Task RunPrescanTasks(IProgress progress, CancellationToken cancellationToken) - { - var tasks = _prescanTasks.ToList(); - - var numComplete = 0; - var numTasks = tasks.Count; - - foreach (var task in tasks) - { - var innerProgress = new ActionableProgress(); - - // Prevent access to modified closure - var currentNumComplete = numComplete; - - innerProgress.RegisterAction(pct => - { - double innerPercent = (currentNumComplete * 100) + pct; - innerPercent /= numTasks; - progress.Report(innerPercent); - }); - - try - { - await task.Run(innerProgress, cancellationToken); - } - catch (OperationCanceledException) - { - _logger.Info("Pre-scan task cancelled: {0}", task.GetType().Name); - break; - } - catch (Exception ex) - { - _logger.ErrorException("Error running pre-scan task", ex); - } - - numComplete++; - double percent = numComplete; - percent /= numTasks; - progress.Report(percent * 100); - } - - progress.Report(100); - } } } -- cgit v1.2.3