瀏覽代碼

WebApi改为MiniApi

warr.qian 1 年之前
父節點
當前提交
f5379d7196

+ 7 - 3
Tools/MiniWebApi/Network/WebApiRouter.cs

@@ -24,6 +24,7 @@ namespace MiniWebApi.Network
 
         public WebApiRouter(string applicationName, Assembly assembly)
         {
+            File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"ApiLog.txt"),$"Register Start {assembly.FullName}\n");
             _assembly = assembly;
             _applicationName = applicationName;
             _applicationName = _applicationName == null ? string.Empty : _applicationName.ToLower();
@@ -67,10 +68,12 @@ namespace MiniWebApi.Network
             {
                 _assembly = Assembly.GetEntryAssembly();
             }
-            var handlerTypes = _assembly. GetTypes().Where(x =>
-                typeof(BaseHandler).IsAssignableFrom(x) && x != typeof(BaseHandler)).ToArray();
+            File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"ApiLog.txt"),$"RegisterHandlers Start {_assembly.FullName}\n");
+            var handlerTypes = _assembly.GetTypes().Where(x =>
+                x.IsSubclassOf(typeof(BaseHandler)) && x != typeof(BaseHandler)).ToArray();
             foreach (var handlerType in handlerTypes)
             {
+                File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"ApiLog.txt"),$"Register handlerType:{handlerType.Name}\n");
                 var handlerAttrs = handlerType.GetCustomAttributes(typeof(WebApiHandlerAttribute), false);
                 if (handlerAttrs.Length > 0)
                 {
@@ -81,7 +84,7 @@ namespace MiniWebApi.Network
                     {
                         _handlers.Add(key, (BaseHandler)handlerType.New());
                     }
-                    //Logger.WriteLineInfo($"Register handler:{key}");
+                    File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"ApiLog.txt"),$"Register handler:{key}\n");
                 }
             }
         }
@@ -178,6 +181,7 @@ namespace MiniWebApi.Network
 
             if (!handlerExist)
             {
+                Console.WriteLine($"Handlers {_handlers.Keys}");
                 Console.WriteLine($"Handler for request: {context.Request.Url} not found.");
                 context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                 context.Response.Close();

+ 10 - 5
Tools/MiniWebApi/Utilities/WebApiUrlInfoParser.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Text;
 
 namespace MiniWebApi.Utilities
 {
@@ -52,15 +53,19 @@ namespace MiniWebApi.Utilities
             {
                 // AppName/Version/HandlerName/ActionName
                 // AppName/HandlerName/ActionName
-                if (urlParts.Length < 2 || urlParts.Length > 4) return null;
-                if (urlParts.Length == 4)
+                if (urlParts.Length < 2) return null;
+                if (urlParts.Length >= 4)
                 {
                     //Contains version.
                     urlApplicationName = urlParts[0].ToLower();
-                    urlVersion = urlParts[1].ToLower();
-                    urlHandlerName = urlParts[2].ToLower();
+                    var urlHandlerNameBuilder = new StringBuilder($"{urlParts[1].ToLower()}");
+                    for(int i=1;i<urlParts.Length-2;i++)
+                    {
+                        urlHandlerNameBuilder.Append($"/{urlParts[i+1].ToLower()}");
+                    }
+                    urlHandlerName = urlHandlerNameBuilder.ToString();
                     //Action name can not to lower
-                    urlActionName = urlParts[3].ToLower();
+                    urlActionName = urlParts[^1].ToLower();
                 }
                 else if(urlParts.Length == 3)
                 {

+ 2 - 1
src/Plugin/TokenVerifyPluginService.cs

@@ -146,7 +146,8 @@ namespace WingCloudServer.Plugin
             "IVinnoIOTService/CheckVersion",
             "IVitalExamService/GetExamListByPhysicalExamNumberAsync",
             "IVitalElectrocardiogramService/GetElectrocardiogramRecordByPhysicalExamNumberAsync",
-            "IReportService/GetVitalReportInfoAsync"
+            "IReportService/GetVitalReportInfoAsync",
+            "IVitalAnalyzeConfigService/GetAnalyzeConfigPageAsync"
         };
 
         public PluginProcessResult PreProcess(IJsonRpcHttpContext context, byte[] requestData)