private Task StartDashboardAsync() { httpServer.RequestError += async(e, req) => { logger.LogError("config server errror", e); return(await HttpResponseHelper.CreateDefaultErrorResponseAsync(req)); }; return(httpServer.ListenAsync()); }
public override async Task <HttpResponse> Invoke(HttpRequest httpRequest) { try { var context = new ActionExecuteContext { HttpRequest = httpRequest }; var(controller, methodInfo, parameter) = route.Route(httpRequest); if (controller == null) { return(await HttpResponseHelper.CreateNotFoundResponseAsync()); } context.Controller = controller; context.Action = methodInfo; ((ControllerBase)controller).Request = httpRequest; var filterList = GetFilters(controller, methodInfo); var stack = new Stack <IFilter>(); for (var i = 0; i < filterList.Count; i++) { var filter = filterList[i]; await filter.OnActionExecutingAsync(context); if (context.Final) { return(context.HttpResponse); } stack.Push(filter); } await controller.OnActionExecutingAsync(context); if (context.Final) { return(context.HttpResponse); } var parameters = new List <object>(); if (parameter != null) { parameters.Add(parameter); } if (methodInfo.ReturnType.IsGenericType) //Task<IActionResult> { var actionResult = await(methodInfo.Invoke(controller, parameters.ToArray()) as Task <IActionResult>); context.HttpResponse = await actionResult.ExecuteResultAsync(); } else { var actionResult = methodInfo.Invoke(controller, parameters.ToArray()) as IActionResult; context.HttpResponse = await actionResult.ExecuteResultAsync(); } context.HttpResponse.Cookies.AddRange(controller.ResponseCookie); await controller.OnActionExecutedAsync(context); if (context.Final) { return(context.HttpResponse); } while (stack.Count != 0) { var filter = stack.Pop(); await filter.OnActionExecutedAsync(context); if (context.Final) { return(context.HttpResponse); } } return(context.HttpResponse); } catch (Exception e) { return(await HttpResponseHelper.CreateDefaultErrorResponseAsync(e)); } }