update plugin interfaces

This commit is contained in:
Luke Pulverenti 2016-10-26 02:01:42 -04:00
parent eb66978207
commit 4b51233cc8
23 changed files with 173 additions and 69 deletions

View File

@ -17,7 +17,7 @@ namespace MediaBrowser.Api
/// <summary>
/// Class BaseApiService
/// </summary>
public class BaseApiService : IHasResultFactory, IRestfulService, IHasSession
public class BaseApiService : IHasResultFactory, IService, IHasSession
{
/// <summary>
/// Gets or sets the logger.

View File

@ -208,7 +208,6 @@
<Compile Include="Net\IHasSession.cs" />
<Compile Include="Net\IHttpResultFactory.cs" />
<Compile Include="Net\IHttpServer.cs" />
<Compile Include="Net\IRestfulService.cs" />
<Compile Include="Net\IServerManager.cs" />
<Compile Include="Net\IServiceRequest.cs" />
<Compile Include="Net\ISessionContext.cs" />

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Services;
namespace MediaBrowser.Controller.Net
{
@ -46,7 +47,7 @@ namespace MediaBrowser.Controller.Net
/// <summary>
/// Inits this instance.
/// </summary>
void Init(IEnumerable<IRestfulService> services);
void Init(IEnumerable<IService> services);
/// <summary>
/// If set, all requests will respond with this message

View File

@ -1,12 +0,0 @@
using MediaBrowser.Model.Services;
namespace MediaBrowser.Controller.Net
{
/// <summary>
/// Interface IRestfulService
/// </summary>
[Logged]
public interface IRestfulService : IService
{
}
}

View File

@ -7,12 +7,20 @@ using MediaBrowser.Model.Services;
namespace MediaBrowser.Controller.Net
{
public class LoggedAttribute : Attribute, IHasRequestFilter
public class LoggedAttribute : IRequestFilter
{
public ILogger Logger { get; set; }
public IUserManager UserManager { get; set; }
public ISessionManager SessionManager { get; set; }
public IAuthorizationContext AuthorizationContext { get; set; }
public LoggedAttribute(ILogger logger, IUserManager userManager, ISessionManager sessionManager, IAuthorizationContext authorizationContext)
{
Logger = logger;
UserManager = userManager;
SessionManager = sessionManager;
AuthorizationContext = authorizationContext;
}
public ILogger Logger { get; private set; }
public IUserManager UserManager { get; private set; }
public ISessionManager SessionManager { get; private set; }
public IAuthorizationContext AuthorizationContext { get; private set; }
/// <summary>
/// The request filter is executed before the service.
@ -20,7 +28,7 @@ namespace MediaBrowser.Controller.Net
/// <param name="request">The http request wrapper</param>
/// <param name="response">The http response wrapper</param>
/// <param name="requestDto">The request DTO</param>
public void RequestFilter(IRequest request, IResponse response, object requestDto)
public void Filter(IRequest request, IResponse response, object requestDto)
{
var serviceRequest = new ServiceRequest(request);
@ -51,25 +59,5 @@ namespace MediaBrowser.Controller.Net
}
}
}
/// <summary>
/// A new shallow copy of this filter is used on every request.
/// </summary>
/// <returns>IHasRequestFilter.</returns>
public IHasRequestFilter Copy()
{
return this;
}
/// <summary>
/// Order in which Request Filters are executed.
/// &lt;0 Executed before global request filters
/// &gt;0 Executed after global request filters
/// </summary>
/// <value>The priority.</value>
public int Priority
{
get { return 0; }
}
}
}

View File

@ -167,6 +167,9 @@
<Compile Include="Net\EndPointInfo.cs" />
<Compile Include="Net\HttpResponse.cs" />
<Compile Include="Net\IpAddressInfo.cs" />
<Compile Include="Plugins\IHasWebPages.cs" />
<Compile Include="Plugins\PluginPageInfo.cs" />
<Compile Include="Reflection\IAssemblyInfo.cs" />
<Compile Include="Services\ApiMemberAttribute.cs" />
<Compile Include="Services\IAsyncStreamWriter.cs" />
<Compile Include="Services\IHasHeaders.cs" />
@ -174,6 +177,7 @@
<Compile Include="Services\IHttpRequest.cs" />
<Compile Include="Services\IHttpResponse.cs" />
<Compile Include="Services\IRequest.cs" />
<Compile Include="Services\IRequestFilter.cs" />
<Compile Include="Services\IRequiresRequestStream.cs" />
<Compile Include="Services\IService.cs" />
<Compile Include="Net\MimeTypes.cs" />

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace MediaBrowser.Model.Plugins
{
public interface IHasWebPages
{
IEnumerable<PluginPageInfo> GetPages();
}
}

