public ServiceUnitResponse Execute(ServiceUnitContext suContext, IUriProcessResolver resolver) { Contract.NotNull(suContext, "suContext"); Contract.NotNull(resolver, "resolver"); using (var logger = new TraceLogger(suContext)) { return(ExecuteInternal(suContext, resolver)); } }
private ServiceUnitResponse ExecuteInternal(ServiceUnitContext suContext, IUriProcessResolver resolver) { var executionType = resolver.GetExecutionType(suContext); ServiceUnitResponse response = null; if (executionType == null) { response = new ServiceUnitResponse(HttpStatusCode.NotFound); HandleError(suContext, resolver, response); return(response); } var instance = resolver.CreateInstance(suContext, executionType); if (instance == null) { response = new ServiceUnitResponse(HttpStatusCode.NotFound); HandleError(suContext, resolver, response); return(response); } var action = resolver.GetAction(suContext, instance); if (action == null) { response = new ServiceUnitResponse(HttpStatusCode.NotFound); HandleError(suContext, resolver, response); return(response); } try { response = resolver.InvokeAction(suContext, action); if (response == null) { return(new ServiceUnitResponse(HttpStatusCode.NotFound)); } if (response.StatusCode != HttpStatusCode.OK) { HandleError(suContext, resolver, response); } } catch (Exception ex) { WriteErrorLog(suContext, ex); return(HandleError(suContext, resolver, new ServiceUnitResponse(HttpStatusCode.InternalServerError) { Data = ex })); } return(response); }
private ServiceUnitResponse HandleError(ServiceUnitContext context, IUriProcessResolver resolver, ServiceUnitResponse response) { if (resolver != null) { foreach (var handler in resolver.HandleErrorPipeline) { handler.Invoke(context, response); } } return(response); }
public static void SetUriProcessResolver(this HttpRequestMessage request, IUriProcessResolver target) { request.Properties.Add(UriProcessResolverKey, target); }