예제 #1
0
        private void OnExecuteRoute(HttpRequest request, HttpResponse response)
        {
            var route  = ServiceRoute.Parse(request);
            var module = _modules.FirstOrDefault(m => m.SearchRoute(route));

            if (module == null)
            {
                response.Error("地址不存在").Send();
                return;
            }

            var result = module.ExecuteRoute(route, request);

            if (!result.Success)
            {
                response.FromText(result.Message.ToString()).Send();
                return;
            }

            if (result.GetType() == typeof(JsonSuccess) && result.Result != null)
            {
                response.FromJson(result.Result).Send();
            }
            else
            {
                response.FromText(result.Result.ToString()).Send();
            }
        }
예제 #2
0
        private void OnExecuteRoute(HttpRequest request, HttpResponse response)
        {
            var route  = ServiceRoute.Parse(request);
            var module = _modules.FirstOrDefault(m => m.SearchRoute(route));

            if (module == null)
            {
                response.Error("地址不存在").Send();
                return;
            }

            var result = module.ExecuteRoute(route, request);

            if (result is IJsonResult)
            {
                response.FromJson(result).Send();
            }
            else if (result is ActionResult actionResult)
            {
                response.FromText(actionResult.Data.ToString()).Send();
            }
        }