From 216c26c91a22a1ff8a4bc8be9a8c8e083e080f6d Mon Sep 17 00:00:00 2001 From: Matthias Sebastian Sort Date: Tue, 23 Apr 2024 08:17:21 +0200 Subject: [PATCH] Fixed some override/new functions in the DestinationWriter. Added extra function to split up the Schema when the provider is Source or Destination as there is some joined tables in the source but not allowed in the destination. --- ...Integration.Providers.OrderProvider.csproj | 2 +- src/OrderDestinationWriter.cs | 4 +- src/OrderProvider.cs | 62 +++++++++++++------ 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj index b36be72..f38e1dd 100644 --- a/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj @@ -1,6 +1,6 @@  - 10.0.14 + 10.0.15 1.0.0.0 Order Provider Order Provider diff --git a/src/OrderDestinationWriter.cs b/src/OrderDestinationWriter.cs index d98eb3a..e202ca9 100644 --- a/src/OrderDestinationWriter.cs +++ b/src/OrderDestinationWriter.cs @@ -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; } @@ -46,7 +46,7 @@ public OrderDestinationWriter(Mapping mapping, SqlConnection connection, ILogger connection.Open(); } - protected new virtual void Initialize() + public new void Initialize() { List destColumns = new(); var columnMappings = Mapping.GetColumnMappings(); diff --git a/src/OrderProvider.cs b/src/OrderProvider.cs index 97cb7c7..c5fd377 100644 --- a/src/OrderProvider.cs +++ b/src/OrderProvider.cs @@ -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; @@ -86,17 +86,7 @@ public override void Close() public override Schema GetOriginalSourceSchema() { - List 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)); @@ -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)); } } } @@ -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 tablestToKeep = new() { "EcomOrders", "EcomOrderLines", "EcomOrderLineFields", "EcomOrderLineFieldGroupRelation" }; + return GetSqlSourceSchema(Connection, tablestToKeep); } public override void OverwriteSourceSchemaToOriginal() @@ -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) @@ -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)); @@ -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)