diff options
| author | stefan <stefan@hegedues.at> | 2018-09-12 19:26:21 +0200 |
|---|---|---|
| committer | stefan <stefan@hegedues.at> | 2018-09-12 19:26:21 +0200 |
| commit | 48facb797ed912e4ea6b04b17d1ff190ac2daac4 (patch) | |
| tree | 8dae77a31670a888d733484cb17dd4077d5444e8 /Emby.Server.Implementations/Services/ServiceExec.cs | |
| parent | c32d8656382a0eacb301692e0084377fc433ae9b (diff) | |
Update to 3.5.2 and .net core 2.1
Diffstat (limited to 'Emby.Server.Implementations/Services/ServiceExec.cs')
| -rw-r--r-- | Emby.Server.Implementations/Services/ServiceExec.cs | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/Emby.Server.Implementations/Services/ServiceExec.cs b/Emby.Server.Implementations/Services/ServiceExec.cs index 5709d3e0a..79b57438c 100644 --- a/Emby.Server.Implementations/Services/ServiceExec.cs +++ b/Emby.Server.Implementations/Services/ServiceExec.cs @@ -70,7 +70,7 @@ namespace Emby.Server.Implementations.Services } } - public static async Task<object> Execute(Type serviceType, IRequest request, object instance, object requestDto, string requestName) + public static Task<object> Execute(Type serviceType, IRequest request, object instance, object requestDto, string requestName) { var actionName = request.Verb ?? "POST"; @@ -82,7 +82,10 @@ namespace Emby.Server.Implementations.Services foreach (var requestFilter in actionContext.RequestFilters) { requestFilter.RequestFilter(request, request.Response, requestDto); - if (request.Response.IsClosed) return null; + if (request.Response.IsClosed) + { + Task.FromResult<object>(null); + } } } @@ -91,17 +94,56 @@ namespace Emby.Server.Implementations.Services var taskResponse = response as Task; if (taskResponse != null) { - await taskResponse.ConfigureAwait(false); - response = ServiceHandler.GetTaskResult(taskResponse); + return GetTaskResult(taskResponse); } - return response; + return Task.FromResult(response); } var expectedMethodName = actionName.Substring(0, 1) + actionName.Substring(1).ToLower(); throw new NotImplementedException(string.Format("Could not find method named {1}({0}) or Any({0}) on Service {2}", requestDto.GetType().GetMethodName(), expectedMethodName, serviceType.GetMethodName())); } + private static async Task<object> GetTaskResult(Task task) + { + try + { + var taskObject = task as Task<object>; + if (taskObject != null) + { + return await taskObject.ConfigureAwait(false); + } + + await task.ConfigureAwait(false); + + var type = task.GetType().GetTypeInfo(); + if (!type.IsGenericType) + { + return null; + } + + var resultProperty = type.GetDeclaredProperty("Result"); + if (resultProperty == null) + { + return null; + } + + var result = resultProperty.GetValue(task); + + // hack alert + if (result.GetType().Name.IndexOf("voidtaskresult", StringComparison.OrdinalIgnoreCase) != -1) + { + return null; + } + + return result; + } + catch (TypeAccessException) + { + return null; //return null for void Task's + } + } + public static List<ServiceMethod> Reset(Type serviceType) { var actions = new List<ServiceMethod>(); |
