Register and construct LibraryManager correctly

pull/2765/head
Mark Monteiro 5 years ago
parent 7fd25f94f3
commit fe9f4e06d1

@ -251,12 +251,6 @@ namespace Emby.Server.Implementations
/// <value>The user manager.</value> /// <value>The user manager.</value>
public IUserManager UserManager { get; set; } public IUserManager UserManager { get; set; }
/// <summary>
/// Gets or sets the library manager.
/// </summary>
/// <value>The library manager.</value>
internal ILibraryManager LibraryManager { get; set; }
/// <summary> /// <summary>
/// Gets or sets the media encoder. /// Gets or sets the media encoder.
/// </summary> /// </summary>
@ -702,8 +696,11 @@ namespace Emby.Server.Implementations
StartupOptions.FFmpegPath); StartupOptions.FFmpegPath);
serviceCollection.AddSingleton(MediaEncoder); serviceCollection.AddSingleton(MediaEncoder);
LibraryManager = new LibraryManager(this, LoggerFactory, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, Resolve<ILibraryMonitor>, FileSystemManager, Resolve<IProviderManager>, Resolve<IUserViewManager>, MediaEncoder); // TODO: Refactor to eliminate the circular dependencies here so that Lazy<T> isn't required
serviceCollection.AddSingleton(LibraryManager); serviceCollection.AddTransient(provider => new Lazy<ILibraryMonitor>(provider.GetRequiredService<ILibraryMonitor>));
serviceCollection.AddTransient(provider => new Lazy<IProviderManager>(provider.GetRequiredService<IProviderManager>));
serviceCollection.AddTransient(provider => new Lazy<IUserViewManager>(provider.GetRequiredService<IUserViewManager>));
serviceCollection.AddSingleton<ILibraryManager, LibraryManager>();
serviceCollection.AddSingleton<IMusicManager, MusicManager>(); serviceCollection.AddSingleton<IMusicManager, MusicManager>();
@ -789,9 +786,7 @@ namespace Emby.Server.Implementations
((UserDataManager)UserDataManager).Repository = userDataRepo; ((UserDataManager)UserDataManager).Repository = userDataRepo;
var itemRepo = (SqliteItemRepository)Resolve<IItemRepository>(); ((SqliteItemRepository)Resolve<IItemRepository>()).Initialize(userDataRepo, UserManager);
itemRepo.Initialize(userDataRepo, UserManager);
((LibraryManager)LibraryManager).ItemRepository = itemRepo;
FindParts(); FindParts();
} }
@ -894,7 +889,7 @@ namespace Emby.Server.Implementations
// For now there's no real way to inject these properly // For now there's no real way to inject these properly
BaseItem.Logger = LoggerFactory.CreateLogger("BaseItem"); BaseItem.Logger = LoggerFactory.CreateLogger("BaseItem");
BaseItem.ConfigurationManager = ServerConfigurationManager; BaseItem.ConfigurationManager = ServerConfigurationManager;
BaseItem.LibraryManager = LibraryManager; BaseItem.LibraryManager = Resolve<ILibraryManager>();
BaseItem.ProviderManager = Resolve<IProviderManager>(); BaseItem.ProviderManager = Resolve<IProviderManager>();
BaseItem.LocalizationManager = LocalizationManager; BaseItem.LocalizationManager = LocalizationManager;
BaseItem.ItemRepository = Resolve<IItemRepository>(); BaseItem.ItemRepository = Resolve<IItemRepository>();
@ -970,7 +965,7 @@ namespace Emby.Server.Implementations
_httpServer.Init(GetExportTypes<IService>(), GetExports<IWebSocketListener>(), GetUrlPrefixes()); _httpServer.Init(GetExportTypes<IService>(), GetExports<IWebSocketListener>(), GetUrlPrefixes());
LibraryManager.AddParts( Resolve<ILibraryManager>().AddParts(
GetExports<IResolverIgnoreRule>(), GetExports<IResolverIgnoreRule>(),
GetExports<IItemResolver>(), GetExports<IItemResolver>(),
GetExports<IIntroProvider>(), GetExports<IIntroProvider>(),

@ -54,9 +54,29 @@ namespace Emby.Server.Implementations.Library
/// </summary> /// </summary>
public class LibraryManager : ILibraryManager public class LibraryManager : ILibraryManager
{ {
private readonly ILogger _logger;
private readonly ITaskManager _taskManager;
private readonly IUserManager _userManager;
private readonly IUserDataManager _userDataRepository;
private readonly IServerConfigurationManager _configurationManager;
private readonly Lazy<ILibraryMonitor> _libraryMonitorFactory;
private readonly Lazy<IProviderManager> _providerManagerFactory;
private readonly Lazy<IUserViewManager> _userviewManagerFactory;
private readonly IServerApplicationHost _appHost;
private readonly IMediaEncoder _mediaEncoder;
private readonly IFileSystem _fileSystem;
private readonly IItemRepository _itemRepository;
private readonly ConcurrentDictionary<Guid, BaseItem> _libraryItemsCache;
private NamingOptions _namingOptions; private NamingOptions _namingOptions;
private string[] _videoFileExtensions; private string[] _videoFileExtensions;
private ILibraryMonitor LibraryMonitor => _libraryMonitorFactory.Value;
private IProviderManager ProviderManager => _providerManagerFactory.Value;
private IUserViewManager UserViewManager => _userviewManagerFactory.Value;
/// <summary> /// <summary>
/// Gets or sets the postscan tasks. /// Gets or sets the postscan tasks.
/// </summary> /// </summary>
@ -89,12 +109,6 @@ namespace Emby.Server.Implementations.Library
/// <value>The comparers.</value> /// <value>The comparers.</value>
private IBaseItemComparer[] Comparers { get; set; } private IBaseItemComparer[] Comparers { get; set; }
/// <summary>
/// Gets or sets the active item repository
/// </summary>
/// <value>The item repository.</value>
public IItemRepository ItemRepository { get; set; }
/// <summary> /// <summary>
/// Occurs when [item added]. /// Occurs when [item added].
/// </summary> /// </summary>
@ -110,90 +124,47 @@ namespace Emby.Server.Implementations.Library
/// </summary> /// </summary>
public event EventHandler<ItemChangeEventArgs> ItemRemoved; public event EventHandler<ItemChangeEventArgs> ItemRemoved;
/// <summary>
/// The _logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// The _task manager
/// </summary>
private readonly ITaskManager _taskManager;
/// <summary>
/// The _user manager
/// </summary>
private readonly IUserManager _userManager;
/// <summary>
/// The _user data repository
/// </summary>
private readonly IUserDataManager _userDataRepository;
/// <summary>
/// Gets or sets the configuration manager.
/// </summary>
/// <value>The configuration manager.</value>
private IServerConfigurationManager ConfigurationManager { get; set; }
private readonly Func<ILibraryMonitor> _libraryMonitorFactory;
private readonly Func<IProviderManager> _providerManagerFactory;
private readonly Func<IUserViewManager> _userviewManager;
public bool IsScanRunning { get; private set; } public bool IsScanRunning { get; private set; }
private IServerApplicationHost _appHost;
private readonly IMediaEncoder _mediaEncoder;
/// <summary>
/// The _library items cache
/// </summary>
private readonly ConcurrentDictionary<Guid, BaseItem> _libraryItemsCache;
/// <summary>
/// Gets the library items cache.
/// </summary>
/// <value>The library items cache.</value>
private ConcurrentDictionary<Guid, BaseItem> LibraryItemsCache => _libraryItemsCache;
private readonly IFileSystem _fileSystem;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="LibraryManager" /> class. /// Initializes a new instance of the <see cref="LibraryManager" /> class.
/// </summary> /// </summary>
/// <param name="appHost">The application host</param> /// <param name="appHost">The application host</param>
/// <param name="loggerFactory">The logger factory.</param> /// <param name="logger">The logger.</param>
/// <param name="taskManager">The task manager.</param> /// <param name="taskManager">The task manager.</param>
/// <param name="userManager">The user manager.</param> /// <param name="userManager">The user manager.</param>
/// <param name="configurationManager">The configuration manager.</param> /// <param name="configurationManager">The configuration manager.</param>
/// <param name="userDataRepository">The user data repository.</param> /// <param name="userDataRepository">The user data repository.</param>
public LibraryManager( public LibraryManager(
IServerApplicationHost appHost, IServerApplicationHost appHost,
ILoggerFactory loggerFactory, ILogger<LibraryManager> logger,
ITaskManager taskManager, ITaskManager taskManager,
IUserManager userManager, IUserManager userManager,
IServerConfigurationManager configurationManager, IServerConfigurationManager configurationManager,
IUserDataManager userDataRepository, IUserDataManager userDataRepository,
Func<ILibraryMonitor> libraryMonitorFactory, Lazy<ILibraryMonitor> libraryMonitorFactory,
IFileSystem fileSystem, IFileSystem fileSystem,
Func<IProviderManager> providerManagerFactory, Lazy<IProviderManager> providerManagerFactory,
Func<IUserViewManager> userviewManager, Lazy<IUserViewManager> userviewManagerFactory,
IMediaEncoder mediaEncoder) IMediaEncoder mediaEncoder,
IItemRepository itemRepository)
{ {
_appHost = appHost; _appHost = appHost;
_logger = loggerFactory.CreateLogger(nameof(LibraryManager)); _logger = logger;
_taskManager = taskManager; _taskManager = taskManager;
_userManager = userManager; _userManager = userManager;
ConfigurationManager = configurationManager; _configurationManager = configurationManager;
_userDataRepository = userDataRepository; _userDataRepository = userDataRepository;
_libraryMonitorFactory = libraryMonitorFactory; _libraryMonitorFactory = libraryMonitorFactory;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_providerManagerFactory = providerManagerFactory; _providerManagerFactory = providerManagerFactory;
_userviewManager = userviewManager; _userviewManagerFactory = userviewManagerFactory;
_mediaEncoder = mediaEncoder; _mediaEncoder = mediaEncoder;
_itemRepository = itemRepository;
_libraryItemsCache = new ConcurrentDictionary<Guid, BaseItem>(); _libraryItemsCache = new ConcurrentDictionary<Guid, BaseItem>();
ConfigurationManager.ConfigurationUpdated += ConfigurationUpdated; _configurationManager.ConfigurationUpdated += ConfigurationUpdated;
RecordConfigurationValues(configurationManager.Configuration); RecordConfigurationValues(configurationManager.Configuration);
} }
@ -272,7 +243,7 @@ namespace Emby.Server.Implementations.Library
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private void ConfigurationUpdated(object sender, EventArgs e) private void ConfigurationUpdated(object sender, EventArgs e)
{ {
var config = ConfigurationManager.Configuration; var config = _configurationManager.Configuration;
var wizardChanged = config.IsStartupWizardCompleted != _wizardCompleted; var wizardChanged = config.IsStartupWizardCompleted != _wizardCompleted;
@ -306,7 +277,7 @@ namespace Emby.Server.Implementations.Library
} }
} }
LibraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; }); _libraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; });
} }
public void DeleteItem(BaseItem item, DeleteOptions options) public void DeleteItem(BaseItem item, DeleteOptions options)
@ -437,10 +408,10 @@ namespace Emby.Server.Implementations.Library
item.SetParent(null); item.SetParent(null);
ItemRepository.DeleteItem(item.Id, CancellationToken.None); _itemRepository.DeleteItem(item.Id, CancellationToken.None);
foreach (var child in children) foreach (var child in children)
{ {
ItemRepository.DeleteItem(child.Id, CancellationToken.None); _itemRepository.DeleteItem(child.Id, CancellationToken.None);
} }
_libraryItemsCache.TryRemove(item.Id, out BaseItem removed); _libraryItemsCache.TryRemove(item.Id, out BaseItem removed);
@ -509,15 +480,15 @@ namespace Emby.Server.Implementations.Library
throw new ArgumentNullException(nameof(type)); throw new ArgumentNullException(nameof(type));
} }
if (key.StartsWith(ConfigurationManager.ApplicationPaths.ProgramDataPath, StringComparison.Ordinal)) if (key.StartsWith(_configurationManager.ApplicationPaths.ProgramDataPath, StringComparison.Ordinal))
{ {
// Try to normalize paths located underneath program-data in an attempt to make them more portable // Try to normalize paths located underneath program-data in an attempt to make them more portable
key = key.Substring(ConfigurationManager.ApplicationPaths.ProgramDataPath.Length) key = key.Substring(_configurationManager.ApplicationPaths.ProgramDataPath.Length)
.TrimStart(new[] { '/', '\\' }) .TrimStart(new[] { '/', '\\' })
.Replace("/", "\\"); .Replace("/", "\\");
} }
if (forceCaseInsensitive || !ConfigurationManager.Configuration.EnableCaseSensitiveItemIds) if (forceCaseInsensitive || !_configurationManager.Configuration.EnableCaseSensitiveItemIds)
{ {
key = key.ToLowerInvariant(); key = key.ToLowerInvariant();
} }
@ -550,7 +521,7 @@ namespace Emby.Server.Implementations.Library
collectionType = GetContentTypeOverride(fullPath, true); collectionType = GetContentTypeOverride(fullPath, true);
} }
var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, directoryService) var args = new ItemResolveArgs(_configurationManager.ApplicationPaths, directoryService)
{ {
Parent = parent, Parent = parent,
Path = fullPath, Path = fullPath,
@ -720,7 +691,7 @@ namespace Emby.Server.Implementations.Library
/// <exception cref="InvalidOperationException">Cannot create the root folder until plugins have loaded.</exception> /// <exception cref="InvalidOperationException">Cannot create the root folder until plugins have loaded.</exception>
public AggregateFolder CreateRootFolder() public AggregateFolder CreateRootFolder()
{ {
var rootFolderPath = ConfigurationManager.ApplicationPaths.RootFolderPath; var rootFolderPath = _configurationManager.ApplicationPaths.RootFolderPath;
Directory.CreateDirectory(rootFolderPath); Directory.CreateDirectory(rootFolderPath);
@ -734,7 +705,7 @@ namespace Emby.Server.Implementations.Library
} }
// Add in the plug-in folders // Add in the plug-in folders
var path = Path.Combine(ConfigurationManager.ApplicationPaths.DataPath, "playlists"); var path = Path.Combine(_configurationManager.ApplicationPaths.DataPath, "playlists");
Directory.CreateDirectory(path); Directory.CreateDirectory(path);
@ -786,7 +757,7 @@ namespace Emby.Server.Implementations.Library
{ {
if (_userRootFolder == null) if (_userRootFolder == null)
{ {
var userRootPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; var userRootPath = _configurationManager.ApplicationPaths.DefaultUserViewsPath;
_logger.LogDebug("Creating userRootPath at {path}", userRootPath); _logger.LogDebug("Creating userRootPath at {path}", userRootPath);
Directory.CreateDirectory(userRootPath); Directory.CreateDirectory(userRootPath);
@ -980,7 +951,7 @@ namespace Emby.Server.Implementations.Library
where T : BaseItem, new() where T : BaseItem, new()
{ {
var path = getPathFn(name); var path = getPathFn(name);
var forceCaseInsensitiveId = ConfigurationManager.Configuration.EnableNormalizedItemByNameIds; var forceCaseInsensitiveId = _configurationManager.Configuration.EnableNormalizedItemByNameIds;
return GetNewItemIdInternal(path, typeof(T), forceCaseInsensitiveId); return GetNewItemIdInternal(path, typeof(T), forceCaseInsensitiveId);
} }
@ -994,7 +965,7 @@ namespace Emby.Server.Implementations.Library
public Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress) public Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
{ {
// Ensure the location is available. // Ensure the location is available.
Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.PeoplePath); Directory.CreateDirectory(_configurationManager.ApplicationPaths.PeoplePath);
return new PeopleValidator(this, _logger, _fileSystem).ValidatePeople(cancellationToken, progress); return new PeopleValidator(this, _logger, _fileSystem).ValidatePeople(cancellationToken, progress);
} }
@ -1031,7 +1002,7 @@ namespace Emby.Server.Implementations.Library
public async Task ValidateMediaLibraryInternal(IProgress<double> progress, CancellationToken cancellationToken) public async Task ValidateMediaLibraryInternal(IProgress<double> progress, CancellationToken cancellationToken)
{ {
IsScanRunning = true; IsScanRunning = true;
_libraryMonitorFactory().Stop(); LibraryMonitor.Stop();
try try
{ {
@ -1039,7 +1010,7 @@ namespace Emby.Server.Implementations.Library
} }
finally finally
{ {
_libraryMonitorFactory().Start(); LibraryMonitor.Start();
IsScanRunning = false; IsScanRunning = false;
} }
} }
@ -1148,7 +1119,7 @@ namespace Emby.Server.Implementations.Library
progress.Report(percent * 100); progress.Report(percent * 100);
} }
ItemRepository.UpdateInheritedValues(cancellationToken); _itemRepository.UpdateInheritedValues(cancellationToken);
progress.Report(100); progress.Report(100);
} }
@ -1168,9 +1139,9 @@ namespace Emby.Server.Implementations.Library
var topLibraryFolders = GetUserRootFolder().Children.ToList(); var topLibraryFolders = GetUserRootFolder().Children.ToList();
_logger.LogDebug("Getting refreshQueue"); _logger.LogDebug("Getting refreshQueue");
var refreshQueue = includeRefreshState ? _providerManagerFactory().GetRefreshQueue() : null; var refreshQueue = includeRefreshState ? ProviderManager.GetRefreshQueue() : null;
return _fileSystem.GetDirectoryPaths(ConfigurationManager.ApplicationPaths.DefaultUserViewsPath) return _fileSystem.GetDirectoryPaths(_configurationManager.ApplicationPaths.DefaultUserViewsPath)
.Select(dir => GetVirtualFolderInfo(dir, topLibraryFolders, refreshQueue)) .Select(dir => GetVirtualFolderInfo(dir, topLibraryFolders, refreshQueue))
.ToList(); .ToList();
} }
@ -1245,7 +1216,7 @@ namespace Emby.Server.Implementations.Library
throw new ArgumentException("Guid can't be empty", nameof(id)); throw new ArgumentException("Guid can't be empty", nameof(id));
} }
if (LibraryItemsCache.TryGetValue(id, out BaseItem item)) if (_libraryItemsCache.TryGetValue(id, out BaseItem item))
{ {
return item; return item;
} }
@ -1276,7 +1247,7 @@ namespace Emby.Server.Implementations.Library
AddUserToQuery(query, query.User, allowExternalContent); AddUserToQuery(query, query.User, allowExternalContent);
} }
return ItemRepository.GetItemList(query); return _itemRepository.GetItemList(query);
} }
public List<BaseItem> GetItemList(InternalItemsQuery query) public List<BaseItem> GetItemList(InternalItemsQuery query)
@ -1300,7 +1271,7 @@ namespace Emby.Server.Implementations.Library
AddUserToQuery(query, query.User); AddUserToQuery(query, query.User);
} }
return ItemRepository.GetCount(query); return _itemRepository.GetCount(query);
} }
public List<BaseItem> GetItemList(InternalItemsQuery query, List<BaseItem> parents) public List<BaseItem> GetItemList(InternalItemsQuery query, List<BaseItem> parents)
@ -1315,7 +1286,7 @@ namespace Emby.Server.Implementations.Library
} }
} }
return ItemRepository.GetItemList(query); return _itemRepository.GetItemList(query);
} }
public QueryResult<BaseItem> QueryItems(InternalItemsQuery query) public QueryResult<BaseItem> QueryItems(InternalItemsQuery query)
@ -1327,12 +1298,12 @@ namespace Emby.Server.Implementations.Library
if (query.EnableTotalRecordCount) if (query.EnableTotalRecordCount)
{ {
return ItemRepository.GetItems(query); return _itemRepository.GetItems(query);
} }
return new QueryResult<BaseItem> return new QueryResult<BaseItem>
{ {
Items = ItemRepository.GetItemList(query).ToArray() Items = _itemRepository.GetItemList(query).ToArray()
}; };
} }
@ -1343,7 +1314,7 @@ namespace Emby.Server.Implementations.Library
AddUserToQuery(query, query.User); AddUserToQuery(query, query.User);
} }
return ItemRepository.GetItemIdsList(query); return _itemRepository.GetItemIdsList(query);
} }
public QueryResult<(BaseItem, ItemCounts)> GetStudios(InternalItemsQuery query) public QueryResult<(BaseItem, ItemCounts)> GetStudios(InternalItemsQuery query)
@ -1354,7 +1325,7 @@ namespace Emby.Server.Implementations.Library
} }
SetTopParentOrAncestorIds(query); SetTopParentOrAncestorIds(query);
return ItemRepository.GetStudios(query); return _itemRepository.GetStudios(query);
} }
public QueryResult<(BaseItem, ItemCounts)> GetGenres(InternalItemsQuery query) public QueryResult<(BaseItem, ItemCounts)> GetGenres(InternalItemsQuery query)
@ -1365,7 +1336,7 @@ namespace Emby.Server.Implementations.Library
} }
SetTopParentOrAncestorIds(query); SetTopParentOrAncestorIds(query);
return ItemRepository.GetGenres(query); return _itemRepository.GetGenres(query);
} }
public QueryResult<(BaseItem, ItemCounts)> GetMusicGenres(InternalItemsQuery query) public QueryResult<(BaseItem, ItemCounts)> GetMusicGenres(InternalItemsQuery query)
@ -1376,7 +1347,7 @@ namespace Emby.Server.Implementations.Library
} }
SetTopParentOrAncestorIds(query); SetTopParentOrAncestorIds(query);
return ItemRepository.GetMusicGenres(query); return _itemRepository.GetMusicGenres(query);
} }
public QueryResult<(BaseItem, ItemCounts)> GetAllArtists(InternalItemsQuery query) public QueryResult<(BaseItem, ItemCounts)> GetAllArtists(InternalItemsQuery query)
@ -1387,7 +1358,7 @@ namespace Emby.Server.Implementations.Library
} }
SetTopParentOrAncestorIds(query); SetTopParentOrAncestorIds(query);
return ItemRepository.GetAllArtists(query); return _itemRepository.GetAllArtists(query);
} }
public QueryResult<(BaseItem, ItemCounts)> GetArtists(InternalItemsQuery query) public QueryResult<(BaseItem, ItemCounts)> GetArtists(InternalItemsQuery query)
@ -1398,7 +1369,7 @@ namespace Emby.Server.Implementations.Library
} }
SetTopParentOrAncestorIds(query); SetTopParentOrAncestorIds(query);
return ItemRepository.GetArtists(query); return _itemRepository.GetArtists(query);
} }
private void SetTopParentOrAncestorIds(InternalItemsQuery query) private void SetTopParentOrAncestorIds(InternalItemsQuery query)
@ -1439,7 +1410,7 @@ namespace Emby.Server.Implementations.Library
} }
SetTopParentOrAncestorIds(query); SetTopParentOrAncestorIds(query);
return ItemRepository.GetAlbumArtists(query); return _itemRepository.GetAlbumArtists(query);
} }
public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query) public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query)
@ -1460,10 +1431,10 @@ namespace Emby.Server.Implementations.Library
if (query.EnableTotalRecordCount) if (query.EnableTotalRecordCount)
{ {
return ItemRepository.GetItems(query); return _itemRepository.GetItems(query);
} }
var list = ItemRepository.GetItemList(query); var list = _itemRepository.GetItemList(query);
return new QueryResult<BaseItem> return new QueryResult<BaseItem>
{ {
@ -1509,7 +1480,7 @@ namespace Emby.Server.Implementations.Library
string.IsNullOrEmpty(query.SeriesPresentationUniqueKey) && string.IsNullOrEmpty(query.SeriesPresentationUniqueKey) &&
query.ItemIds.Length == 0) query.ItemIds.Length == 0)
{ {
var userViews = _userviewManager().GetUserViews(new UserViewQuery var userViews = UserViewManager.GetUserViews(new UserViewQuery
{ {
UserId = user.Id, UserId = user.Id,
IncludeHidden = true, IncludeHidden = true,
@ -1809,7 +1780,7 @@ namespace Emby.Server.Implementations.Library
// Don't iterate multiple times // Don't iterate multiple times
var itemsList = items.ToList(); var itemsList = items.ToList();
ItemRepository.SaveItems(itemsList, cancellationToken); _itemRepository.SaveItems(itemsList, cancellationToken);
foreach (var item in itemsList) foreach (var item in itemsList)
{ {
@ -1846,7 +1817,7 @@ namespace Emby.Server.Implementations.Library
public void UpdateImages(BaseItem item) public void UpdateImages(BaseItem item)
{ {
ItemRepository.SaveImages(item); _itemRepository.SaveImages(item);
RegisterItem(item); RegisterItem(item);
} }
@ -1863,7 +1834,7 @@ namespace Emby.Server.Implementations.Library
{ {
if (item.IsFileProtocol) if (item.IsFileProtocol)
{ {
_providerManagerFactory().SaveMetadata(item, updateReason); ProviderManager.SaveMetadata(item, updateReason);
} }
item.DateLastSaved = DateTime.UtcNow; item.DateLastSaved = DateTime.UtcNow;
@ -1871,7 +1842,7 @@ namespace Emby.Server.Implementations.Library
RegisterItem(item); RegisterItem(item);
} }
ItemRepository.SaveItems(itemsList, cancellationToken); _itemRepository.SaveItems(itemsList, cancellationToken);
if (ItemUpdated != null) if (ItemUpdated != null)
{ {
@ -1947,7 +1918,7 @@ namespace Emby.Server.Implementations.Library
/// <returns>BaseItem.</returns> /// <returns>BaseItem.</returns>
public BaseItem RetrieveItem(Guid id) public BaseItem RetrieveItem(Guid id)
{ {
return ItemRepository.RetrieveItem(id); return _itemRepository.RetrieveItem(id);
} }
public List<Folder> GetCollectionFolders(BaseItem item) public List<Folder> GetCollectionFolders(BaseItem item)
@ -2066,7 +2037,7 @@ namespace Emby.Server.Implementations.Library
private string GetContentTypeOverride(string path, bool inherit) private string GetContentTypeOverride(string path, bool inherit)
{ {
var nameValuePair = ConfigurationManager.Configuration.ContentTypes var nameValuePair = _configurationManager.Configuration.ContentTypes
.FirstOrDefault(i => _fileSystem.AreEqual(i.Name, path) .FirstOrDefault(i => _fileSystem.AreEqual(i.Name, path)
|| (inherit && !string.IsNullOrEmpty(i.Name) || (inherit && !string.IsNullOrEmpty(i.Name)
&& _fileSystem.ContainsSubPath(i.Name, path))); && _fileSystem.ContainsSubPath(i.Name, path)));
@ -2115,7 +2086,7 @@ namespace Emby.Server.Implementations.Library
string sortName) string sortName)
{ {
var path = Path.Combine( var path = Path.Combine(
ConfigurationManager.ApplicationPaths.InternalMetadataPath, _configurationManager.ApplicationPaths.InternalMetadataPath,
"views", "views",
_fileSystem.GetValidFilename(viewType)); _fileSystem.GetValidFilename(viewType));
@ -2147,7 +2118,7 @@ namespace Emby.Server.Implementations.Library
if (refresh) if (refresh)
{ {
item.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None); item.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None);
_providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), RefreshPriority.Normal); ProviderManager.QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), RefreshPriority.Normal);
} }
return item; return item;
@ -2165,7 +2136,7 @@ namespace Emby.Server.Implementations.Library
var id = GetNewItemId(idValues, typeof(UserView)); var id = GetNewItemId(idValues, typeof(UserView));
var path = Path.Combine(ConfigurationManager.ApplicationPaths.InternalMetadataPath, "views", id.ToString("N", CultureInfo.InvariantCulture)); var path = Path.Combine(_configurationManager.ApplicationPaths.InternalMetadataPath, "views", id.ToString("N", CultureInfo.InvariantCulture));
var item = GetItemById(id) as UserView; var item = GetItemById(id) as UserView;
@ -2202,7 +2173,7 @@ namespace Emby.Server.Implementations.Library
if (refresh) if (refresh)
{ {
_providerManagerFactory().QueueRefresh( ProviderManager.QueueRefresh(
item.Id, item.Id,
new MetadataRefreshOptions(new DirectoryService(_fileSystem)) new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{ {
@ -2269,7 +2240,7 @@ namespace Emby.Server.Implementations.Library
if (refresh) if (refresh)
{ {
_providerManagerFactory().QueueRefresh( ProviderManager.QueueRefresh(
item.Id, item.Id,
new MetadataRefreshOptions(new DirectoryService(_fileSystem)) new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{ {
@ -2303,7 +2274,7 @@ namespace Emby.Server.Implementations.Library
var id = GetNewItemId(idValues, typeof(UserView)); var id = GetNewItemId(idValues, typeof(UserView));
var path = Path.Combine(ConfigurationManager.ApplicationPaths.InternalMetadataPath, "views", id.ToString("N", CultureInfo.InvariantCulture)); var path = Path.Combine(_configurationManager.ApplicationPaths.InternalMetadataPath, "views", id.ToString("N", CultureInfo.InvariantCulture));
var item = GetItemById(id) as UserView; var item = GetItemById(id) as UserView;
@ -2346,7 +2317,7 @@ namespace Emby.Server.Implementations.Library
if (refresh) if (refresh)
{ {
_providerManagerFactory().QueueRefresh( ProviderManager.QueueRefresh(
item.Id, item.Id,
new MetadataRefreshOptions(new DirectoryService(_fileSystem)) new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{ {
@ -2677,8 +2648,8 @@ namespace Emby.Server.Implementations.Library
} }
} }
var metadataPath = ConfigurationManager.Configuration.MetadataPath; var metadataPath = _configurationManager.Configuration.MetadataPath;
var metadataNetworkPath = ConfigurationManager.Configuration.MetadataNetworkPath; var metadataNetworkPath = _configurationManager.Configuration.MetadataNetworkPath;
if (!string.IsNullOrWhiteSpace(metadataPath) && !string.IsNullOrWhiteSpace(metadataNetworkPath)) if (!string.IsNullOrWhiteSpace(metadataPath) && !string.IsNullOrWhiteSpace(metadataNetworkPath))
{ {
@ -2689,7 +2660,7 @@ namespace Emby.Server.Implementations.Library
} }
} }
foreach (var map in ConfigurationManager.Configuration.PathSubstitutions) foreach (var map in _configurationManager.Configuration.PathSubstitutions)
{ {
if (!string.IsNullOrWhiteSpace(map.From)) if (!string.IsNullOrWhiteSpace(map.From))
{ {
@ -2758,7 +2729,7 @@ namespace Emby.Server.Implementations.Library
public List<PersonInfo> GetPeople(InternalPeopleQuery query) public List<PersonInfo> GetPeople(InternalPeopleQuery query)
{ {
return ItemRepository.GetPeople(query); return _itemRepository.GetPeople(query);
} }
public List<PersonInfo> GetPeople(BaseItem item) public List<PersonInfo> GetPeople(BaseItem item)
@ -2781,7 +2752,7 @@ namespace Emby.Server.Implementations.Library
public List<Person> GetPeopleItems(InternalPeopleQuery query) public List<Person> GetPeopleItems(InternalPeopleQuery query)
{ {
return ItemRepository.GetPeopleNames(query).Select(i => return _itemRepository.GetPeopleNames(query).Select(i =>
{ {
try try
{ {
@ -2798,7 +2769,7 @@ namespace Emby.Server.Implementations.Library
public List<string> GetPeopleNames(InternalPeopleQuery query) public List<string> GetPeopleNames(InternalPeopleQuery query)
{ {
return ItemRepository.GetPeopleNames(query); return _itemRepository.GetPeopleNames(query);
} }
public void UpdatePeople(BaseItem item, List<PersonInfo> people) public void UpdatePeople(BaseItem item, List<PersonInfo> people)
@ -2808,7 +2779,7 @@ namespace Emby.Server.Implementations.Library
return; return;
} }
ItemRepository.UpdatePeople(item.Id, people); _itemRepository.UpdatePeople(item.Id, people);
} }
public async Task<ItemImageInfo> ConvertImageToLocal(BaseItem item, ItemImageInfo image, int imageIndex) public async Task<ItemImageInfo> ConvertImageToLocal(BaseItem item, ItemImageInfo image, int imageIndex)
@ -2819,7 +2790,7 @@ namespace Emby.Server.Implementations.Library
{ {
_logger.LogDebug("ConvertImageToLocal item {0} - image url: {1}", item.Id, url); _logger.LogDebug("ConvertImageToLocal item {0} - image url: {1}", item.Id, url);
await _providerManagerFactory().SaveImage(item, url, image.Type, imageIndex, CancellationToken.None).ConfigureAwait(false); await ProviderManager.SaveImage(item, url, image.Type, imageIndex, CancellationToken.None).ConfigureAwait(false);
item.UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None); item.UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
@ -2852,7 +2823,7 @@ namespace Emby.Server.Implementations.Library
name = _fileSystem.GetValidFilename(name); name = _fileSystem.GetValidFilename(name);
var rootFolderPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; var rootFolderPath = _configurationManager.ApplicationPaths.DefaultUserViewsPath;
var virtualFolderPath = Path.Combine(rootFolderPath, name); var virtualFolderPath = Path.Combine(rootFolderPath, name);
while (Directory.Exists(virtualFolderPath)) while (Directory.Exists(virtualFolderPath))
@ -2871,7 +2842,7 @@ namespace Emby.Server.Implementations.Library
} }
} }
_libraryMonitorFactory().Stop(); LibraryMonitor.Stop();
try try
{ {
@ -2906,7 +2877,7 @@ namespace Emby.Server.Implementations.Library
{ {
// Need to add a delay here or directory watchers may still pick up the changes // Need to add a delay here or directory watchers may still pick up the changes
await Task.Delay(1000).ConfigureAwait(false); await Task.Delay(1000).ConfigureAwait(false);
_libraryMonitorFactory().Start(); LibraryMonitor.Start();
} }
} }
} }
@ -2966,7 +2937,7 @@ namespace Emby.Server.Implementations.Library
throw new FileNotFoundException("The network path does not exist."); throw new FileNotFoundException("The network path does not exist.");
} }
var rootFolderPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; var rootFolderPath = _configurationManager.ApplicationPaths.DefaultUserViewsPath;
var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName); var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName);
var shortcutFilename = Path.GetFileNameWithoutExtension(path); var shortcutFilename = Path.GetFileNameWithoutExtension(path);
@ -3009,7 +2980,7 @@ namespace Emby.Server.Implementations.Library
throw new FileNotFoundException("The network path does not exist."); throw new FileNotFoundException("The network path does not exist.");
} }
var rootFolderPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; var rootFolderPath = _configurationManager.ApplicationPaths.DefaultUserViewsPath;
var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName); var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName);
var libraryOptions = CollectionFolder.GetLibraryOptions(virtualFolderPath); var libraryOptions = CollectionFolder.GetLibraryOptions(virtualFolderPath);
@ -3062,7 +3033,7 @@ namespace Emby.Server.Implementations.Library
throw new ArgumentNullException(nameof(name)); throw new ArgumentNullException(nameof(name));
} }
var rootFolderPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; var rootFolderPath = _configurationManager.ApplicationPaths.DefaultUserViewsPath;
var path = Path.Combine(rootFolderPath, name); var path = Path.Combine(rootFolderPath, name);
@ -3071,7 +3042,7 @@ namespace Emby.Server.Implementations.Library
throw new FileNotFoundException("The media folder does not exist"); throw new FileNotFoundException("The media folder does not exist");
} }
_libraryMonitorFactory().Stop(); LibraryMonitor.Stop();
try try
{ {
@ -3091,7 +3062,7 @@ namespace Emby.Server.Implementations.Library
{ {
// Need to add a delay here or directory watchers may still pick up the changes // Need to add a delay here or directory watchers may still pick up the changes
await Task.Delay(1000).ConfigureAwait(false); await Task.Delay(1000).ConfigureAwait(false);
_libraryMonitorFactory().Start(); LibraryMonitor.Start();
} }
} }
} }
@ -3105,7 +3076,7 @@ namespace Emby.Server.Implementations.Library
var removeList = new List<NameValuePair>(); var removeList = new List<NameValuePair>();
foreach (var contentType in ConfigurationManager.Configuration.ContentTypes) foreach (var contentType in _configurationManager.Configuration.ContentTypes)
{ {
if (string.IsNullOrWhiteSpace(contentType.Name)) if (string.IsNullOrWhiteSpace(contentType.Name))
{ {
@ -3120,11 +3091,11 @@ namespace Emby.Server.Implementations.Library
if (removeList.Count > 0) if (removeList.Count > 0)
{ {
ConfigurationManager.Configuration.ContentTypes = ConfigurationManager.Configuration.ContentTypes _configurationManager.Configuration.ContentTypes = _configurationManager.Configuration.ContentTypes
.Except(removeList) .Except(removeList)
.ToArray(); .ToArray();
ConfigurationManager.SaveConfiguration(); _configurationManager.SaveConfiguration();
} }
} }
@ -3135,7 +3106,7 @@ namespace Emby.Server.Implementations.Library
throw new ArgumentNullException(nameof(mediaPath)); throw new ArgumentNullException(nameof(mediaPath));
} }
var rootFolderPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; var rootFolderPath = _configurationManager.ApplicationPaths.DefaultUserViewsPath;
var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName); var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName);
if (!Directory.Exists(virtualFolderPath)) if (!Directory.Exists(virtualFolderPath))

Loading…
Cancel
Save