Skip to content

Commit

Permalink
😊 完成 新版本远程请求功能重构和全部文档
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkSoul committed Nov 26, 2024
1 parent f874011 commit d75b514
Show file tree
Hide file tree
Showing 92 changed files with 1,267 additions and 786 deletions.
3 changes: 2 additions & 1 deletion .gitee/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ body:
label: 版本号
description: 请选择项目使用的 Furion 版本?
options:
- 4.9.5.26 (最新)
- 4.9.6 (最新)
- 4.9.5.26
- 4.9.5.25
- 4.9.5.24
- 4.9.5.23
Expand Down
2 changes: 1 addition & 1 deletion framework/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<LangVersion>preview</LangVersion>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<Version>4.9.5.26</Version>
<Version>4.9.6</Version>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Authors>百小僧</Authors>
Expand Down
2 changes: 1 addition & 1 deletion framework/Furion.Pure/Furion.Pure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<ItemGroup>
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.3.8" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// ------------------------------------------------------------------------
// 版权信息
// 版权归百小僧及百签科技(广东)有限公司所有。
// 所有权利保留。
// 官方网站:https://baiqian.com
//
// 许可证信息
// Furion 项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// 官方网站:https://furion.net
//
// 使用条款
// 使用本代码应遵守相关法律法规和许可证的要求。
//
// 免责声明
// 对于因使用本代码而产生的任何直接、间接、偶然、特殊或后果性损害,我们不承担任何责任。
//
// 其他重要信息
// Furion 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。
// 有关 Furion 项目的其他详细信息,请参阅位于源代码树根目录中的 COPYRIGHT 和 DISCLAIMER 文件。
//
// 更多信息
// 请访问 https://gitee.com/dotnetchina/Furion 获取更多关于 Furion 项目的许可证和版权信息。
// ------------------------------------------------------------------------

namespace Furion.Extensions;

/// <summary>
/// <see cref="EventHandler{TEventArgs}" /> 拓展类
/// </summary>
internal static class EventHandlerExtensions
{
/// <summary>
/// 尝试执行事件处理程序
/// </summary>
/// <param name="handler">
/// <see cref="EventHandler{TEventArgs}" />
/// </param>
/// <param name="sender">
/// <see cref="object" />
/// </param>
/// <param name="args">
/// <typeparamref name="TEventArgs" />
/// </param>
/// <typeparam name="TEventArgs">事件参数</typeparam>
internal static void TryInvoke<TEventArgs>(this EventHandler<TEventArgs>? handler, object? sender, TEventArgs args)
{
// 空检查
if (handler is null)
{
return;
}

try
{
handler(sender, args);
}
catch (Exception e)
{
// 输出调试事件
Debugging.Error(e.Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ internal HttpFileDownloadBuilder(HttpMethod httpMethod, Uri? requestUri)
/// </summary>
public Action<Exception>? OnTransferFailed { get; private set; }

/// <summary>
/// 用于处理在文件存在且配置为跳过时的操作
/// </summary>
public Action? OnFileExistAndSkip { get; private set; }

/// <summary>
/// 用于传输进度发生变化时的操作
/// </summary>
Expand Down Expand Up @@ -151,23 +156,6 @@ public HttpFileDownloadBuilder SetDestinationPath(string? destinationPath)
return this;
}

/// <summary>
/// 设置用于传输进度发生变化时执行的委托
/// </summary>
/// <param name="configure">自定义配置委托</param>
/// <returns>
/// <see cref="HttpFileDownloadBuilder" />
/// </returns>
public HttpFileDownloadBuilder SetOnProgressChanged(Func<FileTransferProgress, Task> configure)
{
// 空检查
ArgumentNullException.ThrowIfNull(configure);

OnProgressChanged = configure;

return this;
}

/// <summary>
/// 设置当目标文件已存在时的行为
/// </summary>
Expand All @@ -185,7 +173,7 @@ public HttpFileDownloadBuilder SetFileExistsBehavior(FileExistsBehavior fileExis
}

/// <summary>
/// 设置进度更新(通知)的间隔时间
/// 设置文件传输进度(通知)的间隔时间
/// </summary>
/// <param name="progressInterval">进度更新(通知)的间隔时间</param>
/// <returns>
Expand Down Expand Up @@ -221,6 +209,23 @@ public HttpFileDownloadBuilder SetOnTransferStarted(Action configure)
return this;
}

/// <summary>
/// 设置用于传输进度发生变化时执行的委托
/// </summary>
/// <param name="configure">自定义配置委托</param>
/// <returns>
/// <see cref="HttpFileDownloadBuilder" />
/// </returns>
public HttpFileDownloadBuilder SetOnProgressChanged(Func<FileTransferProgress, Task> configure)
{
// 空检查
ArgumentNullException.ThrowIfNull(configure);

OnProgressChanged = configure;

return this;
}

/// <summary>
/// 设置在文件传输完成时的操作
/// </summary>
Expand Down Expand Up @@ -255,6 +260,23 @@ public HttpFileDownloadBuilder SetOnTransferFailed(Action<Exception> configure)
return this;
}

/// <summary>
/// 设置在文件存在且配置为跳过时的操作
/// </summary>
/// <param name="configure">自定义配置委托</param>
/// <returns>
/// <see cref="HttpFileDownloadBuilder" />
/// </returns>
public HttpFileDownloadBuilder SetOnFileExistAndSkip(Action configure)
{
// 空检查
ArgumentNullException.ThrowIfNull(configure);

OnFileExistAndSkip = configure;

return this;
}

/// <summary>
/// 设置 HTTP 文件传输事件处理程序
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal HttpFileUploadBuilder(HttpMethod httpMethod, Uri? requestUri, string fi
internal Type? FileTransferEventHandlerType { get; private set; }

/// <summary>
/// 设置内容类型
/// 设置内容类型(文件类型)
/// </summary>
/// <param name="contentType">内容类型</param>
/// <returns>
Expand Down Expand Up @@ -209,24 +209,7 @@ public HttpFileUploadBuilder SetMaxFileSizeInBytes(long maxFileSizeInBytes)
}

/// <summary>
/// 设置用于上传进度发生变化时执行的委托
/// </summary>
/// <param name="configure">自定义配置委托</param>
/// <returns>
/// <see cref="HttpFileUploadBuilder" />
/// </returns>
public HttpFileUploadBuilder SetOnProgressChanged(Func<FileTransferProgress, Task> configure)
{
// 空检查
ArgumentNullException.ThrowIfNull(configure);

OnProgressChanged = configure;

return this;
}

/// <summary>
/// 设置进度更新(通知)的间隔时间
/// 设置文件传输进度(通知)的间隔时间
/// </summary>
/// <param name="progressInterval">进度更新(通知)的间隔时间</param>
/// <returns>
Expand Down Expand Up @@ -262,6 +245,23 @@ public HttpFileUploadBuilder SetOnTransferStarted(Action configure)
return this;
}

