diff --git a/Libs/YY.EventLogExportAssistant.ClickHouse/ClickHouseContext.cs b/Libs/YY.EventLogExportAssistant.ClickHouse/ClickHouseContext.cs index 8547e0c..6b855e6 100644 --- a/Libs/YY.EventLogExportAssistant.ClickHouse/ClickHouseContext.cs +++ b/Libs/YY.EventLogExportAssistant.ClickHouse/ClickHouseContext.cs @@ -28,7 +28,7 @@ namespace YY.EventLogExportAssistant.ClickHouse private ClickHouseConnection _connection; private long logFileLastId = -1; - private IExtendedActions _extendedActions; + private readonly IExtendedActions _extendedActions; #endregion @@ -234,86 +234,32 @@ namespace YY.EventLogExportAssistant.ClickHouse } public void SaveLogPosition(InformationSystemsBase system, FileInfo logFileInfo, EventLogPosition position) { - var commandAddLogInfo = _connection.CreateCommand(); - commandAddLogInfo.CommandText = - @"INSERT INTO LogFiles ( - InformationSystem, - Id, - FileName, - CreateDate, - ModificationDate, - LastEventNumber, - LastCurrentFileReferences, - LastCurrentFileData, - LastStreamPosition - ) VALUES ( - {isId:String}, - {newId:Int64}, - {FileName:String}, - {CreateDate:DateTime}, - {ModificationDate:DateTime}, - {LastEventNumber:Int64}, - {LastCurrentFileReferences:String}, - {LastCurrentFileData:String}, - {LastStreamPosition:Int64} - )"; + using (ClickHouseBulkCopy bulkCopyInterface = new ClickHouseBulkCopy(_connection) + { + DestinationTableName = "LogFiles", + BatchSize = 100000 + }) + { + long logFileNewId = GetLogFileInfoNewId(system); + IEnumerable values = new List() + { + new object[] + { + system.Name, + logFileNewId, + logFileInfo.Name, + logFileInfo.CreationTimeUtc, + logFileInfo.LastWriteTimeUtc, + position.EventNumber, + position.CurrentFileReferences.Replace("\\", "\\\\"), + position.CurrentFileData.Replace("\\", "\\\\"), + position.StreamPosition ?? 0 + } + }.AsEnumerable(); - commandAddLogInfo.Parameters.Add(new ClickHouseDbParameter - { - ParameterName = "isId", - DbType = DbType.Int64, - Value = system.Name - }); - commandAddLogInfo.Parameters.Add(new ClickHouseDbParameter - { - ParameterName = "newId", - DbType = DbType.Int64, - Value = GetLogFileInfoNewId(system) - }); - commandAddLogInfo.Parameters.Add(new ClickHouseDbParameter - { - ParameterName = "FileName", - DbType = DbType.AnsiString, - Value = logFileInfo.Name - }); - commandAddLogInfo.Parameters.Add(new ClickHouseDbParameter - { - ParameterName = "CreateDate", - DbType = DbType.DateTime, - Value = logFileInfo.CreationTimeUtc - }); - commandAddLogInfo.Parameters.Add(new ClickHouseDbParameter - { - ParameterName = "ModificationDate", - DbType = DbType.DateTime, - Value = logFileInfo.LastWriteTimeUtc - }); - commandAddLogInfo.Parameters.Add(new ClickHouseDbParameter - { - ParameterName = "LastEventNumber", - DbType = DbType.Int64, - Value = position.EventNumber - }); - commandAddLogInfo.Parameters.Add(new ClickHouseDbParameter - { - ParameterName = "LastCurrentFileReferences", - DbType = DbType.AnsiString, - Value = position.CurrentFileReferences.Replace("\\", "\\\\") - }); - commandAddLogInfo.Parameters.Add(new ClickHouseDbParameter - { - ParameterName = "LastCurrentFileData", - DbType = DbType.AnsiString, - Value = position.CurrentFileData.Replace("\\", "\\\\") - }); - commandAddLogInfo.Parameters.Add(new ClickHouseDbParameter - { - ParameterName = "LastStreamPosition", - DbType = DbType.Int64, - Value = position.StreamPosition ?? 0 - }); - - commandAddLogInfo.ExecuteNonQuery(); + var bulkResult = bulkCopyInterface.WriteToServerAsync(values); + bulkResult.Wait(); + } } public long GetLogFileInfoNewId(InformationSystemsBase system) { diff --git a/Libs/YY.EventLogExportAssistant.ClickHouse/YY.EventLogExportAssistant.ClickHouse.csproj b/Libs/YY.EventLogExportAssistant.ClickHouse/YY.EventLogExportAssistant.ClickHouse.csproj index 0f18ab5..e1ceeed 100644 --- a/Libs/YY.EventLogExportAssistant.ClickHouse/YY.EventLogExportAssistant.ClickHouse.csproj +++ b/Libs/YY.EventLogExportAssistant.ClickHouse/YY.EventLogExportAssistant.ClickHouse.csproj @@ -3,7 +3,7 @@ netstandard2.1 true - 1.0.0.17 + 1.0.0.18 Permitin Yuriy Permitin Yuriy Event log export assistant to ClickHouse @@ -15,7 +15,7 @@ GIT event, log, 1C, enterprise, export, elasticsearch, elk Just beginning... - 1.0.0.17 + 1.0.0.18 diff --git a/Libs/YY.EventLogExportAssistant.PostgreSQL/YY.EventLogExportAssistant.PostgreSQL.csproj b/Libs/YY.EventLogExportAssistant.PostgreSQL/YY.EventLogExportAssistant.PostgreSQL.csproj index 2cfd4b7..0afa930 100644 --- a/Libs/YY.EventLogExportAssistant.PostgreSQL/YY.EventLogExportAssistant.PostgreSQL.csproj +++ b/Libs/YY.EventLogExportAssistant.PostgreSQL/YY.EventLogExportAssistant.PostgreSQL.csproj @@ -2,7 +2,7 @@ netstandard2.1 - 1.0.0.47 + 1.0.0.48 YY.EventLogExportAssistant.PostgreSQL Permitin Yuriy Event log export assistant for PostgreSQL @@ -14,9 +14,9 @@ GIT event, log, 1C, enterprise, export, postgres, postgresql true - 1.0.0.47 + 1.0.0.48 Just beginning... - 1.0.0.47 + 1.0.0.48 @@ -32,7 +32,7 @@ - + diff --git a/Tests/YY.EventLogExportAssistant.ClickHouse.Tests/YY.EventLogExportAssistant.ClickHouse.Tests.csproj b/Tests/YY.EventLogExportAssistant.ClickHouse.Tests/YY.EventLogExportAssistant.ClickHouse.Tests.csproj index b029511..2340fe6 100644 --- a/Tests/YY.EventLogExportAssistant.ClickHouse.Tests/YY.EventLogExportAssistant.ClickHouse.Tests.csproj +++ b/Tests/YY.EventLogExportAssistant.ClickHouse.Tests/YY.EventLogExportAssistant.ClickHouse.Tests.csproj @@ -14,7 +14,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Tests/YY.EventLogExportAssistant.Core.Tests/YY.EventLogExportAssistant.Core.Tests.csproj b/Tests/YY.EventLogExportAssistant.Core.Tests/YY.EventLogExportAssistant.Core.Tests.csproj index 8dff231..19138a6 100644 --- a/Tests/YY.EventLogExportAssistant.Core.Tests/YY.EventLogExportAssistant.Core.Tests.csproj +++ b/Tests/YY.EventLogExportAssistant.Core.Tests/YY.EventLogExportAssistant.Core.Tests.csproj @@ -20,7 +20,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Tests/YY.EventLogExportAssistant.ElasticSearch.Tests/YY.EventLogExportAssistant.ElasticSearch.Tests.csproj b/Tests/YY.EventLogExportAssistant.ElasticSearch.Tests/YY.EventLogExportAssistant.ElasticSearch.Tests.csproj index 1a9a853..b4860eb 100644 --- a/Tests/YY.EventLogExportAssistant.ElasticSearch.Tests/YY.EventLogExportAssistant.ElasticSearch.Tests.csproj +++ b/Tests/YY.EventLogExportAssistant.ElasticSearch.Tests/YY.EventLogExportAssistant.ElasticSearch.Tests.csproj @@ -17,7 +17,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Tests/YY.EventLogExportAssistant.MySQL.Tests/YY.EventLogExportAssistant.MySQL.Tests.csproj b/Tests/YY.EventLogExportAssistant.MySQL.Tests/YY.EventLogExportAssistant.MySQL.Tests.csproj index 75ab742..dcb7a0a 100644 --- a/Tests/YY.EventLogExportAssistant.MySQL.Tests/YY.EventLogExportAssistant.MySQL.Tests.csproj +++ b/Tests/YY.EventLogExportAssistant.MySQL.Tests/YY.EventLogExportAssistant.MySQL.Tests.csproj @@ -14,7 +14,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Tests/YY.EventLogExportAssistant.PostgreSQL.Tests/YY.EventLogExportAssistant.PostgreSQL.Tests.csproj b/Tests/YY.EventLogExportAssistant.PostgreSQL.Tests/YY.EventLogExportAssistant.PostgreSQL.Tests.csproj index 3cae971..49473fe 100644 --- a/Tests/YY.EventLogExportAssistant.PostgreSQL.Tests/YY.EventLogExportAssistant.PostgreSQL.Tests.csproj +++ b/Tests/YY.EventLogExportAssistant.PostgreSQL.Tests/YY.EventLogExportAssistant.PostgreSQL.Tests.csproj @@ -15,7 +15,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Tests/YY.EventLogExportAssistant.SQLServer.Tests/YY.EventLogExportAssistant.SQLServer.Tests.csproj b/Tests/YY.EventLogExportAssistant.SQLServer.Tests/YY.EventLogExportAssistant.SQLServer.Tests.csproj index d99d0ea..6f4f205 100644 --- a/Tests/YY.EventLogExportAssistant.SQLServer.Tests/YY.EventLogExportAssistant.SQLServer.Tests.csproj +++ b/Tests/YY.EventLogExportAssistant.SQLServer.Tests/YY.EventLogExportAssistant.SQLServer.Tests.csproj @@ -18,7 +18,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive