Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed logic for EcomAssortmentPermissions as it is irrelevant for t… #19

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading