整理代码
This commit is contained in:
@@ -130,8 +130,8 @@ public class CsvSource:IDataSource
|
||||
public virtual async Task GetHeaderAndCsvFiles()
|
||||
{
|
||||
var text = await File.ReadAllTextAsync(_sqlFilePath);
|
||||
headers = await DumpDataHelper.GetCsvHeadersFromSqlFileAsync(text);
|
||||
csvFiles = await DumpDataHelper.GetCsvFileNamesFromSqlFileAsync(text, new Regex(@"'.+\.dat.zst'"));
|
||||
headers = DumpDataHelper.GetCsvHeadersFromSqlFileAsync(text);
|
||||
csvFiles = DumpDataHelper.GetCsvFileNamesFromSqlFileAsync(text, new Regex(@"'.+\.dat.zst'"));
|
||||
|
||||
}
|
||||
public virtual async Task DoEnqueue(Action<DataRecord> action)
|
||||
@@ -140,9 +140,9 @@ public class CsvSource:IDataSource
|
||||
foreach (var file in csvFiles)
|
||||
{
|
||||
var filePath= Path.Combine(_inputDir, file);
|
||||
using (var fs = File.OpenRead(filePath))
|
||||
using var fs = File.OpenRead(filePath);
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(fs))
|
||||
using StreamReader sr = new (fs);
|
||||
{
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
@@ -164,9 +164,9 @@ public class CsvSource:IDataSource
|
||||
if (file != null)
|
||||
{
|
||||
var filePath = Path.Combine(_inputDir, file);
|
||||
using (var fs = File.OpenRead(filePath))
|
||||
using var fs = File.OpenRead(filePath);
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(fs))
|
||||
using StreamReader sr = new(fs);
|
||||
{
|
||||
var line = await sr.ReadLineAsync();
|
||||
var fields = ParseRow2(line, QuoteChar, Delimiter);
|
||||
|
@@ -27,14 +27,11 @@ public class JsvSource:IDataSource
|
||||
_inputDir = inputDir;
|
||||
_tableName = tableName;
|
||||
_jsv = new JsvStringSerializer();
|
||||
// _reader = new StreamReader(filePath);
|
||||
//Headers = headers;
|
||||
_logger = logger;
|
||||
// _logger?.LogInformation("Reading file: {FilePath}", filePath);
|
||||
//_tableName = DumpDataHelper.GetTableName(filePath);
|
||||
}
|
||||
public async Task DoEnqueue(Action<DataRecord> action)
|
||||
public Task DoEnqueue(Action<DataRecord> action)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@@ -109,10 +109,6 @@ public partial class MySqlDestination : IDisposable, IAsyncDisposable
|
||||
var sb = new StringBuilder();
|
||||
foreach (var (tableName, records) in tableRecords)
|
||||
{
|
||||
if (tableName == "order_process_step")
|
||||
{
|
||||
var a = 1;
|
||||
}
|
||||
if (records.Count == 0)
|
||||
continue;
|
||||
|
||||
|
@@ -10,7 +10,6 @@ public class ProcessContext
|
||||
private int _inputCount;
|
||||
private int _transformCount;
|
||||
private int _outputCount;
|
||||
private int _finishedTaskCount;
|
||||
private ConcurrentBag<Exception> _exceptionList = new ConcurrentBag<Exception>();
|
||||
public bool IsInputCompleted { get; private set; }
|
||||
public bool IsTransformCompleted { get; private set; }
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using ConsoleApp2.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using ZstdSharp;
|
||||
namespace ConsoleApp2.Services
|
||||
@@ -10,22 +9,21 @@ namespace ConsoleApp2.Services
|
||||
public ZstSource(string inputDir, string tableName, string delimiter = ",", char quoteChar = '"',
|
||||
ILogger? logger = null) : base(inputDir, tableName, delimiter = ",", quoteChar = '"', logger = null)
|
||||
{
|
||||
//throw new Exception("aaa");
|
||||
string pattern = $"^.*\\.{tableName}\\..*\\.sql.zst$";
|
||||
_sqlFilePath = Directory.GetFiles(_inputDir).FirstOrDefault(s => Regex.Match(s, pattern).Success);
|
||||
|
||||
}
|
||||
private async Task<string> DecompressFile(string filePath)
|
||||
private static async Task<string> DecompressFile(string filePath)
|
||||
{
|
||||
using (var input = File.OpenRead(filePath))
|
||||
using var input = File.OpenRead(filePath);
|
||||
{
|
||||
using (var decopress = new DecompressionStream(input))
|
||||
using var decopress = new DecompressionStream(input);
|
||||
{
|
||||
|
||||
var ms = new MemoryStream();
|
||||
decopress.CopyTo(ms);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
StreamReader reader = new StreamReader(ms);
|
||||
StreamReader reader = new(ms);
|
||||
var text = await reader.ReadToEndAsync();
|
||||
return text;
|
||||
|
||||
@@ -35,8 +33,8 @@ namespace ConsoleApp2.Services
|
||||
public override async Task GetHeaderAndCsvFiles()
|
||||
{
|
||||
var text = await DecompressFile(_sqlFilePath);
|
||||
headers=await DumpDataHelper.GetCsvHeadersFromSqlFileAsync(text);
|
||||
csvFiles=await DumpDataHelper.GetCsvFileNamesFromSqlFileAsync(text, new Regex(@"'.+\.dat.zst'"));
|
||||
headers= DumpDataHelper.GetCsvHeadersFromSqlFileAsync(text);
|
||||
csvFiles= DumpDataHelper.GetCsvFileNamesFromSqlFileAsync(text, new Regex(@"'.+\.dat.zst'"));
|
||||
|
||||
}
|
||||
public override async Task DoEnqueue(Action<DataRecord> action)
|
||||
@@ -45,11 +43,11 @@ namespace ConsoleApp2.Services
|
||||
foreach (var file in csvFiles)
|
||||
{
|
||||
var filePath = Path.Combine(_inputDir, file);
|
||||
using (var input = File.OpenRead(filePath))
|
||||
using var input = File.OpenRead(filePath);
|
||||
{
|
||||
using (var decopress = new DecompressionStream(input))
|
||||
using var decopress = new DecompressionStream(input);
|
||||
{
|
||||
using( var reader = new StreamReader(decopress))
|
||||
using var reader = new StreamReader(decopress);
|
||||
{
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
@@ -88,9 +86,5 @@ namespace ConsoleApp2.Services
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
//_reader.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user