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 PathExecutionParams getExecutionParams(string method, string reqUrl) { PathExecutionParams executionParams = null; bool isFound = false; Dictionary <string, string> variables = null; PathExecutionInfo executionInfo = null; string[] urlSplit = reqUrl.Split('/'); if (pathExecutionInfo.ContainsKey(method)) { variables = new Dictionary <string, string>(); foreach (KeyValuePair <string, PathExecutionInfo> onePath in pathExecutionInfo[method]) { string[] definedPathSplit = onePath.Key.Split('/'); if (definedPathSplit.Length == urlSplit.Length) { variables.Clear(); isFound = true; for (int i = 0; i < definedPathSplit.Length; i++) { if (definedPathSplit[i].StartsWith("@")) { variables.Add(definedPathSplit[i].Substring(1), urlSplit[i]); } else { if (definedPathSplit[i] != urlSplit[i]) { isFound = false; break; } } } } if (isFound) { executionInfo = onePath.Value; break; } } } if (isFound) { executionParams = new PathExecutionParams(); executionParams.ExecutionInfo = executionInfo; executionParams.Parameters = variables; } return(executionParams); }