Skip to content

Commit

Permalink
Removed logic for EcomAssortmentPermissions as it is irrelevant for t…
Browse files Browse the repository at this point in the history
…his provider. Added missing Write function. Added extra logging in the RunJob-Catch function. Bump version to 10.0.11
  • Loading branch information
MatthiasSort committed Jan 23, 2024
1 parent 96b851f commit cbca585
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.10</Version>
<Version>10.0.11</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Order Provider</Title>
<Description>Order Provider</Description>
Expand Down
50 changes: 45 additions & 5 deletions src/OrderDestinationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand All @@ -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<string, object> 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 + ".");
}
}
}
}
5 changes: 4 additions & 1 deletion src/OrderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cbca585

Please sign in to comment.