/// <summary>
/// 设置用于上传进度发生变化时执行的委托
/// </summary>
/// <param name="configure">自定义配置委托</param>
/// <returns>
/// <see cref="HttpFileUploadBuilder" />
/// </returns>
public HttpFileUploadBuilder SetOnProgressChanged(Func<FileTransferProgress, Task> configure)
{
// 空检查
ArgumentNullException.ThrowIfNull(configure);

OnProgressChanged = configure;

return this;
}

/// <summary>
/// 设置在文件传输完成时的操作
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ internal HttpLongPollingBuilder(HttpMethod httpMethod, Uri? requestUri)
/// </summary>
public Func<HttpResponseMessage, Task>? OnError { get; private set; }

/// <summary>
/// 用于响应标头包含 <c>X-End-Of-Stream</c> 时触发的操作
/// </summary>
public Func<HttpResponseMessage, Task>? OnEndOfStream { get; private set; }

/// <summary>
/// 实现 <see cref="IHttpLongPollingEventHandler" /> 的类型
/// </summary>
Expand Down Expand Up @@ -198,6 +203,23 @@ public HttpLongPollingBuilder SetOnError(Func<HttpResponseMessage, Task> configu
return this;
}

/// <summary>
/// 设置在响应标头包含 <c>X-End-Of-Stream</c> 时触发的操作
/// </summary>
/// <param name="configure">自定义配置委托</param>
/// <returns>
/// <see cref="HttpLongPollingBuilder" />
/// </returns>
public HttpLongPollingBuilder SetOnEndOfStream(Func<HttpResponseMessage, Task> configure)
{
// 空检查
ArgumentNullException.ThrowIfNull(configure);

OnEndOfStream = configure;

return this;
}

