|
1 | 1 | using Microsoft.AspNetCore.Mvc; |
2 | 2 | using Microsoft.Extensions.DependencyInjection; |
3 | 3 | using Senparc.CO2NET.ApiBind; |
| 4 | +using Senparc.CO2NET.Trace; |
4 | 5 | using System; |
5 | 6 | using System.Collections.Concurrent; |
6 | 7 | using System.Collections.Generic; |
@@ -110,25 +111,33 @@ private static void AddAndInitDynamicApi(this IServiceCollection services, (IMvc |
110 | 111 | var threadIndex = i; |
111 | 112 | var wrapperTask = Task.Factory.StartNew(async () => |
112 | 113 | { |
113 | | - //此处使用 Task 效率并不比 Keys.ToList() 方法快 |
114 | | - webApiEngine.WriteLog($"Get API Groups: {threadIndex + 1}/{apiGouupsCount}, now dealing with: {category}"); |
115 | | - var dtStart = SystemTime.Now; |
116 | | - var apiBindGroup = apiGroups.FirstOrDefault(z => z.Key == category); |
117 | | - |
118 | | - var apiCount = await webApiEngine.BuildWebApi(apiBindGroup).ConfigureAwait(false); |
119 | | - var apiAssembly = webApiEngine.GetApiAssembly(category); |
120 | | - |
121 | | - //程序部件:https://docs.microsoft.com/zh-cn/aspnet/core/mvc/advanced/app-parts?view=aspnetcore-2.2 |
122 | | - if (builder.coreBuilder != null) |
| 114 | + try |
123 | 115 | { |
124 | | - builder.coreBuilder.AddApplicationPart(apiAssembly); |
| 116 | + |
| 117 | + //此处使用 Task 效率并不比 Keys.ToList() 方法快 |
| 118 | + webApiEngine.WriteLog($"Get API Groups: {threadIndex + 1}/{apiGouupsCount}, now dealing with: {category}"); |
| 119 | + var dtStart = SystemTime.Now; |
| 120 | + var apiBindGroup = apiGroups.FirstOrDefault(z => z.Key == category); |
| 121 | + |
| 122 | + var apiCount = await webApiEngine.BuildWebApi(apiBindGroup).ConfigureAwait(false); |
| 123 | + var apiAssembly = webApiEngine.GetApiAssembly(category); |
| 124 | + |
| 125 | + //程序部件:https://docs.microsoft.com/zh-cn/aspnet/core/mvc/advanced/app-parts?view=aspnetcore-2.2 |
| 126 | + if (builder.coreBuilder != null) |
| 127 | + { |
| 128 | + builder.coreBuilder.AddApplicationPart(apiAssembly); |
| 129 | + } |
| 130 | + else |
| 131 | + { |
| 132 | + builder.builder.AddApplicationPart(apiAssembly); |
| 133 | + } |
| 134 | + |
| 135 | + assemblyBuildStat[category] = (apiCount: apiCount, costMs: SystemTime.DiffTotalMS(dtStart)); |
125 | 136 | } |
126 | | - else |
| 137 | + catch (Exception ex) |
127 | 138 | { |
128 | | - builder.builder.AddApplicationPart(apiAssembly); |
| 139 | + SenparcTrace.BaseExceptionLog(ex); |
129 | 140 | } |
130 | | - |
131 | | - assemblyBuildStat[category] = (apiCount: apiCount, costMs: SystemTime.DiffTotalMS(dtStart)); |
132 | 141 | }); |
133 | 142 | taskList.Add(wrapperTask.Unwrap()); |
134 | 143 | } |
|
0 commit comments