diff --git a/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj index 0db4f00..eee7930 100644 --- a/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj @@ -1,6 +1,6 @@  - 10.0.10 + 10.0.11 1.0.0.0 Order Provider Order Provider diff --git a/src/OrderDestinationWriter.cs b/src/OrderDestinationWriter.cs index ce12cac..6ffc97c 100644 --- a/src/OrderDestinationWriter.cs +++ b/src/OrderDestinationWriter.cs @@ -20,6 +20,7 @@ internal class OrderDestinationWriter : BaseSqlWriter private bool SkipFailingRows { get; } internal SqlCommand SqlCommand { get; } internal int RowsToWriteCount { get; set; } + private int LastLogRowsCount { get; set; } public OrderDestinationWriter(Mapping mapping, SqlConnection connection, ILogger logger, bool skipFailingRows) { @@ -45,11 +46,6 @@ public OrderDestinationWriter(Mapping mapping, SqlConnection connection, ILogger { destColumns.Add((SqlColumn)columnMapping.DestinationColumn); } - if (Mapping.DestinationTable != null && Mapping.DestinationTable.Name == "EcomAssortmentPermissions") - { - if (columnMappings.Find(m => string.Compare(m.DestinationColumn.Name, "AssortmentPermissionAccessUserID", true) == 0) == null) - destColumns.Add(new SqlColumn("AssortmentPermissionAccessUserID", typeof(string), SqlDbType.Int, null, -1, false, true, false)); - } SQLTable.CreateTempTable(SqlCommand, Mapping.DestinationTable.SqlSchema, Mapping.DestinationTable.Name, TempTablePrefix, destColumns, Logger); TableToWrite = DataToWrite.Tables.Add(Mapping.DestinationTable.Name + TempTablePrefix); @@ -71,4 +67,48 @@ internal void FinishWriting() internal void MoveDataToMainTable(SqlTransaction sqlTransaction, bool updateOnlyExistingRecords, bool insertOnlyNewRecords) => MoveDataToMainTable(Mapping, SqlCommand, sqlTransaction, TempTablePrefix, updateOnlyExistingRecords, insertOnlyNewRecords); + + + public new void Write(Dictionary row) + { + DataRow dataRow = TableToWrite.NewRow(); + var columnMappings = Mapping.GetColumnMappings(); + + var activeColumnMappings = columnMappings.Where(cm => cm.Active); + foreach (ColumnMapping columnMapping in activeColumnMappings) + { + object rowValue = null; + if (columnMapping.HasScriptWithValue || row.TryGetValue(columnMapping.SourceColumn?.Name, out rowValue)) + { + object dataToRow = columnMapping.ConvertInputValueToOutputValue(rowValue); + + if (columnMappings.Any(obj => obj.DestinationColumn.Name == columnMapping.DestinationColumn.Name && obj.GetId() != columnMapping.GetId())) + { + dataRow[columnMapping.DestinationColumn.Name] += dataToRow.ToString(); + } + else + { + dataRow[columnMapping.DestinationColumn.Name] = dataToRow; + } + } + else + { + Logger.Info(BaseDestinationWriter.GetRowValueNotFoundMessage(row, columnMapping.SourceColumn.Table.Name, columnMapping.SourceColumn.Name)); + } + } + + // if 10k write table to db, empty table + if (TableToWrite.Rows.Count >= 1000) + { + RowsToWriteCount = RowsToWriteCount + TableToWrite.Rows.Count; + SkippedFailedRowsCount = SqlBulkCopierWriteToServer(SqlBulkCopier, TableToWrite, SkipFailingRows, Mapping, Logger); + RowsToWriteCount = RowsToWriteCount - SkippedFailedRowsCount; + TableToWrite.Clear(); + if (RowsToWriteCount >= LastLogRowsCount + 10000) + { + LastLogRowsCount = RowsToWriteCount; + Logger.Log("Added " + RowsToWriteCount + " rows to temporary table for " + Mapping.DestinationTable.Name + "."); + } + } + } } diff --git a/src/OrderProvider.cs b/src/OrderProvider.cs index ecc3721..621ff5d 100644 --- a/src/OrderProvider.cs +++ b/src/OrderProvider.cs @@ -360,7 +360,10 @@ public override bool RunJob(Job job) catch (Exception ex) { string msg = ex.Message; - LogManager.System.GetLogger(LogCategory.Application, "Dataintegration").Error($"{GetType().Name} error: {ex.Message} Stack: {ex.StackTrace}", ex); + string stackTrace = ex.StackTrace; + + Logger?.Error($"Error: {msg.Replace(System.Environment.NewLine, " ")} Stack: {stackTrace.Replace(System.Environment.NewLine, " ")}", ex); + LogManager.System.GetLogger(LogCategory.Application, "Dataintegration").Error($"{GetType().Name} error: {msg} Stack: {stackTrace}", ex); if (sourceRow != null) msg += GetFailedSourceRowMessage(sourceRow);