public Task Invoke(HttpContext context, string path) { // 获取申请器 var request = context.Request; // Program.Println($"[*] 包 {this.Name} 接受 {request.Method} {path} ..."); // 执行事件 switch (request.Method) { case "POST": // 遍历所有注册接口 foreach (var info in Posts) { if (path == info.Route) { return(ExecuteMethod(context, info)); } } break; case "GET": // 遍历所有注册接口 foreach (var info in Gets) { if (path == info.Route) { return(ExecuteMethod(context, info)); } } // 判断是否存在静态文件 string filePath = $"{this.RootPath}{path.Replace('/', it.SplitChar)}"; Program.Println($"[*] 查找静态文件 {filePath} ..."); if (System.IO.File.Exists(filePath)) { Program.Println($"[*] 输出文件 {filePath} ..."); string ext = System.IO.Path.GetExtension(filePath).ToLower(); if (_mimes.ContainsKey(ext)) { // Program.Println($"[*] 输出mime {_mimes[ext]} ..."); context.Response.ContentType = _mimes[ext]; } return(context.Response.SendFileAsync(filePath)); } break; } return(null); }
// 加载页面 private void LoadPages(TreeNode node, string path) { // 判断当前目录是否存在配置文件 if (!path.EndsWith("\\")) { path += "\\"; } string jsonPath = $"{path}config.json"; if (System.IO.File.Exists(jsonPath)) { // 读取文件内容 string content = dpz3.File.UTF8File.ReadAllText(jsonPath); using (var json = dpz3.Json.Parser.ParseJson(content)) { // 产生新的信息 string workFolderPages = it.WorkPath + "\\wwwroot\\"; string pathPart = path.Substring(workFolderPages.Length, path.Length - workFolderPages.Length - 1); string guid = null; do { guid = Guid.NewGuid().ToString(); } while (_pages.ContainsKey(guid)); _pages[guid] = path; // 设置表节点 TreeNode nodePage = new TreeNode(); nodePage.Name = guid; nodePage.Text = $"{json.Str["Name"]} [{pathPart}]"; nodePage.ImageIndex = 4; nodePage.SelectedImageIndex = 4; nodePage.ContextMenuStrip = this.contextMenuPage; node.Nodes.Add(nodePage); } } else { // 遍历子目录查询 string[] dirs = System.IO.Directory.GetDirectories(path); foreach (var dir in dirs) { LoadPages(node, dir); } } }