mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-31 21:08:27 +01:00
Switched to MEF as a means to locate plugins and resolvers
This commit is contained in:
parent
84af205572
commit
97ee9fed14
@@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Model.Configuration;
|
||||
|
||||
namespace MediaBrowser.Controller.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Extends BaseConfigurationController by adding methods to get and set UIConfiguration data
|
||||
/// </summary>
|
||||
public class ServerConfigurationController : ConfigurationController<ServerConfiguration>
|
||||
{
|
||||
private string GetDictionaryKey(Guid userId, string deviceName)
|
||||
{
|
||||
string guidString = userId == Guid.Empty ? string.Empty : userId.ToString();
|
||||
|
||||
return deviceName + "-" + guidString;
|
||||
}
|
||||
|
||||
public UserConfiguration GetUserConfiguration(Guid userId)
|
||||
{
|
||||
return Configuration.DefaultUserConfiguration;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
@@ -17,7 +18,7 @@ using MediaBrowser.Model.Users;
|
||||
|
||||
namespace MediaBrowser.Controller
|
||||
{
|
||||
public class Kernel : BaseKernel<ServerConfigurationController, ServerConfiguration>
|
||||
public class Kernel : BaseKernel<ServerConfiguration>
|
||||
{
|
||||
public static Kernel Instance { get; private set; }
|
||||
|
||||
@@ -37,6 +38,12 @@ namespace MediaBrowser.Controller
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of currently registered entity resolvers
|
||||
/// </summary>
|
||||
[ImportMany(typeof(IBaseItemResolver))]
|
||||
public IEnumerable<IBaseItemResolver> EntityResolvers { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a kernal based on a Data path, which is akin to our current programdata path
|
||||
/// </summary>
|
||||
@@ -51,35 +58,27 @@ namespace MediaBrowser.Controller
|
||||
|
||||
ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath;
|
||||
ItemController.BeginResolvePath += ItemController_BeginResolvePath;
|
||||
|
||||
// Add support for core media types - audio, video, etc
|
||||
AddBaseItemType<Folder, FolderResolver>();
|
||||
AddBaseItemType<Audio, AudioResolver>();
|
||||
AddBaseItemType<Video, VideoResolver>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tells the kernel to start spinning up
|
||||
/// </summary>
|
||||
public override void Init()
|
||||
protected override void OnComposablePartsLoaded()
|
||||
{
|
||||
base.Init();
|
||||
List<IBaseItemResolver> resolvers = EntityResolvers.ToList();
|
||||
|
||||
// Add the internal resolvers
|
||||
resolvers.Add(new VideoResolver());
|
||||
resolvers.Add(new AudioResolver());
|
||||
resolvers.Add(new FolderResolver());
|
||||
|
||||
EntityResolvers = resolvers;
|
||||
|
||||
// The base class will fire up all the plugins
|
||||
base.OnComposablePartsLoaded();
|
||||
|
||||
// Get users from users folder
|
||||
// Load root media folder
|
||||
Parallel.Invoke(ReloadUsers, ReloadRoot);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new BaseItem subclass
|
||||
/// </summary>
|
||||
public void AddBaseItemType<TBaseItemType, TResolverType>()
|
||||
where TBaseItemType : BaseItem, new()
|
||||
where TResolverType : BaseItemResolver<TBaseItemType>, new()
|
||||
{
|
||||
ItemController.AddResovler<TBaseItemType, TResolverType>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires when a path is about to be resolved, but before child folders and files
|
||||
/// have been collected from the file system.
|
||||
@@ -147,6 +146,11 @@ namespace MediaBrowser.Controller
|
||||
}
|
||||
}
|
||||
|
||||
public UserConfiguration GetUserConfiguration(Guid userId)
|
||||
{
|
||||
return Configuration.DefaultUserConfiguration;
|
||||
}
|
||||
|
||||
public void ReloadItem(BaseItem item)
|
||||
{
|
||||
Folder folder = item as Folder;
|
||||
@@ -250,7 +254,7 @@ namespace MediaBrowser.Controller
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
UserConfiguration config = ConfigurationController.GetUserConfiguration(userId);
|
||||
UserConfiguration config = GetUserConfiguration(userId);
|
||||
|
||||
return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => !(i is Folder) && (now - i.DateCreated).TotalDays < config.RecentItemDays);
|
||||
}
|
||||
|
||||
@@ -13,18 +13,6 @@ namespace MediaBrowser.Controller.Library
|
||||
{
|
||||
public class ItemController
|
||||
{
|
||||
private List<IBaseItemResolver> Resolvers = new List<IBaseItemResolver>();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new BaseItem resolver.
|
||||
/// </summary>
|
||||
public void AddResovler<TBaseItemType, TResolverType>()
|
||||
where TBaseItemType : BaseItem, new()
|
||||
where TResolverType : BaseItemResolver<TBaseItemType>, new()
|
||||
{
|
||||
Resolvers.Insert(0, new TResolverType());
|
||||
}
|
||||
|
||||
#region PreBeginResolvePath Event
|
||||
/// <summary>
|
||||
/// Fires when a path is about to be resolved, but before child folders and files
|
||||
@@ -127,7 +115,7 @@ namespace MediaBrowser.Controller.Library
|
||||
private BaseItem ResolveItem(ItemResolveEventArgs args)
|
||||
{
|
||||
// If that didn't pan out, try the slow ones
|
||||
foreach (IBaseItemResolver resolver in Resolvers)
|
||||
foreach (IBaseItemResolver resolver in Kernel.Instance.EntityResolvers)
|
||||
{
|
||||
var item = resolver.ResolvePath(args);
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.Composition" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Reactive">
|
||||
<HintPath>..\packages\Rx-Main.1.0.11226\lib\Net4\System.Reactive.dll</HintPath>
|
||||
@@ -43,7 +44,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Configuration\ServerConfiguration.cs" />
|
||||
<Compile Include="Configuration\ServerConfigurationController.cs" />
|
||||
<Compile Include="Events\ItemResolveEventArgs.cs" />
|
||||
<Compile Include="IO\DirectoryWatchers.cs" />
|
||||
<Compile Include="IO\Shortcut.cs" />
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System.IO;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using MediaBrowser.Controller.Events;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Resolvers
|
||||
{
|
||||
[Export(typeof(IBaseItemResolver))]
|
||||
public class AudioResolver : BaseItemResolver<Audio>
|
||||
{
|
||||
protected override Audio Resolve(ItemResolveEventArgs args)
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.ComponentModel.Composition;
|
||||
using MediaBrowser.Controller.Events;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Controller.Xml;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Resolvers
|
||||
{
|
||||
[Export(typeof(IBaseItemResolver))]
|
||||
public class FolderResolver : BaseFolderResolver<Folder>
|
||||
{
|
||||
protected override Folder Resolve(ItemResolveEventArgs args)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using MediaBrowser.Controller.Events;
|
||||
using MediaBrowser.Model.Entities;
|
||||
@@ -8,6 +9,7 @@ namespace MediaBrowser.Controller.Resolvers
|
||||
/// <summary>
|
||||
/// Resolves a Path into a Video
|
||||
/// </summary>
|
||||
[Export(typeof(IBaseItemResolver))]
|
||||
public class VideoResolver : BaseVideoResolver<Video>
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user