View File

@ -0,0 +1,9 @@
namespace MediaBrowser.Model.Plugins
{
public class PluginPageInfo
{
public string Name { get; set; }
public string EmbeddedResourcePath { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using System;
using System.IO;
namespace MediaBrowser.Model.Reflection
{
public interface IAssemblyInfo
{
Stream GetManifestResourceStream(Type type, string resource);
}
}

View File

@ -0,0 +1,8 @@

namespace MediaBrowser.Model.Services
{
public interface IRequestFilter
{
void Filter(IRequest request, IResponse response, object requestDto);
}
}

View File

@ -53,10 +53,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="taglib-sharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

View File

@ -17,9 +17,9 @@ using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Security;
using MediaBrowser.Controller;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
@ -34,7 +34,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
private readonly ILogger _logger;
public IEnumerable<string> UrlPrefixes { get; private set; }
private readonly List<IRestfulService> _restServices = new List<IRestfulService>();
private readonly List<IService> _restServices = new List<IService>();
private IHttpListener _listener;
@ -49,13 +49,16 @@ namespace MediaBrowser.Server.Implementations.HttpServer
private readonly INetworkManager _networkManager;
private readonly IMemoryStreamProvider _memoryStreamProvider;
public HttpListenerHost(IApplicationHost applicationHost,
private readonly IServerApplicationHost _appHost;
public HttpListenerHost(IServerApplicationHost applicationHost,
ILogManager logManager,
IServerConfigurationManager config,
string serviceName,
string defaultRedirectPath, INetworkManager networkManager, IMemoryStreamProvider memoryStreamProvider, params Assembly[] assembliesWithServices)
: base(serviceName, assembliesWithServices)
{
_appHost = applicationHost;
DefaultRedirectPath = defaultRedirectPath;
_networkManager = networkManager;
_memoryStreamProvider = memoryStreamProvider;
@ -116,6 +119,12 @@ namespace MediaBrowser.Server.Implementations.HttpServer
// }
//});
var requestFilters = _appHost.GetExports<IRequestFilter>().ToList();
foreach (var filter in requestFilters)
{
HostContext.GlobalRequestFilters.Add(filter.Filter);
}
HostContext.GlobalResponseFilters.Add(new ResponseFilter(_logger).FilterResponse);
}
@ -569,7 +578,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// Adds the rest handlers.
/// </summary>
/// <param name="services">The services.</param>
public void Init(IEnumerable<IRestfulService> services)
public void Init(IEnumerable<IService> services)
{
_restServices.AddRange(services);

View File

@ -1,6 +1,5 @@
using MediaBrowser.Common;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.IO;
@ -18,17 +17,17 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// Creates the server.
/// </summary>
/// <returns>IHttpServer.</returns>
public static IHttpServer CreateServer(IApplicationHost applicationHost,
public static IHttpServer CreateServer(IServerApplicationHost applicationHost,
ILogManager logManager,
IServerConfigurationManager config,
INetworkManager _networkmanager,
INetworkManager networkmanager,
IMemoryStreamProvider streamProvider,
string serverName,
string defaultRedirectpath)
{
LogManager.LogFactory = new ServerLogFactory(logManager);
return new HttpListenerHost(applicationHost, logManager, config, serverName, defaultRedirectpath, _networkmanager, streamProvider);
return new HttpListenerHost(applicationHost, logManager, config, serverName, defaultRedirectpath, networkmanager, streamProvider);
}
}
}

View File

@ -5,7 +5,7 @@ using MediaBrowser.Model.Services;
namespace MediaBrowser.Server.Implementations.HttpServer
{
public class SwaggerService : IHasResultFactory, IRestfulService
public class SwaggerService : IHasResultFactory, IService
{
private readonly IServerApplicationPaths _appPaths;

View File

@ -270,6 +270,7 @@
<Compile Include="Persistence\DataExtensions.cs" />
<Compile Include="Persistence\IDbConnector.cs" />
<Compile Include="Persistence\MediaStreamColumns.cs" />
<Compile Include="Reflection\AssemblyInfo.cs" />
<Compile Include="Social\SharingManager.cs" />
<Compile Include="Social\SharingRepository.cs" />
<Compile Include="Sorting\StartDateComparer.cs" />

View File

@ -0,0 +1,14 @@
using System;
using System.IO;
using MediaBrowser.Model.Reflection;
namespace MediaBrowser.Server.Implementations.Reflection
{
public class AssemblyInfo : IAssemblyInfo
{
public Stream GetManifestResourceStream(Type type, string resource)
{
return type.Assembly.GetManifestResourceStream(resource);
}
}
}

View File

@ -111,9 +111,12 @@ using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.News;
using MediaBrowser.Model.Reflection;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.Social;
using MediaBrowser.Model.Xml;
using MediaBrowser.Server.Implementations.Reflection;
using MediaBrowser.Server.Implementations.Xml;
namespace MediaBrowser.Server.Startup.Common
@ -634,6 +637,7 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer());
RegisterSingleInstance<IXmlReaderSettingsFactory>(new XmlReaderSettingsFactory());
RegisterSingleInstance<IAssemblyInfo>(new AssemblyInfo());
UserDataManager = new UserDataManager(LogManager, ServerConfigurationManager);
RegisterSingleInstance(UserDataManager);
@ -985,7 +989,7 @@ namespace MediaBrowser.Server.Startup.Common
base.FindParts();
HttpServer.Init(GetExports<IRestfulService>(false));
HttpServer.Init(GetExports<IService>(false));
ServerManager.AddWebSocketListeners(GetExports<IWebSocketListener>(false));

View File

@ -1,4 +1,6 @@
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Plugins;
namespace MediaBrowser.WebDashboard.Api
{
@ -30,5 +32,13 @@ namespace MediaBrowser.WebDashboard.Api
// Don't use "N" because it needs to match Plugin.Id
PluginId = page.Plugin.Id.ToString();
}
public ConfigurationPageInfo(IPlugin plugin, PluginPageInfo page)
{
Name = page.Name;
// Don't use "N" because it needs to match Plugin.Id
PluginId = plugin.Id.ToString();
}
}
}

View File

@ -12,8 +12,11 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Reflection;
using MediaBrowser.Model.Services;
namespace MediaBrowser.WebDashboard.Api
@ -76,7 +79,7 @@ namespace MediaBrowser.WebDashboard.Api
/// <summary>
/// Class DashboardService
/// </summary>
public class DashboardService : IRestfulService, IHasResultFactory
public class DashboardService : IService, IHasResultFactory
{
/// <summary>
/// Gets or sets the logger.
@ -109,6 +112,7 @@ namespace MediaBrowser.WebDashboard.Api
private readonly IFileSystem _fileSystem;
private readonly ILocalizationManager _localization;
private readonly IJsonSerializer _jsonSerializer;
private readonly IAssemblyInfo _assemblyInfo;
/// <summary>
/// Initializes a new instance of the <see cref="DashboardService" /> class.
@ -116,13 +120,14 @@ namespace MediaBrowser.WebDashboard.Api
/// <param name="appHost">The app host.</param>
/// <param name="serverConfigurationManager">The server configuration manager.</param>
/// <param name="fileSystem">The file system.</param>
public DashboardService(IServerApplicationHost appHost, IServerConfigurationManager serverConfigurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer)
public DashboardService(IServerApplicationHost appHost, IServerConfigurationManager serverConfigurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer, IAssemblyInfo assemblyInfo)
{
_appHost = appHost;
_serverConfigurationManager = serverConfigurationManager;
_fileSystem = fileSystem;
_localization = localization;
_jsonSerializer = jsonSerializer;
_assemblyInfo = assemblyInfo;
}
/// <summary>
@ -132,9 +137,32 @@ namespace MediaBrowser.WebDashboard.Api
/// <returns>System.Object.</returns>
public Task<object> Get(GetDashboardConfigurationPage request)
{
var page = ServerEntryPoint.Instance.PluginConfigurationPages.First(p => p.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase));
IPlugin plugin = null;
Stream stream = null;
return ResultFactory.GetStaticResult(Request, page.Plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => GetPackageCreator().ModifyHtml("dummy.html", page.GetHtmlStream(), null, _appHost.ApplicationVersion.ToString(), null, false));
var page = ServerEntryPoint.Instance.PluginConfigurationPages.FirstOrDefault(p => string.Equals(p.Name, request.Name, StringComparison.OrdinalIgnoreCase));
if (page != null)
{
plugin = page.Plugin;
stream = page.GetHtmlStream();
}
if (plugin == null)
{
var altPage = GetPluginPages().FirstOrDefault(p => string.Equals(p.Item1.Name, request.Name, StringComparison.OrdinalIgnoreCase));
if (altPage != null)
{
plugin = altPage.Item2;
stream = _assemblyInfo.GetManifestResourceStream(plugin.GetType(), altPage.Item1.EmbeddedResourcePath);
}
}
if (plugin != null && stream != null)
{
return ResultFactory.GetStaticResult(Request, plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => GetPackageCreator().ModifyHtml("dummy.html", stream, null, _appHost.ApplicationVersion.ToString(), null, false));
}
throw new ResourceNotFoundException();
}
/// <summary>
@ -162,7 +190,7 @@ namespace MediaBrowser.WebDashboard.Api
if (request.PageType.HasValue)
{
pages = pages.Where(p => p.ConfigurationPageType == request.PageType.Value);
pages = pages.Where(p => p.ConfigurationPageType == request.PageType.Value).ToList();
}
// Don't allow a failing plugin to fail them all
@ -182,9 +210,33 @@ namespace MediaBrowser.WebDashboard.Api
.Where(i => i != null)
.ToList();
configPages.AddRange(_appHost.Plugins.SelectMany(GetConfigPages));
return ResultFactory.GetOptimizedResult(Request, configPages);
}
private IEnumerable<Tuple<PluginPageInfo, IPlugin>> GetPluginPages()
{
return _appHost.Plugins.SelectMany(GetPluginPages);
}
private IEnumerable<Tuple<PluginPageInfo, IPlugin>> GetPluginPages(IPlugin plugin)
{
var hasConfig = plugin as IHasWebPages;
if (hasConfig == null)
{
return new List<Tuple<PluginPageInfo, IPlugin>>();
}
return hasConfig.GetPages().Select(i => new Tuple<PluginPageInfo, IPlugin>(i, plugin));
}
private IEnumerable<ConfigurationPageInfo> GetConfigPages(IPlugin plugin)
{
return GetPluginPages(plugin).Select(i => new ConfigurationPageInfo(plugin, i.Item1));
}
public object Get(GetRobotsTxt request)
{
return Get(new GetDashboardResource

View File

@ -1,6 +1,7 @@
using MediaBrowser.Common;
using MediaBrowser.Controller.Plugins;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.WebDashboard
{
@ -10,7 +11,7 @@ namespace MediaBrowser.WebDashboard
/// Gets the list of plugin configuration pages
/// </summary>
/// <value>The configuration pages.</value>
public IEnumerable<IPluginConfigurationPage> PluginConfigurationPages { get; private set; }
public List<IPluginConfigurationPage> PluginConfigurationPages { get; private set; }
private readonly IApplicationHost _appHost;
@ -24,7 +25,7 @@ namespace MediaBrowser.WebDashboard
public void Run()
{
PluginConfigurationPages = _appHost.GetExports<IPluginConfigurationPage>();
PluginConfigurationPages = _appHost.GetExports<IPluginConfigurationPage>().ToList();
}
public void Dispose()

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.676</version>
<version>3.0.680</version>
<title>Emby.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Emby Theater and Emby Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Emby 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.676" />
<dependency id="MediaBrowser.Common" version="3.0.680" />
<dependency id="NLog" version="4.3.8" />
<dependency id="SimpleInjector" version="3.2.2" />
</dependencies>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.676</version>
<version>3.0.680</version>
<title>Emby.Common</title>
<authors>Emby Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.676</version>
<version>3.0.680</version>
<title>Emby.Server.Core</title>
<authors>Emby Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,10 +12,11 @@
<description>Contains core components required to build plugins for Emby Server.</description>
<copyright>Copyright © Emby 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.676" />
<dependency id="MediaBrowser.Common" version="3.0.680" />
</dependencies>
</metadata>
<files>
<file src="dlls\MediaBrowser.Controller.dll" target="lib\net45\MediaBrowser.Controller.dll" />
<file src="dlls\MediaBrowser.Controller.dll" target="lib\portable-net45+win8+wpa81\MediaBrowser.Controller.dll" />
</files>
</package>