internal static void Process(HttpContext context) { FrameworkResponse frmRes = new FrameworkResponse(); HttpRequest req = context.Request; HttpResponse res = context.Response; var relUrl = req.Url.ToString().Replace("http://" + req.Url.Authority, ""); PathExecutionParams exeParams = repo[req.HttpMethod, relUrl]; try { if (exeParams != null) { object newObj = Activator.CreateInstance(exeParams.ExecutionInfo.Type); var exeMethod = exeParams.ExecutionInfo.Method; List <object> activatorParams = new List <object>(); var methodParams = exeMethod.GetParameters(); foreach (var mParam in methodParams) { if (exeParams.Parameters.ContainsKey(mParam.Name)) { var strValue = exeParams.Parameters[mParam.Name]; object convertedValue = Convert.ChangeType(strValue, mParam.ParameterType); activatorParams.Add(convertedValue); } else { throw new ParameterMismatchException(); } } object output = exeMethod.Invoke(newObj, activatorParams.ToArray()); frmRes.Success = true; frmRes.Result = output; res.ContentType = "application/json"; } else { res.ContentType = "application/json"; frmRes.Success = false; frmRes.Result = "404 Not Found"; res.StatusCode = 404; } } catch (Exception ex) { res.ContentType = "application/json"; frmRes.Success = false; frmRes.Result = ex; res.StatusCode = 500; } res.Write(getJson(frmRes)); }
private static string getJson(FrameworkResponse response) { return(JsonConvert.SerializeObject(response)); }