From 784df84bf1c65d80f1b31acce16d8419d21d7c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20IVASCOT?= Date: Fri, 16 Oct 2020 15:11:25 +0200 Subject: [PATCH] - Fix the trigger "auto-drop" function (the trigger drop needs to be the last operation before return) - Fix incorrect WaitForNotifications start that prevent stop to termitate if stoped on application closing (wrong task was waited) --- .../Inheritance/SqlTableDependencyTest.cs | 2 +- .../Resources/SqlScripts.cs | 16 +++++++-- .../SqlTableDependency.cs | 33 ++++++++++--------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/TableDependency.SqlClient.Test/Inheritance/SqlTableDependencyTest.cs b/TableDependency.SqlClient.Test/Inheritance/SqlTableDependencyTest.cs index db5dfb6..51cab25 100644 --- a/TableDependency.SqlClient.Test/Inheritance/SqlTableDependencyTest.cs +++ b/TableDependency.SqlClient.Test/Inheritance/SqlTableDependencyTest.cs @@ -177,7 +177,7 @@ protected override IList CreateSqlServerDatabaseObjects(IEnumerable - WaitForNotifications( - _cancellationTokenSource.Token, - onChangedSubscribedList, - onErrorSubscribedList, - onStatusChangedSubscribedList, - timeOut, - watchDogTimeOut), - _cancellationTokenSource.Token); + _task = WaitForNotifications(_cancellationTokenSource.Token, onChangedSubscribedList, onErrorSubscribedList, + onStatusChangedSubscribedList, timeOut, watchDogTimeOut); this.WriteTraceMessage(TraceLevel.Info, $"Waiting for receiving {_tableName}'s records change notifications."); } @@ -192,7 +185,7 @@ public override void Stop() if (_task != null) { _cancellationTokenSource.Cancel(true); - _task?.Wait(); + _task.Wait(); } _task = null; @@ -382,7 +375,7 @@ protected override void DropDatabaseObjects() return string.Format("IF EXISTS (SELECT * FROM sys.service_message_types WITH (NOLOCK) WHERE name = N'{0}') DROP MESSAGE TYPE [{0}];", pm); })); - var dropAllScript = this.PrepareScriptDropAll(dropMessages); + var dropAllScript = this.PrepareScriptDropAll(dropMessages, false); sqlCommand.Transaction = sqlTransaction; sqlCommand.CommandType = CommandType.Text; @@ -525,7 +518,8 @@ protected virtual IList CreateSqlServerDatabaseObjects(IEnumerable CreateSqlServerDatabaseObjects(IEnumerable