Skip to content

Commit

Permalink
Merge pull request #23 from dynamicweb/mss/16522
Browse files Browse the repository at this point in the history
Fixed some override/new functions in the DestinationWriter. Added ext…
  • Loading branch information
frederik5480 authored Apr 23, 2024
2 parents 371e881 + 216c26c commit 4aaa972
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.14</Version>
<Version>10.0.15</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Order Provider</Title>
<Description>Order Provider</Description>
Expand Down
4 changes: 2 additions & 2 deletions src/OrderDestinationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Dynamicweb.DataIntegration.Providers.OrderProvider;

internal class OrderDestinationWriter : BaseSqlWriter
{
private new Mapping Mapping { get; }
public new Mapping Mapping { get; }
private ILogger Logger { get; }
private SqlBulkCopy SqlBulkCopier { get; }
private int SkippedFailedRowsCount { get; set; }
Expand Down Expand Up @@ -46,7 +46,7 @@ public OrderDestinationWriter(Mapping mapping, SqlConnection connection, ILogger
connection.Open();
}

protected new virtual void Initialize()
public new void Initialize()
{
List<SqlColumn> destColumns = new();
var columnMappings = Mapping.GetColumnMappings();
Expand Down
62 changes: 44 additions & 18 deletions src/OrderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace Dynamicweb.DataIntegration.Providers.OrderProvider;

[AddInName("Dynamicweb.DataIntegration.Providers.Provider"), AddInLabel("Order Provider"), AddInDescription("Order provider"), AddInIgnore(false)]
public class OrderProvider : BaseSqlProvider, IParameterOptions
public class OrderProvider : BaseSqlProvider, IParameterOptions, ISource, IDestination
{
private const string OrderCustomerAccessUserExternalId = "OrderCustomerAccessUserExternalId";
private Job job = null;
Expand Down Expand Up @@ -86,17 +86,7 @@ public override void Close()

public override Schema GetOriginalSourceSchema()
{
List<string> tablestToKeep = new() { "EcomOrders", "EcomOrderLines", "EcomOrderLineFields", "EcomOrderLineFieldGroupRelation" };
Schema result = GetSqlSourceSchema(Connection, tablestToKeep);

foreach (Table table in result.GetTables())
{
if (table.Name == "EcomOrders")
{
table.AddColumn(new SqlColumn(OrderCustomerAccessUserExternalId, typeof(string), SqlDbType.NVarChar, table, -1,
false, false, true));
}
}
Schema result = GetSqlSchemas();

var orderLinesTable = result.GetTables().FirstOrDefault(obj => string.Equals(obj.Name, "EcomOrderLines", StringComparison.OrdinalIgnoreCase));
var ordersTable = result.GetTables().FirstOrDefault(obj => string.Equals(obj.Name, "EcomOrders", StringComparison.OrdinalIgnoreCase));
Expand All @@ -106,7 +96,7 @@ public override Schema GetOriginalSourceSchema()
{
if (!column.Name.Equals(OrderCustomerAccessUserExternalId, StringComparison.OrdinalIgnoreCase))
{
_ = orderLinesTable.AddNewColumn($"{column.Name}", column.Type, -1, false, column.IsPrimaryKey);
orderLinesTable.AddColumn(new SqlColumn(column.Name, typeof(string), SqlDbType.NVarChar, orderLinesTable, -1, false, false, true));
}
}
}
Expand All @@ -116,7 +106,23 @@ public override Schema GetOriginalSourceSchema()

public override Schema GetOriginalDestinationSchema()
{
return GetOriginalSourceSchema();
Schema result = GetSqlSchemas();

foreach (Table table in result.GetTables())
{
if (table.Name == "EcomOrders")
{
table.AddColumn(new SqlColumn(OrderCustomerAccessUserExternalId, typeof(string), SqlDbType.NVarChar, table, -1, false, false, true));
}
}

return result;
}

private Schema GetSqlSchemas()
{
List<string> tablestToKeep = new() { "EcomOrders", "EcomOrderLines", "EcomOrderLineFields", "EcomOrderLineFieldGroupRelation" };
return GetSqlSourceSchema(Connection, tablestToKeep);
}

public override void OverwriteSourceSchemaToOriginal()
Expand All @@ -126,14 +132,21 @@ public override void OverwriteSourceSchemaToOriginal()

public override void OverwriteDestinationSchemaToOriginal()
{
Schema = GetOriginalSourceSchema();
Schema = GetOriginalDestinationSchema();
}

Schema IDestination.GetSchema()
{
Schema ??= GetOriginalDestinationSchema();
return Schema;
}

public override Schema GetSchema()
Schema ISource.GetSchema()
{
Schema ??= GetOriginalSourceSchema();
return Schema;
}

public OrderProvider(XmlNode xmlNode)
{
foreach (XmlNode node in xmlNode.ChildNodes)
Expand Down Expand Up @@ -206,7 +219,20 @@ public override string ValidateSourceSettings()
return null;
}

public override void SaveAsXml(XmlTextWriter xmlTextWriter)
void ISource.SaveAsXml(XmlTextWriter xmlTextWriter)
{
xmlTextWriter.WriteElementString("SqlConnectionString", SqlConnectionString);
xmlTextWriter.WriteElementString("ExportNotYetExportedOrders", ExportNotExportedOrders.ToString(CultureInfo.CurrentCulture));
xmlTextWriter.WriteElementString("ExportOnlyOrdersWithoutExtID", ExportOnlyOrdersWithoutExtID.ToString(CultureInfo.CurrentCulture));
xmlTextWriter.WriteElementString("DoNotExportCarts ", DoNotExportCarts.ToString(CultureInfo.CurrentCulture));
xmlTextWriter.WriteElementString("OrderStateAfterExport ", OrderStateAfterExport);
xmlTextWriter.WriteElementString("DiscardDuplicates", DiscardDuplicates.ToString(CultureInfo.CurrentCulture));
xmlTextWriter.WriteElementString("RemoveMissingOrderLines", RemoveMissingOrderLines.ToString(CultureInfo.CurrentCulture));
xmlTextWriter.WriteElementString("SkipFailingRows", SkipFailingRows.ToString());
(this as ISource).GetSchema().SaveAsXml(xmlTextWriter);
}

void IDestination.SaveAsXml(XmlTextWriter xmlTextWriter)
{
xmlTextWriter.WriteElementString("SqlConnectionString", SqlConnectionString);
xmlTextWriter.WriteElementString("ExportNotYetExportedOrders", ExportNotExportedOrders.ToString(CultureInfo.CurrentCulture));
Expand All @@ -216,7 +242,7 @@ public override void SaveAsXml(XmlTextWriter xmlTextWriter)
xmlTextWriter.WriteElementString("DiscardDuplicates", DiscardDuplicates.ToString(CultureInfo.CurrentCulture));
xmlTextWriter.WriteElementString("RemoveMissingOrderLines", RemoveMissingOrderLines.ToString(CultureInfo.CurrentCulture));
xmlTextWriter.WriteElementString("SkipFailingRows", SkipFailingRows.ToString());
GetSchema().SaveAsXml(xmlTextWriter);
(this as IDestination).GetSchema().SaveAsXml(xmlTextWriter);
}

public override void UpdateSourceSettings(ISource source)
Expand Down

0 comments on commit 4aaa972

Please sign in to comment.