98 lines
3.9 KiB
C#
98 lines
3.9 KiB
C#
using ConsoleApp2.Const;
|
|
using ConsoleApp2.HostedServices;
|
|
using ConsoleApp2.HostedServices.Abstractions;
|
|
using ConsoleApp2.Options;
|
|
using ConsoleApp2.Services;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using MySqlConnector;
|
|
using Serilog;
|
|
|
|
// 运行之前把Mysql max_allowed_packets 调大
|
|
// 运行之前把process_step表的外键删掉
|
|
|
|
await RunProgram();
|
|
return;
|
|
|
|
async Task RunProgram()
|
|
{
|
|
ThreadPool.SetMaxThreads(200, 200);
|
|
var host = Host.CreateApplicationBuilder();
|
|
host.Configuration.AddCommandLine(args);
|
|
host.Services.Configure<CsvOptions>(option =>
|
|
{
|
|
option.Delimiter = ",";
|
|
option.QuoteChar = '"';
|
|
option.InputDir = "D:/Dump";
|
|
});
|
|
host.Services.Configure<DataTransformOptions>(options =>
|
|
{
|
|
options.DatabaseFilter = record => "cferp_test_1";
|
|
options.ColumnTypeConfig = new()
|
|
{
|
|
{ "simple_plan_order.PlaceData", ColumnType.Blob },
|
|
{ "order_block_plan_result.PlaceData", ColumnType.Blob },
|
|
{ "order_box_block.Data", ColumnType.Blob },
|
|
{ "order_data_goods.ExtraProp", ColumnType.Text },
|
|
{ "order_module_extra.JsonStr", ColumnType.Text },
|
|
{ "process_info.Users", ColumnType.Text },
|
|
{ "order_process_schdule.CustomOrderNo", ColumnType.Text },
|
|
{ "order_process_schdule.OrderProcessStepName", ColumnType.Text },
|
|
{ "order_process_schdule.AreaName", ColumnType.Text },
|
|
{ "order_process_schdule.ConsigneeAddress", ColumnType.Text },
|
|
{ "order_process_schdule.ConsigneePhone", ColumnType.Text },
|
|
{ "report_source.Sql", ColumnType.Text },
|
|
{ "report_source.KeyValue", ColumnType.Text },
|
|
{ "report_source.Setting", ColumnType.Text },
|
|
{ "order_data_block.RemarkJson", ColumnType.Text },
|
|
{ "order_patch_detail.BlockDetail", ColumnType.Text },
|
|
{ "order_scrap_board.OutLineJson", ColumnType.Text },
|
|
{ "simple_package.Items", ColumnType.Text },
|
|
{ "order_batch_pack_config.Setting", ColumnType.Text },
|
|
{ "machine.Settings", ColumnType.Text },
|
|
{ "sys_config.Value", ColumnType.Text },
|
|
{ "sys_config.JsonStr", ColumnType.Text },
|
|
{ "process_item_exp.ItemJson", ColumnType.Text },
|
|
{ "report_template.Template", ColumnType.Text },
|
|
{ "report_template.SourceConfig", ColumnType.Text },
|
|
{ "order_block_plan.OrderNos", ColumnType.Text },
|
|
{ "order_block_plan.BlockInfo", ColumnType.Text },
|
|
};
|
|
});
|
|
|
|
host.Services.Configure<DatabaseOutputOptions>(options =>
|
|
{
|
|
options.ConnectionString = new MySqlConnectionStringBuilder
|
|
{
|
|
Server = "127.0.0.1",
|
|
Port = 33306,
|
|
Database = "cferp_test_1",
|
|
UserID = "root",
|
|
Password = "123456",
|
|
MaximumPoolSize = 50, // 这个值应当小于 max_connections
|
|
}.ConnectionString;
|
|
options.MaxTask = 16;
|
|
options.FlushCount = 200;
|
|
});
|
|
host.Services.AddLogging(builder =>
|
|
{
|
|
builder.ClearProviders();
|
|
builder.AddSerilog(new LoggerConfiguration().WriteTo.Console().CreateLogger());
|
|
});
|
|
|
|
host.Services.AddSingleton<ProcessContext>();
|
|
host.Services.AddKeyedSingleton<DataRecordQueue>(ProcessStep.Producer);
|
|
host.Services.AddKeyedSingleton<DataRecordQueue>(ProcessStep.Consumer);
|
|
host.Services.AddTransient<TaskManager>();
|
|
|
|
host.Services.AddHostedService<MainHostedService>();
|
|
host.Services.AddHostedService<TaskMonitorService>();
|
|
host.Services.AddSingleton<IInputService, InputService>();
|
|
host.Services.AddSingleton<ITransformService, TransformService>();
|
|
host.Services.AddSingleton<IOutputService, OutputService>();
|
|
|
|
var app = host.Build();
|
|
await app.RunAsync();
|
|
} |