From b495ff84468710e371b7a964e314e8440cfe5936 Mon Sep 17 00:00:00 2001 From: Hamid Date: Sun, 19 Jun 2022 18:23:31 +0430 Subject: [PATCH] Adding Table Name With Schema to Message Event --- .../SqlDependencyEx.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ServiceBrokerListener/ServiceBrokerListener.Domain/SqlDependencyEx.cs b/ServiceBrokerListener/ServiceBrokerListener.Domain/SqlDependencyEx.cs index d78b77d..4d07afe 100644 --- a/ServiceBrokerListener/ServiceBrokerListener.Domain/SqlDependencyEx.cs +++ b/ServiceBrokerListener/ServiceBrokerListener.Domain/SqlDependencyEx.cs @@ -26,14 +26,16 @@ public enum NotificationTypes public class TableChangedEventArgs : EventArgs { private readonly string notificationMessage; + private readonly string tableNameWithShema; private const string INSERTED_TAG = "inserted"; private const string DELETED_TAG = "deleted"; - public TableChangedEventArgs(string notificationMessage) + public TableChangedEventArgs(string notificationMessage,string tableNameWithShema) { this.notificationMessage = notificationMessage; + this.tableNameWithShema = tableNameWithShema; } public XElement Data @@ -42,7 +44,7 @@ public XElement Data { if (string.IsNullOrWhiteSpace(notificationMessage)) return null; - return ReadXDocumentWithInvalidCharacters(notificationMessage); + return ReadXDocumentWithInvalidCharacters(notificationMessage, tableNameWithShema); } } @@ -66,11 +68,11 @@ public NotificationTypes NotificationType /// /// The input string. /// The result XElement. - private static XElement ReadXDocumentWithInvalidCharacters(string xml) + private static XElement ReadXDocumentWithInvalidCharacters(string xml,string tblName) { XDocument xDocument = null; - XmlReaderSettings xmlReaderSettings = new XmlReaderSettings {CheckCharacters = false}; + XmlReaderSettings xmlReaderSettings = new XmlReaderSettings { CheckCharacters = false }; using (var stream = new StringReader(xml)) using (XmlReader xmlReader = XmlReader.Create(stream, xmlReaderSettings)) @@ -80,6 +82,8 @@ private static XElement ReadXDocumentWithInvalidCharacters(string xml) xDocument = XDocument.Load(xmlReader); } + xDocument.Root.Add(new XDocument("Table",tblName)); + return xDocument.Root; } } @@ -778,10 +782,11 @@ private void InstallNotification() private void OnTableChanged(string message) { + var tblWithShem = SchemaName + "." + TableName; var evnt = this.TableChanged; if (evnt == null) return; - evnt.Invoke(this, new TableChangedEventArgs(message)); + evnt.Invoke(this, new TableChangedEventArgs(message, tblWithShem)); } private void OnNotificationProcessStopped()