From 5c4e6fd82a3ef656bee5fae53bff16a41394d06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E5=A4=A9=E5=A4=A9?= Date: Thu, 8 Jan 2026 11:43:29 +0800 Subject: [PATCH 1/4] init --- Net/NDownload/NDlConnection.cs | 5 +++++ Net/NDownload/NDlFactory.cs | 5 +++++ Net/NDownload/NDlScheduler.cs | 5 +++++ Net/NDownload/NDlSource.cs | 5 +++++ Net/NDownload/NDlSourceManager.cs | 5 +++++ Net/NDownload/NDlTask.cs | 5 +++++ Net/NDownload/NDlTaskSegment.cs | 5 +++++ 7 files changed, 35 insertions(+) create mode 100644 Net/NDownload/NDlConnection.cs create mode 100644 Net/NDownload/NDlFactory.cs create mode 100644 Net/NDownload/NDlScheduler.cs create mode 100644 Net/NDownload/NDlSource.cs create mode 100644 Net/NDownload/NDlSourceManager.cs create mode 100644 Net/NDownload/NDlTask.cs create mode 100644 Net/NDownload/NDlTaskSegment.cs diff --git a/Net/NDownload/NDlConnection.cs b/Net/NDownload/NDlConnection.cs new file mode 100644 index 00000000..6c020a4d --- /dev/null +++ b/Net/NDownload/NDlConnection.cs @@ -0,0 +1,5 @@ +namespace PCL.Core.Net.NDownload; + +public class NDlConnection +{ +} \ No newline at end of file diff --git a/Net/NDownload/NDlFactory.cs b/Net/NDownload/NDlFactory.cs new file mode 100644 index 00000000..c41be5cf --- /dev/null +++ b/Net/NDownload/NDlFactory.cs @@ -0,0 +1,5 @@ +namespace PCL.Core.Net.NDownload; + +public static class NDlFactory +{ +} diff --git a/Net/NDownload/NDlScheduler.cs b/Net/NDownload/NDlScheduler.cs new file mode 100644 index 00000000..03e46b2a --- /dev/null +++ b/Net/NDownload/NDlScheduler.cs @@ -0,0 +1,5 @@ +namespace PCL.Core.Net.NDownload; + +public class NDlScheduler +{ +} \ No newline at end of file diff --git a/Net/NDownload/NDlSource.cs b/Net/NDownload/NDlSource.cs new file mode 100644 index 00000000..9b1e4a47 --- /dev/null +++ b/Net/NDownload/NDlSource.cs @@ -0,0 +1,5 @@ +namespace PCL.Core.Net.NDownload; + +public class NDlSource +{ +} \ No newline at end of file diff --git a/Net/NDownload/NDlSourceManager.cs b/Net/NDownload/NDlSourceManager.cs new file mode 100644 index 00000000..4cc41185 --- /dev/null +++ b/Net/NDownload/NDlSourceManager.cs @@ -0,0 +1,5 @@ +namespace PCL.Core.Net.NDownload; + +public class NDlSourceManager +{ +} \ No newline at end of file diff --git a/Net/NDownload/NDlTask.cs b/Net/NDownload/NDlTask.cs new file mode 100644 index 00000000..20c6a88b --- /dev/null +++ b/Net/NDownload/NDlTask.cs @@ -0,0 +1,5 @@ +namespace PCL.Core.Net.NDownload; + +public class NDlTask +{ +} \ No newline at end of file diff --git a/Net/NDownload/NDlTaskSegment.cs b/Net/NDownload/NDlTaskSegment.cs new file mode 100644 index 00000000..9b02bc29 --- /dev/null +++ b/Net/NDownload/NDlTaskSegment.cs @@ -0,0 +1,5 @@ +namespace PCL.Core.Net.NDownload; + +public class NDlTaskSegment +{ +} \ No newline at end of file From ae1ae3d4ac8b510aaa446602b8877980ac452e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E5=A4=A9=E5=A4=A9?= Date: Thu, 8 Jan 2026 19:49:48 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A5=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Net/NDownload/IDlConnection.cs | 29 ++++++++++++++ Net/NDownload/IDlResourceMapping.cs | 10 +++++ Net/NDownload/IDlWriter.cs | 31 +++++++++++++++ Net/NDownload/NDlConnection.cs | 5 --- Net/NDownload/NDlConnectionInfo.cs | 15 +++++++ Net/NDownload/NDlFactory.cs | 61 ++++++++++++++++++++++++++++- Net/NDownload/NDlScheduler.cs | 2 +- Net/NDownload/NDlSource.cs | 5 --- Net/NDownload/NDlSourceManager.cs | 4 +- Net/NDownload/NDlTask.cs | 2 +- Net/NDownload/NDlTaskSegment.cs | 2 +- 11 files changed, 150 insertions(+), 16 deletions(-) create mode 100644 Net/NDownload/IDlConnection.cs create mode 100644 Net/NDownload/IDlResourceMapping.cs create mode 100644 Net/NDownload/IDlWriter.cs delete mode 100644 Net/NDownload/NDlConnection.cs create mode 100644 Net/NDownload/NDlConnectionInfo.cs delete mode 100644 Net/NDownload/NDlSource.cs diff --git a/Net/NDownload/IDlConnection.cs b/Net/NDownload/IDlConnection.cs new file mode 100644 index 00000000..533b9919 --- /dev/null +++ b/Net/NDownload/IDlConnection.cs @@ -0,0 +1,29 @@ +using System.Threading.Tasks; + +namespace PCL.Core.Net.NDownload; + +/// +/// 下载连接,负责与服务器进行通信。 +/// +public interface IDlConnection +{ + /// + /// 开始连接,发起与服务器的通信。 + /// + /// 起始偏移,为 0 表示不使用分块 + /// 连接信息 + public Task StartAsync(long beginOffset); + + /// + /// 停止连接,同时停止服务器通信并释放资源。 + /// + /// + public Task StopAsync(); + + /// + /// 读取指定长度的数据,若无法继续读取则返回空数组。 + /// + /// 读取长度 + /// 字节数组形式的数据 + public Task ReadAsync(int length); +} diff --git a/Net/NDownload/IDlResourceMapping.cs b/Net/NDownload/IDlResourceMapping.cs new file mode 100644 index 00000000..db7f9db8 --- /dev/null +++ b/Net/NDownload/IDlResourceMapping.cs @@ -0,0 +1,10 @@ +namespace PCL.Core.Net.NDownload; + +/// +/// 资源 ID 映射。 +/// +/// 映射目标类型 +public interface IDlResourceMapping +{ + public TMappingValue? Parse(string resId); +} diff --git a/Net/NDownload/IDlWriter.cs b/Net/NDownload/IDlWriter.cs new file mode 100644 index 00000000..80c66b38 --- /dev/null +++ b/Net/NDownload/IDlWriter.cs @@ -0,0 +1,31 @@ +using System.IO; +using System.Threading.Tasks; + +namespace PCL.Core.Net.NDownload; + +/// +/// 下载写入器。 +/// +public interface IDlWriter +{ + /// + /// 是否支持并行写入,即是否支持多次调用 。 + /// + public bool IsSupportParallel { get; } + + /// + /// 创建写入流。 + /// + /// 写入流 + public Task CreateStreamAsync(); + + /// + /// 停止写入并释放资源。 + /// + public Task StopAsync(); + + /// + /// 完成写入,用于执行某些并行操作的收尾工作 (例如合并文件)。 + /// + public Task FinishAsync(); +} diff --git a/Net/NDownload/NDlConnection.cs b/Net/NDownload/NDlConnection.cs deleted file mode 100644 index 6c020a4d..00000000 --- a/Net/NDownload/NDlConnection.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace PCL.Core.Net.NDownload; - -public class NDlConnection -{ -} \ No newline at end of file diff --git a/Net/NDownload/NDlConnectionInfo.cs b/Net/NDownload/NDlConnectionInfo.cs new file mode 100644 index 00000000..5d9ab2fe --- /dev/null +++ b/Net/NDownload/NDlConnectionInfo.cs @@ -0,0 +1,15 @@ +namespace PCL.Core.Net.NDownload; + +/// +/// 下载连接信息。 +/// +/// 内容长度,单位为字节 +/// 起始偏移 +/// 结束偏移 +/// 是否支持分块 +public record NDlConnectionInfo( + long Length, + long BeginOffset, + long EndOffset, + bool IsSupportSegment +); diff --git a/Net/NDownload/NDlFactory.cs b/Net/NDownload/NDlFactory.cs index c41be5cf..55a01c76 100644 --- a/Net/NDownload/NDlFactory.cs +++ b/Net/NDownload/NDlFactory.cs @@ -1,5 +1,64 @@ namespace PCL.Core.Net.NDownload; -public static class NDlFactory +/// +/// 无泛型的下载器构建工厂。 +/// +public abstract class NDlFactory { + /// + /// 新建连接。 + /// + /// 资源 ID + /// 重试计数,用于自动换源 + /// 下载连接 + public abstract IDlConnection CreateConnection(string resId, int retry = 0); + + /// + /// 新建写入器。 + /// + /// 资源 ID + /// 下载写入器 + public abstract IDlWriter CreateWriter(string resId); +} + +/// +/// 下载器构建工厂。 +/// +/// 下载源参数类型 +/// 写入目标参数类型 +public abstract class NDlFactory : NDlFactory +{ + /// + /// 下载源管理器。 + /// + protected abstract NDlSourceManager SourceManager { get; } + + /// + /// 写入目标。 + /// + protected abstract IDlResourceMapping TargetMapping { get; } + + /// + /// 新建连接。 + /// + /// 下载源参数 + /// 下载连接 + protected abstract IDlConnection CreateConnection(TSourceArgument source); + + public override IDlConnection CreateConnection(string resId, int retry = 0) + { + throw new System.NotImplementedException(); + } + + /// + /// 新建写入器。 + /// + /// 写入目标 + /// 下载写入器 + protected abstract IDlWriter CreateWriter(TTargetArgument target); + + public override IDlWriter CreateWriter(string resId) + { + throw new System.NotImplementedException(); + } } diff --git a/Net/NDownload/NDlScheduler.cs b/Net/NDownload/NDlScheduler.cs index 03e46b2a..99d4f16d 100644 --- a/Net/NDownload/NDlScheduler.cs +++ b/Net/NDownload/NDlScheduler.cs @@ -2,4 +2,4 @@ namespace PCL.Core.Net.NDownload; public class NDlScheduler { -} \ No newline at end of file +} diff --git a/Net/NDownload/NDlSource.cs b/Net/NDownload/NDlSource.cs deleted file mode 100644 index 9b1e4a47..00000000 --- a/Net/NDownload/NDlSource.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace PCL.Core.Net.NDownload; - -public class NDlSource -{ -} \ No newline at end of file diff --git a/Net/NDownload/NDlSourceManager.cs b/Net/NDownload/NDlSourceManager.cs index 4cc41185..a8eaa8c2 100644 --- a/Net/NDownload/NDlSourceManager.cs +++ b/Net/NDownload/NDlSourceManager.cs @@ -1,5 +1,5 @@ namespace PCL.Core.Net.NDownload; -public class NDlSourceManager +public class NDlSourceManager { -} \ No newline at end of file +} diff --git a/Net/NDownload/NDlTask.cs b/Net/NDownload/NDlTask.cs index 20c6a88b..134f7b64 100644 --- a/Net/NDownload/NDlTask.cs +++ b/Net/NDownload/NDlTask.cs @@ -2,4 +2,4 @@ namespace PCL.Core.Net.NDownload; public class NDlTask { -} \ No newline at end of file +} diff --git a/Net/NDownload/NDlTaskSegment.cs b/Net/NDownload/NDlTaskSegment.cs index 9b02bc29..f855e0c7 100644 --- a/Net/NDownload/NDlTaskSegment.cs +++ b/Net/NDownload/NDlTaskSegment.cs @@ -2,4 +2,4 @@ namespace PCL.Core.Net.NDownload; public class NDlTaskSegment { -} \ No newline at end of file +} From 5316dcd397587d8d53e9f8260dbeb1a83d3c2895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E5=A4=A9=E5=A4=A9?= Date: Mon, 12 Jan 2026 18:00:32 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=86=8D=E6=8C=A4=E4=B8=80=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Net/NDownload/NDlFactory.cs | 21 +++++++++++---------- Net/NDownload/NDlSourceManager.cs | 11 ++++++++++- Net/NDownload/NDlSourceReport.cs | 7 +++++++ 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 Net/NDownload/NDlSourceReport.cs diff --git a/Net/NDownload/NDlFactory.cs b/Net/NDownload/NDlFactory.cs index 55a01c76..df099b6c 100644 --- a/Net/NDownload/NDlFactory.cs +++ b/Net/NDownload/NDlFactory.cs @@ -9,16 +9,15 @@ public abstract class NDlFactory /// 新建连接。 /// /// 资源 ID - /// 重试计数,用于自动换源 /// 下载连接 - public abstract IDlConnection CreateConnection(string resId, int retry = 0); + public abstract IDlConnection? CreateConnection(string resId); /// /// 新建写入器。 /// /// 资源 ID /// 下载写入器 - public abstract IDlWriter CreateWriter(string resId); + public abstract IDlWriter? CreateWriter(string resId); } /// @@ -29,12 +28,12 @@ public abstract class NDlFactory public abstract class NDlFactory : NDlFactory { /// - /// 下载源管理器。 + /// 下载源映射。 /// - protected abstract NDlSourceManager SourceManager { get; } + protected abstract IDlResourceMapping SourceMapping { get; } /// - /// 写入目标。 + /// 写入目标映射。 /// protected abstract IDlResourceMapping TargetMapping { get; } @@ -45,9 +44,10 @@ public abstract class NDlFactory : NDlFactory /// 下载连接 protected abstract IDlConnection CreateConnection(TSourceArgument source); - public override IDlConnection CreateConnection(string resId, int retry = 0) + public override IDlConnection? CreateConnection(string resId) { - throw new System.NotImplementedException(); + var source = SourceMapping.Parse(resId); + return (source == null) ? null : CreateConnection(source); } /// @@ -57,8 +57,9 @@ public override IDlConnection CreateConnection(string resId, int retry = 0) /// 下载写入器 protected abstract IDlWriter CreateWriter(TTargetArgument target); - public override IDlWriter CreateWriter(string resId) + public override IDlWriter? CreateWriter(string resId) { - throw new System.NotImplementedException(); + var target = TargetMapping.Parse(resId); + return (target == null) ? null : CreateWriter(target); } } diff --git a/Net/NDownload/NDlSourceManager.cs b/Net/NDownload/NDlSourceManager.cs index a8eaa8c2..08240d81 100644 --- a/Net/NDownload/NDlSourceManager.cs +++ b/Net/NDownload/NDlSourceManager.cs @@ -1,5 +1,14 @@ +using System.Collections.Generic; + namespace PCL.Core.Net.NDownload; -public class NDlSourceManager +public class NDlSourceManager(IList> sources) + : IDlResourceMapping { + public IList> Sources { get; } = sources; + + public TSourceArgument? Parse(string resId) + { + throw new System.NotImplementedException(); + } } diff --git a/Net/NDownload/NDlSourceReport.cs b/Net/NDownload/NDlSourceReport.cs new file mode 100644 index 00000000..656e78fb --- /dev/null +++ b/Net/NDownload/NDlSourceReport.cs @@ -0,0 +1,7 @@ +namespace PCL.Core.Net.NDownload; + +public record NDlSourceReport( + bool IsSupportSegment = true, + int RetryCount = 0, + long AverageSpeed = -1 +); From 199d23005955044f0e5440b23d7ddcaa2823bf55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E5=A4=A9=E5=A4=A9?= Date: Sun, 18 Jan 2026 10:11:57 +0800 Subject: [PATCH 4/4] =?UTF-8?q?imp:=20=E5=BE=AE=E8=B0=83=20source=20report?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Net/NDownload/NDlSourceReport.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Net/NDownload/NDlSourceReport.cs b/Net/NDownload/NDlSourceReport.cs index 656e78fb..f19cbb82 100644 --- a/Net/NDownload/NDlSourceReport.cs +++ b/Net/NDownload/NDlSourceReport.cs @@ -1,7 +1,13 @@ namespace PCL.Core.Net.NDownload; +/// +/// 下载源质量报告 +/// +/// 支持最大分块数量 +/// 重试计数 +/// 总体平均速度 public record NDlSourceReport( - bool IsSupportSegment = true, + int MaxSegmentCount = 1, int RetryCount = 0, long AverageSpeed = -1 );