public static Task <object> Execute(Type serviceType, IRequest request, object instance, object requestDto, string requestName) { var actionName = request.Verb ?? "POST"; ServiceMethod actionContext; if (ServiceExecGeneral.execMap.TryGetValue(ServiceMethod.Key(serviceType, actionName, requestName), out actionContext)) { if (actionContext.RequestFilters != null) { foreach (var requestFilter in actionContext.RequestFilters) { requestFilter.RequestFilter(request, request.Response, requestDto); if (request.Response.IsClosed) { Task.FromResult <object>(null); } } } var response = actionContext.ServiceAction(instance, requestDto); var taskResponse = response as Task; if (taskResponse != null) { return(GetTaskResult(taskResponse)); } 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())); }
public static List <ServiceMethod> Reset(Type serviceType) { var actions = new List <ServiceMethod>(); foreach (var mi in serviceType.GetActions()) { var actionName = mi.Name; var args = mi.GetParameters(); var requestType = args[0].ParameterType; var actionCtx = new ServiceMethod { Id = ServiceMethod.Key(serviceType, actionName, requestType.GetMethodName()) }; try { actionCtx.ServiceAction = CreateExecFn(serviceType, requestType, mi); } catch { //Potential problems with MONO, using reflection for fallback actionCtx.ServiceAction = (service, request) => mi.Invoke(service, new[] { request }); } var reqFilters = new List <IHasRequestFilter>(); foreach (var attr in mi.GetCustomAttributes(true)) { var hasReqFilter = attr as IHasRequestFilter; if (hasReqFilter != null) { reqFilters.Add(hasReqFilter); } } if (reqFilters.Count > 0) { actionCtx.RequestFilters = reqFilters.OrderBy(i => i.Priority).ToArray(); } actions.Add(actionCtx); } return(actions); }
public static List <ServiceMethod> Reset(Type serviceType) { var actions = new List <ServiceMethod>(); foreach (var mi in serviceType.GetActions()) { var actionName = mi.Name; var args = mi.GetParameters(); var requestType = args[0].ParameterType; var actionCtx = new ServiceMethod { Id = ServiceMethod.Key(serviceType, actionName, requestType.GetMethodName()) }; actionCtx.ServiceAction = CreateExecFn(serviceType, requestType, mi); var reqFilters = new List <IHasRequestFilter>(); foreach (var attr in mi.GetCustomAttributes(true)) { if (attr is IHasRequestFilter hasReqFilter) { reqFilters.Add(hasReqFilter); } } if (reqFilters.Count > 0) { actionCtx.RequestFilters = reqFilters.OrderBy(i => i.Priority).ToArray(); } actions.Add(actionCtx); } return(actions); }