From 7846f782cd18fa09ee255a881ca2d0c4001986f7 Mon Sep 17 00:00:00 2001 From: MatthiasSort Date: Wed, 8 Nov 2023 10:30:27 +0100 Subject: [PATCH] added try-catch on the Close function to add a log when the SourceReader does UpdateExportedOrdersInDb. Added Transaction-logic for UpdateExportedOrdersInDb function, so we now do a RollBack if an Exception is made on the Commit to database. --- ...eb.DataIntegration.Providers.OrderProvider.csproj | 2 +- src/OrderProvider.cs | 12 ++++++++++-- src/OrderSourceReader.cs | 6 +++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj index 7244ef6..deb1f07 100644 --- a/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj @@ -1,6 +1,6 @@  - 10.0.7 + 10.0.8 1.0.0.0 Order Provider Order Provider diff --git a/src/OrderProvider.cs b/src/OrderProvider.cs index fc1e189..25e691c 100644 --- a/src/OrderProvider.cs +++ b/src/OrderProvider.cs @@ -71,8 +71,16 @@ public override void LoadSettings(Job job) public new void Close() { if (job != null && job.Result == JobResult.Completed) - OrderSourceReader.UpdateExportedOrdersInDb(OrderStateAfterExport, connection); - + { + try + { + OrderSourceReader.UpdateExportedOrdersInDb(OrderStateAfterExport, connection); + } + catch (Exception ex) + { + Logger?.Warn(ex.Message); + } + } Connection.Close(); } diff --git a/src/OrderSourceReader.cs b/src/OrderSourceReader.cs index b745597..e25dc94 100644 --- a/src/OrderSourceReader.cs +++ b/src/OrderSourceReader.cs @@ -153,6 +153,8 @@ public static void UpdateExportedOrdersInDb(string orderStateIDAfterExport, SqlC SqlCommand command = new SqlCommand { Connection = connection }; try { + command.Transaction = connection.BeginTransaction("OrderProviderTransaction"); + if (connection.State.ToString() != "Open") connection.Open(); @@ -185,10 +187,12 @@ public static void UpdateExportedOrdersInDb(string orderStateIDAfterExport, SqlC command.ExecuteNonQuery(); ClearOrderCache(_ordersToExport); } + command.Transaction.Commit(); } catch (Exception ex) { - throw new Exception(string.Format("Exception message: {0} Sql query: {1}", ex.Message, command.CommandText), ex); + command.Transaction.Rollback(); + throw new Exception(string.Format("A rollback is made as exception is made with message: {0} Sql query: {1}", ex.Message, command.CommandText), ex); } finally {