public DirectRequest[] BuildFromFormData(NameValueCollection form) { var request = new DirectRequest(); var data = new JObject(); foreach(string key in form.AllKeys) { switch(key) { case "extTID": request.Tid = int.Parse(form[key]); break; case "extAction": request.Action = form[key]; break; case "extMethod": request.Method = form[key]; break; case "extType": request.Type = form[key]; break; case "extUpload": request.Upload = bool.Parse(form[key]); break; default: data.Add(key, new JValue(form[key])); break; } } request.Data = data; return new[] { request }; }
public DirectResponse(DirectRequest request, Exception e) : this(request) { Type = "exception"; Message = e.Message; Where = e.ToString(); }
public DirectRequest[] BuildFromFormData(NameValueCollection form, IDictionary<string, Stream> files) { var request = new DirectRequest(); foreach(string key in form.AllKeys) { switch(key) { case "extTID": request.Tid = Int32.Parse(form[key]); break; case "extAction": request.Action = form[key]; break; case "extMethod": request.Method = form[key]; break; case "extType": request.Type = form[key]; break; case "extUpload": request.Upload = Boolean.Parse(form[key]); break; default: request.FormData.Add(key, form[key]); break; } } foreach (var kvp in files) { request.FormData.Add(kvp.Key, kvp.Value); } return new[] { request }; }
public DirectResponse(DirectRequest request) { Action = request.Action; Method = request.Method; Tid = request.Tid; Type = request.Type; }
internal DirectResponse Handle(DirectRequest request, JsonSerializer jsonSerializer, MethodInfo methodInfo, object actionInstance, Type type) { actionInstance = actionInstance ?? Activator.CreateInstance(type); jsonSerializer = jsonSerializer ?? new JsonSerializer { ContractResolver = new CamelCasePropertyNamesContractResolver() }; object[] parameters = _parametersParser.Parse(methodInfo.GetParameters(), request.JsonData, request.FormData, jsonSerializer); object result = methodInfo.Invoke(actionInstance, parameters); return new DirectResponse(request, SerializeResult(result, jsonSerializer)); }
internal DirectResponse Handle(DirectRequest request, JsonSerializer jsonSerializer, MethodInfo methodInfo, object actionInstance, Type type) { actionInstance = actionInstance ?? Activator.CreateInstance(type); jsonSerializer = jsonSerializer ?? new JsonSerializer { ContractResolver = new CamelCasePropertyNamesContractResolver() }; object[] parameters = _parametersParser.Parse(methodInfo.GetParameters(), request.JsonData, request.FormData, jsonSerializer); object result = methodInfo.Invoke(actionInstance, parameters); return(new DirectResponse(request, SerializeResult(result, jsonSerializer))); }
public DirectResponse Handle(DirectRequest request) { JsonSerializer jsonSerializer = _objectFactory.GetJsonSerializer(); try { return Handle(request, jsonSerializer); } finally { _objectFactory.Release(jsonSerializer); } }
private DirectResponse Handle(DirectRequest request, JsonSerializer jsonSerializer) { object actionInstance = _objectFactory.GetInstance(_metadata.GetActionType(request.Action)); try { return Handle(request, jsonSerializer, actionInstance); } finally { _objectFactory.Release(actionInstance); } }
internal DirectResponse Handle(DirectRequest request, JsonSerializer jsonSerializer, object actionInstance) { var response = new DirectResponse(request); MethodInfo methodInfo = _metadata.GetMethodInfo(request.Action, request.Method); object result = null; try { object[] parameters = _parametersParser.Parse(methodInfo.GetParameters(), request.JsonData, request.FormData, jsonSerializer); result = methodInfo.Invoke(actionInstance, parameters); } catch(TargetInvocationException e) { response.SetException(e.InnerException); } catch(Exception e) { response.SetException(e); } response.Result = SerializeResult(result, jsonSerializer); return response; }
internal DirectResponse Handle(DirectRequest request, JsonSerializer jsonSerializer, object actionInstance) { var response = new DirectResponse(request); MethodInfo methodInfo = _metadata.GetMethodInfo(request.Action, request.Method); object result = null; try { object[] parameters = (request.Data.Type == JTokenType.Array ? _parameterValuesParser.ParseByPosition(methodInfo.GetParameters(), (JArray)request.Data, jsonSerializer) : _parameterValuesParser.ParseByName(methodInfo.GetParameters(), (JObject)request.Data, jsonSerializer)); result = methodInfo.Invoke(actionInstance, parameters); } catch(TargetInvocationException e) { response.SetException(e.InnerException); } catch(Exception e) { response.SetException(e); } response.Result = SerializeResult(result, jsonSerializer); return response; }
public DirectResponse Handle(DirectRequest request) { try { Type type = _metadata.GetActionType(request.Action, request.Method); MethodInfo methodInfo = _metadata.GetMethodInfo(request.Action, request.Method); var response = new DirectResponse(request); _directHandlerInterceptor.Invoke(type, methodInfo, delegate(object actionInstance, JsonSerializer jsonSerializer) { response = Handle(request, jsonSerializer, methodInfo, actionInstance, type); }); return response; //JsonSerializer jsonSerializer = _objectFactory.GetJsonSerializer(); //try //{ // object actionInstance = _objectFactory.GetInstance(type); // try // { // return Handle(request, jsonSerializer, methodInfo, actionInstance); // } // finally // { // _objectFactory.Release(actionInstance); // } //} //finally //{ // _objectFactory.Release(jsonSerializer); //} } catch(TargetInvocationException e) { return new DirectResponse(request, e.InnerException); } catch(Exception e) { return new DirectResponse(request, e); } }
public DirectResponse Handle(DirectRequest request) { try { Type type = _metadata.GetActionType(request.Action, request.Method); MethodInfo methodInfo = _metadata.GetMethodInfo(request.Action, request.Method); var response = new DirectResponse(request); _directHandlerInterceptor.Invoke(type, methodInfo, delegate(object actionInstance, JsonSerializer jsonSerializer) { response = Handle(request, jsonSerializer, methodInfo, actionInstance, type); }); return(response); //JsonSerializer jsonSerializer = _objectFactory.GetJsonSerializer(); //try //{ // object actionInstance = _objectFactory.GetInstance(type); // try // { // return Handle(request, jsonSerializer, methodInfo, actionInstance); // } // finally // { // _objectFactory.Release(actionInstance); // } //} //finally //{ // _objectFactory.Release(jsonSerializer); //} } catch (TargetInvocationException e) { return(new DirectResponse(request, e.InnerException)); } catch (Exception e) { return(new DirectResponse(request, e)); } }
public DirectRequest[] BuildFromFormData(NameValueCollection form, Dictionary <string, HttpPostedFile> files) { var request = new DirectRequest(); foreach (string key in form.AllKeys) { switch (key) { case "extTID": request.Tid = Int32.Parse(form[key]); break; case "extAction": request.Action = form[key]; break; case "extMethod": request.Method = form[key]; break; case "extType": request.Type = form[key]; break; case "extUpload": request.Upload = Boolean.Parse(form[key]); break; default: request.FormData.Add(key, form[key]); break; } } foreach (var kvp in files) { request.FormData.Add(kvp.Key, kvp.Value); } return(new[] { request }); }
public DirectResponse(DirectRequest request, JToken result) : this(request) { Result = result; }