Skip to content

Commit a3a5b70

Browse files
committed
feat: 将HttpClientApi相关功能从ServiceCodeGenerator迁移到独立的HttpUtils项目
重构HttpClientApi相关代码,将其从ServiceCodeGenerator项目中独立出来,创建新的HttpUtils项目。主要变更包括: - 创建新的Mud.HttpUtils项目结构 - 迁移所有HttpClientApi相关的模型、生成器和辅助类 - 更新项目引用和.gitignore配置 - 添加README文档说明 - 重命名接口方法ChangeCurrentContext为UseApp
1 parent a085866 commit a3a5b70

23 files changed

Lines changed: 276 additions & 77 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
/bin/Debug/netstandard2.0
1111
/Core/Mud.EntityCodeGenerator/obj
1212
/Core/Mud.ServiceCodeGenerator/obj
13+
/Core/Mud.HttpUtils/obj
14+
/Core/Mud.HttpUtils/Debug
1315
/bin/Debug
1416
/Test/Mud.Common.CodeGenerator/bin/Debug
1517
/Test/Mud.Common.CodeGenerator/obj
@@ -18,6 +20,7 @@
1820
/.vs/Mud.CodeGenerator/CopilotIndices/17.14.1147.5054
1921
/.vs
2022
/.docs
23+
/.comate
2124
/Test/CodeBaseTest/bin/Debug
2225
/Test/CodeBaseTest/obj
2326
/Test/DebugTest/bin/Debug/net8.0

Core/Mud.HttpUtils/GlobalUsings.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// -----------------------------------------------------------------------
2+
// 作者:Mud Studio 版权所有 (c) Mud Studio 2025
3+
// Mud.CodeGenerator 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
4+
// 本项目主要遵循 MIT 许可证进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 文件。
5+
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目开发而产生的一切法律纠纷和责任,我们不承担任何责任!
6+
// -----------------------------------------------------------------------
7+
8+
global using Microsoft.CodeAnalysis;
9+
global using Microsoft.CodeAnalysis.CSharp;
10+
global using Microsoft.CodeAnalysis.CSharp.Syntax;
11+
global using Microsoft.CodeAnalysis.Diagnostics;
12+
global using Microsoft.CodeAnalysis.Text;
13+
global using Mud.CodeGenerator;
14+
global using System;
15+
global using System.Collections.Generic;
16+
global using System.Collections.ObjectModel;
17+
global using System.Linq;
18+
global using System.Text;

Core/Mud.ServiceCodeGenerator/HttpInvoke/Generators/ClassStructureGenerator.cs renamed to Core/Mud.HttpUtils/HttpInvoke/Generators/ClassStructureGenerator.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目开发而产生的一切法律纠纷和责任,我们不承担任何责任!
66
// -----------------------------------------------------------------------
77

8-
using System.Text;
9-
10-
namespace Mud.ServiceCodeGenerator.HttpInvoke.Generators;
8+
namespace Mud.HttpUtils.HttpInvoke.Generators;
119

1210
/// <summary>
1311
/// 类结构生成器,负责生成实现类的结构声明

Core/Mud.ServiceCodeGenerator/HttpInvoke/Generators/ConstructorGenerator.cs renamed to Core/Mud.HttpUtils/HttpInvoke/Generators/ConstructorGenerator.cs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
using System.Text;
99

10-
namespace Mud.ServiceCodeGenerator.HttpInvoke.Generators;
10+
namespace Mud.HttpUtils.HttpInvoke.Generators;
1111

1212
/// <summary>
1313
/// 构造函数生成器,负责生成类的字段和构造函数
@@ -52,11 +52,10 @@ private void GenerateClassFields()
5252

5353
if (_context.HasInheritedFrom) return;
5454

55-
_codeBuilder.AppendLine(" /// <summary>");
56-
_codeBuilder.AppendLine(" /// 用于JSON内容序列化与反序列化操作的<see cref = \"JsonSerializerOptions\"/> 参数实例。");
57-
_codeBuilder.AppendLine(" /// </summary>");
58-
_codeBuilder.AppendLine($" {_context.FieldAccessibility}IMudAppContext _appContext;");
59-
55+
// _codeBuilder.AppendLine(" /// <summary>");
56+
// _codeBuilder.AppendLine(" /// 用于JSON内容序列化与反序列化操作的<see cref = \"JsonSerializerOptions\"/> 参数实例。");
57+
// _codeBuilder.AppendLine(" /// </summary>");
58+
// _codeBuilder.AppendLine($" {_context.FieldAccessibility}IMudAppContext _appContext;");
6059

6160
_codeBuilder.AppendLine(" /// <summary>");
6261
_codeBuilder.AppendLine(" /// 用于JSON内容序列化与反序列化操作的<see cref = \"JsonSerializerOptions\"/> 参数实例。");
@@ -145,7 +144,7 @@ private void GenerateConstructorBody()
145144
if (_context.HasTokenManager)
146145
{
147146
_codeBuilder.AppendLine(" _appManager = appManager ?? throw new ArgumentNullException(nameof(appManager));");
148-
_codeBuilder.AppendLine(" _appContext = appManager.GetDefaultApp();");
147+
// _codeBuilder.AppendLine(" _appContext = appManager.GetDefaultApp();");
149148
}
150149
}
151150

