internal static void InitRepo(Assembly callingAssembly) { repo = new PathRepo(); var referencedAssemblies = callingAssembly.GetReferencedAssemblies(); var currentAsm = Assembly.GetExecutingAssembly(); foreach (var refAsm in referencedAssemblies) { try { var asm = Assembly.LoadWithPartialName(refAsm.FullName); if (asm == currentAsm) { continue; } foreach (var typ in asm.GetTypes()) { if (typ.IsSubclassOf(typeof(RestService))) { var classAttribObj = typ.GetCustomAttributes(typeof(RestClass), false).FirstOrDefault(); string baseUrl; if (classAttribObj != null) { var classAttrib = (RestClass)classAttribObj; baseUrl = classAttrib.Path; } else { baseUrl = ""; } var methods = typ.GetMethods(); foreach (var method in methods) { var methodAttribObject = method.GetCustomAttributes(typeof(RestMethod), false).FirstOrDefault(); if (methodAttribObject != null) { var methodAttrib = (RestMethod)methodAttribObject; var finalUrl = baseUrl + (methodAttrib.Path == null ? "" : methodAttrib.Path); var finalMethod = methodAttrib.Method; PathExecutionInfo exeInfo = new PathExecutionInfo(); exeInfo.Type = typ; exeInfo.Method = method; repo.AddExecutionInfo(finalMethod, finalUrl, exeInfo); } } } } } catch (Exception ex) { } } }
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); }
internal void AddExecutionInfo(string method, string reqUrl, PathExecutionInfo value) { Dictionary <string, PathExecutionInfo> methodDic; if (!pathExecutionInfo.ContainsKey(method)) { methodDic = new Dictionary <string, PathExecutionInfo>(); pathExecutionInfo.Add(method, methodDic); } else { methodDic = pathExecutionInfo[method]; } if (!methodDic.ContainsKey(reqUrl)) { methodDic.Add(reqUrl, value); } }