mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-26 10:44:50 +03:00
extracted provider manager. took more off the kernel
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
@@ -12,7 +11,7 @@ namespace MediaBrowser.Controller.Providers
|
||||
/// <summary>
|
||||
/// Class BaseMetadataProvider
|
||||
/// </summary>
|
||||
public abstract class BaseMetadataProvider : IDisposable
|
||||
public abstract class BaseMetadataProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the logger.
|
||||
@@ -27,16 +26,6 @@ namespace MediaBrowser.Controller.Providers
|
||||
/// <value>The configuration manager.</value>
|
||||
protected IServerConfigurationManager ConfigurationManager { get; private set; }
|
||||
|
||||
// Cache these since they will be used a lot
|
||||
/// <summary>
|
||||
/// The false task result
|
||||
/// </summary>
|
||||
protected static readonly Task<bool> FalseTaskResult = Task.FromResult(false);
|
||||
/// <summary>
|
||||
/// The true task result
|
||||
/// </summary>
|
||||
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
|
||||
|
||||
/// <summary>
|
||||
/// The _id
|
||||
/// </summary>
|
||||
@@ -135,7 +124,7 @@ namespace MediaBrowser.Controller.Providers
|
||||
/// <param name="providerVersion">The provider version.</param>
|
||||
/// <param name="status">The status.</param>
|
||||
/// <exception cref="System.ArgumentNullException">item</exception>
|
||||
protected virtual void SetLastRefreshed(BaseItem item, DateTime value, string providerVersion, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
|
||||
public virtual void SetLastRefreshed(BaseItem item, DateTime value, string providerVersion, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
@@ -162,7 +151,7 @@ namespace MediaBrowser.Controller.Providers
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="status">The status.</param>
|
||||
protected virtual void SetLastRefreshed(BaseItem item, DateTime value, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
|
||||
public void SetLastRefreshed(BaseItem item, DateTime value, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
|
||||
{
|
||||
SetLastRefreshed(item, value, ProviderVersion, status);
|
||||
}
|
||||
@@ -254,76 +243,7 @@ namespace MediaBrowser.Controller.Providers
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task{System.Boolean}.</returns>
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
public async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
Logger.Info("Running for {0}", item.Path ?? item.Name ?? "--Unknown--");
|
||||
|
||||
// This provides the ability to cancel just this one provider
|
||||
var innerCancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
Kernel.Instance.ProviderManager.OnProviderRefreshBeginning(this, item, innerCancellationTokenSource);
|
||||
|
||||
try
|
||||
{
|
||||
var task = FetchAsyncInternal(item, force, CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token);
|
||||
|
||||
await task.ConfigureAwait(false);
|
||||
|
||||
if (task.IsFaulted)
|
||||
{
|
||||
// Log the AggregateException
|
||||
if (task.Exception != null)
|
||||
{
|
||||
Logger.ErrorException("AggregateException:", task.Exception);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return task.Result;
|
||||
}
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
Logger.Info("{0} cancelled for {1}", GetType().Name, item.Name);
|
||||
|
||||
// If the outer cancellation token is the one that caused the cancellation, throw it
|
||||
if (cancellationToken.IsCancellationRequested && ex.CancellationToken == cancellationToken)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("failed refreshing {0}", ex, item.Name);
|
||||
|
||||
SetLastRefreshed(item, DateTime.UtcNow, ProviderRefreshStatus.Failure);
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
innerCancellationTokenSource.Dispose();
|
||||
|
||||
Kernel.Instance.ProviderManager.OnProviderRefreshCompleted(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="force">if set to <c>true</c> [force].</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task{System.Boolean}.</returns>
|
||||
protected abstract Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken);
|
||||
public abstract Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
@@ -331,23 +251,6 @@ namespace MediaBrowser.Controller.Providers
|
||||
/// <value>The priority.</value>
|
||||
public abstract MetadataProviderPriority Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources.
|
||||
/// </summary>
|
||||
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
||||
protected virtual void Dispose(bool dispose)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true or false indicating if the provider should refresh when the contents of it's directory changes
|
||||
/// </summary>
|
||||
@@ -386,34 +289,4 @@ namespace MediaBrowser.Controller.Providers
|
||||
return item.FileSystemStamp;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines when a provider should execute, relative to others
|
||||
/// </summary>
|
||||
public enum MetadataProviderPriority
|
||||
{
|
||||
// Run this provider at the beginning
|
||||
/// <summary>
|
||||
/// The first
|
||||
/// </summary>
|
||||
First = 1,
|
||||
|
||||
// Run this provider after all first priority providers
|
||||
/// <summary>
|
||||
/// The second
|
||||
/// </summary>
|
||||
Second = 2,
|
||||
|
||||
// Run this provider after all second priority providers
|
||||
/// <summary>
|
||||
/// The third
|
||||
/// </summary>
|
||||
Third = 3,
|
||||
|
||||
// Run this provider last
|
||||
/// <summary>
|
||||
/// The last
|
||||
/// </summary>
|
||||
Last = 4
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user