@@ -226,30 +225,30 @@ private void GenerateUseAppMethod()
226225
if (!_context.HasTokenManager)
227226
return;
228227

229-
_codeBuilder.AppendLine(" /// <summary>");
230-
_codeBuilder.AppendLine(" /// 切换到指定的飞书应用上下文。");
231-
_codeBuilder.AppendLine(" /// </summary>");
232-
_codeBuilder.AppendLine(" /// <returns>返回切换后的应用上下文。</returns>");
233-
_codeBuilder.AppendLine($" public IMudAppContext UseApp(string appKey)");
234-
_codeBuilder.AppendLine(" {");
235-
_codeBuilder.AppendLine(" _appContext = _appManager.GetApp(appKey);");
236-
_codeBuilder.AppendLine(" if(_appContext == null)");
237-
_codeBuilder.AppendLine(" throw new InvalidOperationException($\"无法找到指定的应用上下文,AppKey: {appKey}\");");
238-
_codeBuilder.AppendLine(" return _appContext;");
239-
_codeBuilder.AppendLine(" }");
240-
_codeBuilder.AppendLine();
241-
242-
_codeBuilder.AppendLine(" /// <summary>");
243-
_codeBuilder.AppendLine(" /// 切换到默认的飞书应用上下文。");
244-
_codeBuilder.AppendLine(" /// </summary>");
245-
_codeBuilder.AppendLine(" /// <returns>返回默认的应用上下文。</returns>");
246-
_codeBuilder.AppendLine($" public IMudAppContext UseDefaultApp()");
247-
_codeBuilder.AppendLine(" {");
248-
_codeBuilder.AppendLine(" _appContext = _appManager.GetDefaultApp();");
249-
_codeBuilder.AppendLine(" if(_appContext == null)");
250-
_codeBuilder.AppendLine(" throw new InvalidOperationException($\"无法找到默认的应用上下文。\");");
251-
_codeBuilder.AppendLine(" return _appContext;");
252-
_codeBuilder.AppendLine(" }");
253-
_codeBuilder.AppendLine();
228+
// _codeBuilder.AppendLine(" /// <summary>");
229+
// _codeBuilder.AppendLine(" /// 切换到指定的飞书应用上下文。");
230+
// _codeBuilder.AppendLine(" /// </summary>");
231+
// _codeBuilder.AppendLine(" /// <returns>返回切换后的应用上下文。</returns>");
232+
// _codeBuilder.AppendLine($" public IMudAppContext UseApp(string appKey)");
233+
// _codeBuilder.AppendLine(" {");
234+
// _codeBuilder.AppendLine(" _appContext = _appManager.GetApp(appKey);");
235+
// _codeBuilder.AppendLine(" if(_appContext == null)");
236+
// _codeBuilder.AppendLine(" throw new InvalidOperationException($\"无法找到指定的应用上下文,AppKey: {appKey}\");");
237+
// _codeBuilder.AppendLine(" return _appContext;");
238+
// _codeBuilder.AppendLine(" }");
239+
// _codeBuilder.AppendLine();
240+
241+
// _codeBuilder.AppendLine(" /// <summary>");
242+
// _codeBuilder.AppendLine(" /// 切换到默认的飞书应用上下文。");
243+
// _codeBuilder.AppendLine(" /// </summary>");
244+
// _codeBuilder.AppendLine(" /// <returns>返回默认的应用上下文。</returns>");
245+
// _codeBuilder.AppendLine($" public IMudAppContext UseDefaultApp()");
246+
// _codeBuilder.AppendLine(" {");
247+
// _codeBuilder.AppendLine(" _appContext = _appManager.GetDefaultApp();");
248+
// _codeBuilder.AppendLine(" if(_appContext == null)");
249+
// _codeBuilder.AppendLine(" throw new InvalidOperationException($\"无法找到默认的应用上下文。\");");
250+
// _codeBuilder.AppendLine(" return _appContext;");
251+
// _codeBuilder.AppendLine(" }");
252+
// _codeBuilder.AppendLine();
254253
}
255254
}

Core/Mud.ServiceCodeGenerator/HttpInvoke/Generators/InterfaceCodeGenerator.cs renamed to Core/Mud.HttpUtils/HttpInvoke/Generators/InterfaceCodeGenerator.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
// -----------------------------------------------------------------------
1+
// -----------------------------------------------------------------------
22
// 作者:Mud Studio 版权所有 (c) Mud Studio 2025
33
// Mud.CodeGenerator 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
44
// 本项目主要遵循 MIT 许可证进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 文件。
55
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目开发而产生的一切法律纠纷和责任,我们不承担任何责任!
66
// -----------------------------------------------------------------------
77

