public override void ExecuteResult(ControllerContext context)
        {
            HttpBaseContext baseContext = context.RequestContext.Context;

            if (this.Code != default)
            {
                this.Code = ResponseCode.Success;
            }
            if (String.IsNullOrEmpty(this.Message))
            {
                this.Message = ResponseCodeString.Message(this.Code);
            }
            baseContext.Response.ResponseContent = JsonConvert.SerializeObject(this);
        }
Esempio n. 2
0
 public RouteData GetRouteData(HttpBaseContext httpContext)
 {
     if (!String.IsNullOrWhiteSpace(m_ignore) && Regex.IsMatch(httpContext.Request.Uri.ToString(), m_ignore))
     {
         return(null);
     }
     foreach (var route in this)
     {
         RouteData routeData = route.GetRouteData(httpContext);
         if (routeData != null)
         {
             return(routeData);
         }
     }
     return(null);
 }
        /// <summary>
        /// 这里实质是通过http去做解析,但是这里就做了一个简单的类型,实现后期功能
        /// </summary>
        /// <param name="model"></param>
        public void Execute(HttpTranferModel model)
        {
            HttpBaseContext context = m_application.CreateContext();

            context.Request.Headers        = JsonConvert.SerializeObject(model.Headers);
            context.Request.RequestContent = JsonConvert.SerializeObject(model.Body);
            foreach (var item in model.QueryParams)
            {
                context.Request.QueryParams += item.Key + "=" + item.Value + "&";
            }
            context.Request.Uri = model.Url;
            Task task = m_application.ProcessRequestAsync(context);

            task.ContinueWith(t => Console.WriteLine("请求结束"));
            task.ContinueWith(t => Console.WriteLine("请求报错,错误为" + t.Exception), TaskContinuationOptions.OnlyOnFaulted);
            task.Start();
        }
Esempio n. 4
0

        
Esempio n. 5
0
        public void Init(HttpBaseContext context)
        {
            RouteData routeData = RouteTable.Routes.GetRouteData(context);

            if (routeData == null)
            {
                return;
            }
            RequestContext request = new RequestContext()
            {
                Context   = context,
                RouteData = routeData
            };
            IApiHandler handler = routeData.RouteHandler.GetApiHandler(request);

            handler.ProcessRequest();
            Console.WriteLine(request.Context.Response.ResponseContent);
        }
Esempio n. 6
0
 public abstract RouteData GetRouteData(HttpBaseContext httpContext);