public static void Get(GetInterceptor interceptor) { Type type = interceptor.GetType(); if (Gets.ContainsKey(type)) { return; } Gets.Add(type, interceptor); }
public IDictionary <string, object> Get(DocumentTable table, string key) { Gets.Add(Tuple.Create(table, key)); return(store.Get(table, key)); }
// 注册类库 private void RegLibrary(string path) { Program.Println($" 正在注册类库 {path} ..."); // 加载类库 Assembly assembly = Assembly.LoadFile(path); // 遍历类库中的所有类 var tps = assembly.GetTypes(); foreach (var tp in tps) { // 遍历类型特性,判断类是否满足条件 var attrs = tp.GetCustomAttributes(); foreach (var attr in attrs) { if (attr.GetType().FullName == "dpz3.Modular.ModularAttribute") { // 重建模块化特性 dpz3.Modular.ModularAttribute modular = (dpz3.Modular.ModularAttribute)attr; // 找到Api定义类 switch (modular.ModularType) { case ModularTypes.Api: case ModularTypes.Session: case ModularTypes.SessionApi: // 读取路由地址定义 string route = modular.Route.Replace("{ControllerName}", tp.Name); // 确定类名称 string className = ""; switch (modular.ModularType) { case ModularTypes.Api: className = "ControllerBase"; break; case ModularTypes.Session: className = "SessionControllerBase"; break; case ModularTypes.SessionApi: className = "JttpSessionControllerBase"; break; } // 遍历所有的函数定义 var methods = tp.GetMethods(); foreach (var method in methods) { // 遍历函数特性,判断函数是否满足条件 var methodAttrs = method.GetCustomAttributes(); foreach (var methodAttr in methodAttrs) { if (methodAttr.GetType().FullName == "dpz3.Modular.ModularAttribute") { // 重建模块化特性 dpz3.Modular.ModularAttribute methodModular = (dpz3.Modular.ModularAttribute)methodAttr; string routeNew = $"{route}/{methodModular.Route}".ToLower(); ModularMethodInfo methodInfo = new ModularMethodInfo() { Method = method, Assembly = assembly, Type = tp, Route = routeNew, ClassName = className, }; switch (methodModular.ModularType) { case dpz3.Modular.ModularTypes.Post: // 添加一条POST接口信息 Program.Println($"[@] POST /{this.Name}{routeNew} ..."); Posts.Add(methodInfo); break; case dpz3.Modular.ModularTypes.Get: // 添加一条GET接口信息 Program.Println($"[@] GET /{this.Name}{routeNew} ..."); Gets.Add(methodInfo); // 处理特殊的首页 if (routeNew.EndsWith("/index")) { routeNew = routeNew.Substring(0, routeNew.Length - 5); // 添加一条GET接口信息 Program.Println($"[@] GET /{this.Name}{routeNew} ..."); Gets.Add(new ModularMethodInfo() { Method = method, Assembly = assembly, Type = tp, Route = routeNew, ClassName = className, }); } break; } // 结束特性循环 break; } } } break; } // 结束特性循环 break; } } } }