/// <summary>
/// 设置长轮询事件处理程序
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public HttpMultipartFormDataBuilder Add(HttpContent httpContent, string? name, s
ArgumentException.ThrowIfNullOrWhiteSpace(contentType);

// 构建 HttpContent 实例
var httpContent = httpContentProcessorFactory.BuildHttpContent(multipartFormDataItem.RawContent, contentType,
var httpContent = httpContentProcessorFactory.Build(multipartFormDataItem.RawContent, contentType,
multipartFormDataItem.ContentEncoding, processors);

// 处理 ByteArrayContent、StreamContent 和 ReadOnlyMemoryContent 类型文件的名称
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public HttpRemoteBuilder AddHttpContentConverters(Func<IEnumerable<IHttpContentC
}

/// <summary>
/// 添加自定义 <see cref="ObjectContentConverter{TResult}" /> 工厂
/// 设置 <see cref="IObjectContentConverterFactory" /> 对象内容转换器工厂
/// </summary>
/// <typeparam name="TFactory">
/// <see cref="IObjectContentConverterFactory" />
Expand All @@ -162,7 +162,7 @@ public HttpRemoteBuilder UseObjectContentConverterFactory<TFactory>()
UseObjectContentConverterFactory(typeof(TFactory));

/// <summary>
/// 添加自定义 <see cref="ObjectContentConverter{TResult}" /> 工厂
/// 设置 <see cref="IObjectContentConverterFactory" /> 对象内容转换器工厂
/// </summary>
/// <param name="factoryType">
/// <see cref="IObjectContentConverterFactory" />
Expand Down Expand Up @@ -233,49 +233,49 @@ public HttpRemoteBuilder AddHttpDeclarative(Type declarativeType)
}

/// <summary>
/// 扫描程序集并添加 HTTP 声明式服务
/// 添加 HTTP 声明式服务
/// </summary>
/// <param name="assemblies"><see cref="Assembly" /> 集合</param>
/// <param name="declarativeTypes">
/// <see cref="IHttpDeclarative" /> 集合
/// </param>
/// <returns>
/// <see cref="HttpRemoteBuilder" />
/// </returns>
public HttpRemoteBuilder AddHttpDeclarativeFromAssemblies(params IEnumerable<Assembly?> assemblies)
/// <exception cref="ArgumentException"></exception>
public HttpRemoteBuilder AddHttpDeclaratives(params IEnumerable<Type> declarativeTypes)
{
// 空检查
ArgumentNullException.ThrowIfNull(assemblies);
ArgumentNullException.ThrowIfNull(declarativeTypes);

AddHttpDeclaratives(assemblies.SelectMany(ass =>
(ass?.GetExportedTypes() ?? Enumerable.Empty<Type>()).Where(t =>
t.IsInterface && typeof(IHttpDeclarative).IsAssignableFrom(t))));
foreach (var declarativeType in declarativeTypes)
{
AddHttpDeclarative(declarativeType);
}

return this;
}

/// <summary>
/// 添加 HTTP 声明式服务
/// 扫描程序集并添加 HTTP 声明式服务
/// </summary>
/// <param name="declarativeTypes">
/// <see cref="IHttpDeclarative" /> 集合
/// </param>
/// <param name="assemblies"><see cref="Assembly" /> 集合</param>
/// <returns>
/// <see cref="HttpRemoteBuilder" />
/// </returns>
/// <exception cref="ArgumentException"></exception>
public HttpRemoteBuilder AddHttpDeclaratives(params IEnumerable<Type> declarativeTypes)
public HttpRemoteBuilder AddHttpDeclarativeFromAssemblies(params IEnumerable<Assembly?> assemblies)
{
// 空检查
ArgumentNullException.ThrowIfNull(declarativeTypes);
ArgumentNullException.ThrowIfNull(assemblies);

foreach (var declarativeType in declarativeTypes)
{
AddHttpDeclarative(declarativeType);
}
AddHttpDeclaratives(assemblies.SelectMany(ass =>
(ass?.GetExportedTypes() ?? Enumerable.Empty<Type>()).Where(t =>
t.IsInterface && typeof(IHttpDeclarative).IsAssignableFrom(t))));

return this;
}

/// <summary>
/// 添加 HTTP 声明式 <see cref="IHttpDeclarativeExtractor" /> 集合提取器
/// 添加 HTTP 声明式 <see cref="IHttpDeclarativeExtractor" /> 提取器
/// </summary>
/// <remarks>支持多次调用。</remarks>
/// <param name="configure"><see cref="IHttpDeclarativeExtractor" /> 实例提供器</param>
Expand Down Expand Up @@ -326,6 +326,9 @@ internal void Build(IServiceCollection services)
new HttpContentConverterFactory(provider,
_httpContentConverterProviders?.SelectMany(u => u.Invoke()).ToArray()));

// 注册对象内容转换器工厂
services.TryAddSingleton<IObjectContentConverterFactory, ObjectContentConverterFactory>();

// 注册 HTTP 远程请求服务
services.TryAddSingleton<IHttpRemoteService>(provider =>
ActivatorUtilities.CreateInstance<HttpRemoteService>(provider,
Expand All @@ -336,8 +339,9 @@ internal void Build(IServiceCollection services)
HttpDeclarativeExtractors = _httpDeclarativeExtractors?.AsReadOnly()
}));

// 注册或替换 IObjectContentConverterFactory 工厂
if (_objectContentConverterFactoryType is not null)
// 检查是否自定义了对象内容转换器工厂,如果存在则替换
if (_objectContentConverterFactoryType is not null &&
_objectContentConverterFactoryType != typeof(ObjectContentConverterFactory))
{
services.Replace(ServiceDescriptor.Singleton(typeof(IObjectContentConverterFactory),
_objectContentConverterFactoryType));
Expand Down
Loading

0 comments on commit d75b514

Please sign in to comment.