A powerful asset collection framework for .NET applications.
$ dotnet add package SuCaiFlow.EntityFrameworkSuCaiFlow 是一个素材采集流程库,旨在提供一个灵活、可扩展的素材采集框架,可以轻松集成到任何.NET 应用程序中。
<PackageReference Include="SuCaiFlow" Version="1.0.0" />
或者通过项目引用方式使用。
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SuCaiFlow.Core.Extensions;
using SuCaiFlow.EntityFramework.Extensions;
var builder = Host.CreateApplicationBuilder(args);
// 添加 SuCaiFlow 服务
builder.Services.AddSuCaiFlow();
// 添加 SuCaiFlow 数据库上下文和仓储
builder.Services.AddSuCaiFlowDbContext<SuCaiFlowDbContext>(options =>
options.UseInMemoryDatabase("SuCaiFlowDemo"));
builder.Services.AddSuCaiFlowRepositories();
var host = builder.Build();
// 使用服务
var collectionTaskService = host.Services.GetRequiredService<ICollectionTaskService>();
// 创建采集任务
var taskId = await collectionTaskService.CreateCollectionTaskAsync(
"示例任务",
"这是一个示例采集任务",
"<https://example.com>",
".item",
new Dictionary<string, string> { { "key", "value" } });
// 启动任务
await collectionTaskService.StartCollectionTaskAsync(taskId);
包含所有实体和接口定义:
包含业务逻辑实现:
包含数据访问实现:
public class CustomSiteCollector : BaseSiteCollector
{
public override string SiteIdentifier => "customsite.com";
public override string DisplayName => "自定义站点采集器";
public override async Task<List<string>> ParsePageAsync(CollectionTask task, string pageUrl, CollectionTaskConfig? config = null)
{
// 实现页面解析逻辑
return new List<string>();
}
public override async Task<CollectedAsset?> DownloadAssetAsync(string url, CollectionTaskConfig? config = null)
{
// 实现资源下载逻辑
return new CollectedAsset();
}
}
然后在服务注册中添加:
builder.Services.AddScoped<ISiteCollector, CustomSiteCollector>();
SuCaiFlow 提供以下依赖注入扩展方法:
MIT