Esempio n. 1
0
        public static IDictionary <string, object> MergeDictionary(params IDictionary <string, object>[] sources)
        {
            IDictionary <string, object> result = new Dictionary <string, object>();

            RequestDataHelper.MergeDictionary(ref result, sources);
            return(result);
        }
Esempio n. 2
0
 public static void InitParams(HttpContext httpContext)
 {
     if (threadLocalParams.Value == null)
     {
         IDictionary <string, object> queryParams = RequestDataHelper.GetQueryParameters(httpContext.Request);
         IDictionary <string, object> formData    = RequestDataHelper.GetFormParameters(httpContext.Request);
         object body = RequestDataHelper.GetBodyJsonParameters(httpContext.Request, httpContext.Response);
         IDictionary <string, IList <IFormFile> > files   = RequestDataHelper.GetFormFiles(httpContext.Request);
         IDictionary <string, object>             headers = RequestDataHelper.GetRequestHeaders(httpContext.Request);
         IDictionary <string, object>             cookies = RequestDataHelper.GetRequestCookies(httpContext.Request);
         var mixParams = RequestDataHelper.MixParameters(queryParams, formData, body);
         threadLocalParams.Value = new ReqestParams(httpContext, queryParams, files, headers, cookies, formData, mixParams, body);
     }
 }
Esempio n. 3
0
        private static IDictionary <string, object> MixParameters(IDictionary <string, object> query, IDictionary <string, object> formData, object bodyJson)
        {
            var parameters = RequestDataHelper.MergeDictionary(query, formData);

            if (bodyJson is IDictionary <string, object> )
            {
                IDictionary <string, object> bodyParams = (IDictionary <string, object>)bodyJson;
                parameters = RequestDataHelper.MergeDictionary(parameters, bodyParams);
            }
            else
            {
                parameters["__BodyJson"] = bodyJson;
            }
            return(parameters);
        }
Esempio n. 4
0
 private static object GetBodyJsonParameters(HttpRequest request, HttpResponse response)
 {
     if (request.ContentType == "application/json")
     {
         response.ContentType = "application/json";
         request.EnableRewind();
         request.Body.Position = 0;
         var body = request.Body;
         if (body.Length > 0)
         {
             using (var reader = new StreamReader(body))
             {
                 var content = reader.ReadToEnd();
                 request.Body.Position = 0;
                 var result = JsonConvert.DeserializeObject(content);
                 if (result is JObject)
                 {
                     return(((JObject)result).ToObject <IDictionary <string, object> >());
                 }
                 else
                 {
                     return(result);
                 }
             }
         }
     }
     else if (request.ContentType == "text/plain")
     {
         request.EnableRewind();
         request.Body.Position = 0;
         var body = request.Body;
         if (body.Length > 0)
         {
             using (var reader = new StreamReader(body))
             {
                 var content = reader.ReadToEnd();
                 request.Body.Position = 0;
                 return(RequestDataHelper.BuildPlainTextParameters(content));
             }
         }
     }
     return(null);
 }