aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Services/ServiceController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/Services/ServiceController.cs')
-rw-r--r--Emby.Server.Implementations/Services/ServiceController.cs51
1 files changed, 40 insertions, 11 deletions
diff --git a/Emby.Server.Implementations/Services/ServiceController.cs b/Emby.Server.Implementations/Services/ServiceController.cs
index 714a16df5..d283bf81f 100644
--- a/Emby.Server.Implementations/Services/ServiceController.cs
+++ b/Emby.Server.Implementations/Services/ServiceController.cs
@@ -5,7 +5,6 @@ using System.Threading.Tasks;
using Emby.Server.Implementations.HttpServer;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Services;
-using ServiceStack;
namespace Emby.Server.Implementations.Services
{
@@ -53,32 +52,62 @@ namespace Emby.Server.Implementations.Services
ServiceExecGeneral.CreateServiceRunnersFor(requestType, actions);
- var returnMarker = requestType.GetTypeWithGenericTypeDefinitionOf(typeof(IReturn<>));
+ var returnMarker = GetTypeWithGenericTypeDefinitionOf(requestType, typeof(IReturn<>));
var responseType = returnMarker != null ?
GetGenericArguments(returnMarker)[0]
: mi.ReturnType != typeof(object) && mi.ReturnType != typeof(void) ?
mi.ReturnType
: Type.GetType(requestType.FullName + "Response");
- RegisterRestPaths(requestType);
+ RegisterRestPaths(appHost, requestType);
appHost.AddServiceInfo(serviceType, requestType, responseType);
}
}
+ private static Type GetTypeWithGenericTypeDefinitionOf(Type type, Type genericTypeDefinition)
+ {
+ foreach (var t in type.GetTypeInfo().ImplementedInterfaces)
+ {
+ if (t.GetTypeInfo().IsGenericType && t.GetGenericTypeDefinition() == genericTypeDefinition)
+ {
+ return t;
+ }
+ }
+
+ var genericType = FirstGenericType(type);
+ if (genericType != null && genericType.GetGenericTypeDefinition() == genericTypeDefinition)
+ {
+ return genericType;
+ }
+
+ return null;
+ }
+
+ public static Type FirstGenericType(Type type)
+ {
+ while (type != null)
+ {
+ if (type.GetTypeInfo().IsGenericType)
+ return type;
+
+ type = type.GetTypeInfo().BaseType;
+ }
+ return null;
+ }
+
public readonly Dictionary<string, List<RestPath>> RestPathMap = new Dictionary<string, List<RestPath>>(StringComparer.OrdinalIgnoreCase);
- public void RegisterRestPaths(Type requestType)
+ public void RegisterRestPaths(HttpListenerHost appHost, Type requestType)
{
- var appHost = ServiceStackHost.Instance;
var attrs = appHost.GetRouteAttributes(requestType);
- foreach (MediaBrowser.Model.Services.RouteAttribute attr in attrs)
+ foreach (RouteAttribute attr in attrs)
{
- var restPath = new RestPath(requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes);
+ var restPath = new RestPath(appHost.CreateInstance, appHost.GetParseFn, requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes);
if (!restPath.IsValid)
throw new NotSupportedException(string.Format(
- "RestPath '{0}' on Type '{1}' is not Valid", attr.Path, requestType.GetOperationName()));
+ "RestPath '{0}' on Type '{1}' is not Valid", attr.Path, requestType.GetMethodName()));
RegisterRestPath(restPath);
}
@@ -89,10 +118,10 @@ namespace Emby.Server.Implementations.Services
public void RegisterRestPath(RestPath restPath)
{
if (!restPath.Path.StartsWith("/"))
- throw new ArgumentException(string.Format("Route '{0}' on '{1}' must start with a '/'", restPath.Path, restPath.RequestType.GetOperationName()));
+ throw new ArgumentException(string.Format("Route '{0}' on '{1}' must start with a '/'", restPath.Path, restPath.RequestType.GetMethodName()));
if (restPath.Path.IndexOfAny(InvalidRouteChars) != -1)
throw new ArgumentException(string.Format("Route '{0}' on '{1}' contains invalid chars. " +
- "See https://github.com/ServiceStack/ServiceStack/wiki/Routing for info on valid routes.", restPath.Path, restPath.RequestType.GetOperationName()));
+ "See https://github.com/ServiceStack/ServiceStack/wiki/Routing for info on valid routes.", restPath.Path, restPath.RequestType.GetMethodName()));
List<RestPath> pathsAtFirstMatch;
if (!RestPathMap.TryGetValue(restPath.FirstMatchHashKey, out pathsAtFirstMatch))
@@ -180,7 +209,7 @@ namespace Emby.Server.Implementations.Services
req.Dto = requestDto;
//Executes the service and returns the result
- var response = await ServiceExecGeneral.Execute(serviceType, req, service, requestDto, requestType.GetOperationName()).ConfigureAwait(false);
+ var response = await ServiceExecGeneral.Execute(serviceType, req, service, requestDto, requestType.GetMethodName()).ConfigureAwait(false);
return response;
}