8-
using Microsoft.CodeAnalysis.Text;
9-
using Mud.ServiceCodeGenerator.HttpInvoke.Generators;
10-
using Mud.ServiceCodeGenerator.HttpInvoke.Helpers;
11-
using System.Text;
8+
using Mud.CodeGenerator;
9+
using Mud.HttpUtils.HttpInvoke.Generators;
10+
using Mud.HttpUtils.HttpInvoke.Helpers;
1211

13-
namespace Mud.ServiceCodeGenerator.HttpInvoke;
12+
namespace Mud.HttpUtils.HttpInvoke;
1413

1514

1615
internal class InterfaceImpCodeGenerator
@@ -223,7 +222,6 @@ private string GetHttpClientApiContentTypeFromAttribute(AttributeData? attribute
223222

224223

225224

226-
227225
private Configuration ExtractConfigurationFromAttributes()
228226
{
229227
return new Configuration
@@ -465,4 +463,4 @@ private void GenerateInterfaceHeaders(MethodAnalysisResult methodInfo)
465463
}
466464
}
467465
}
468-
}
466+
}

Core/Mud.ServiceCodeGenerator/HttpInvoke/Generators/RequestBuilder.cs renamed to Core/Mud.HttpUtils/HttpInvoke/Generators/RequestBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
using System.Text;
99

10-
namespace Mud.ServiceCodeGenerator.HttpInvoke.Generators;
10+
namespace Mud.HttpUtils.HttpInvoke.Generators;
1111

1212
/// <summary>
1313
/// HTTP 请求构建器,负责生成 HTTP 请求的构建逻辑
@@ -211,7 +211,7 @@ public void GenerateRequestExecution(StringBuilder codeBuilder, MethodAnalysisRe
211211
var deserializeType = methodInfo.IsAsyncMethod ? methodInfo.AsyncInnerReturnType : methodInfo.ReturnType;
212212
codeBuilder.AppendLine();
213213

214-
codeBuilder.AppendLine($" var httpClient = _appContext.HttpClient;");
214+
codeBuilder.AppendLine($" var httpClient = /*_appContext.HttpClient;*/ /* TODO: Replace with actual HttpClient access */");
215215
if (filePathParam != null)
216216
{
217217
codeBuilder.AppendLine($" await httpClient.DownloadLargeAsync(request, {filePathParam.Name}{cancellationTokenArg});");

Core/Mud.ServiceCodeGenerator/HttpInvoke/Helpers/BaseClassValidator.cs renamed to Core/Mud.HttpUtils/HttpInvoke/Helpers/BaseClassValidator.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目开发而产生的一切法律纠纷和责任,我们不承担任何责任!
66
// -----------------------------------------------------------------------
77

8-
9-
10-
using Microsoft.CodeAnalysis;
11-
using Microsoft.CodeAnalysis.CSharp.Syntax;
12-
13-
namespace Mud.ServiceCodeGenerator.HttpInvoke.Helpers;
8+
namespace Mud.HttpUtils.HttpInvoke.Helpers;
149

1510
/// <summary>
1611
/// 验证结果

Core/Mud.ServiceCodeGenerator/MethodHelper.cs renamed to Core/Mud.HttpUtils/HttpInvoke/Helpers/MethodHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
using System.Globalization;
99

10-
namespace Mud.ServiceCodeGenerator.HttpInvoke;
10+
namespace Mud.HttpUtils.HttpInvoke.Helpers;
1111

1212
/// <summary>
1313
/// 函数帮助类

Core/Mud.ServiceCodeGenerator/HttpInvoke/Helpers/ParameterValidationHelper.cs renamed to Core/Mud.HttpUtils/HttpInvoke/Helpers/ParameterValidationHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
using System.Text;
99

10-
namespace Mud.ServiceCodeGenerator.HttpInvoke.Helpers;
10+
namespace Mud.HttpUtils.HttpInvoke.Helpers;
1111

1212
/// <summary>
1313
/// 参数验证辅助类,负责生成参数验证代码

Core/Mud.ServiceCodeGenerator/HttpInvoke/HttpInvokeBaseSourceGenerator.cs renamed to Core/Mud.HttpUtils/HttpInvoke/HttpInvokeBaseSourceGenerator.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
using Microsoft.CodeAnalysis.Diagnostics;
99
using System.Collections.Immutable;
10+
using Mud.CodeGenerator;
1011

11-
namespace Mud.ServiceCodeGenerator.HttpInvoke;
12+
namespace Mud.HttpUtils.HttpInvoke;
1213

1314
/// <summary>
1415
/// 生成Http调用代码的源代码生成器基类
@@ -216,4 +217,4 @@ protected IReadOnlyList<string> GenerateCorrectParameterCallList(IReadOnlyList<P
216217
return callParameters;
217218
}
218219
#endregion
219-
}
220+
}

0 commit comments

Comments
 (0)