示例#1
0
 public SqlDependencyQualifiedObjectName GetTableTrigger(SqlDependencyQualifiedObjectName table)
 {
     if (table?.Name == null)
     {
         throw new ArgumentNullException(nameof(table));
     }
     return(new SqlDependencyQualifiedObjectName(IntermediateObjectPrefix + TableTriggerBaseName + "_" + table.Name.Trim(), table.Schema));
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="table">Changed table</param>
        /// <param name="changes">Changes</param>
        public SqlDependencyTableChangedEventArgs(SqlDependencyQualifiedObjectName table, SqlDependencyMonitoredChanges changes)
        {
            if (table?.Name == null)
            {
                throw new ArgumentNullException(nameof(table));
            }
            if (changes == SqlDependencyMonitoredChanges.None)
            {
                throw new ArgumentNullException(nameof(changes));
            }

            Table = table;
            Changes = changes;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="table">Changed table</param>
        /// <param name="changes">Changes</param>
        public SqlDependencyTableChangedEventArgs(SqlDependencyQualifiedObjectName table, SqlDependencyMonitoredChanges changes)
        {
            if (table?.Name == null)
            {
                throw new ArgumentNullException(nameof(table));
            }
            if (changes == SqlDependencyMonitoredChanges.None)
            {
                throw new ArgumentNullException(nameof(changes));
            }

            Table   = table;
            Changes = changes;
        }
 /// <summary>
 /// Stops dependency on a table
 /// </summary>
 private SqlDependencyQualifiedObjectName StopDependency(SqlDependency dependency, SqlDependencyQualifiedObjectName table = null)
 {
     dependency.OnChange -= OnSqlDependencyChanged;
     using (new MonitorLock(_dependencies))
     {
         if (table == null)
         {
             table = _dependencies.Where(kv => kv.Value == dependency).Select(kv => kv.Key).SingleOrDefault();
         }
         if (table != null)
         {
             _dependencies.Remove(table);
         }
     }
     return table;
 }
        private void StartDependency(SqlDependencyQualifiedObjectName table, SqlConnection conn = null)
        {
            // Execute
            var newConnection = conn == null;
            conn = conn ?? new SqlConnection(Parameters.ConnectionString);
            try
            {
                var cmdText = string.Format(CultureInfo.InvariantCulture,
                    @"SELECT [ObjectId], [ObjectName], [LastInsertDate], [LastUpdateDate], [LastDeleteDate]
                        FROM {0}
                        WHERE [ObjectName] = '{1}'",
                    Parameters.Options.ChangeHolderTable.AlternateFullName, table);

                using (var cmd = new SqlCommand(cmdText, conn))
                {
                    // Ensure connection
                    Helper.EnsureOpenConnection(conn);

                    // Properties
                    cmd.CommandType = CommandType.Text;

                    // Set cmd notification to null
                    cmd.Notification = null;

                    // Dependency
                    var sqlDependency = new SqlDependency(cmd);
                    sqlDependency.OnChange += OnSqlDependencyChanged;

                    // Execute reader
                    using (var dataTable = new DataTable())
                    {
                        dataTable.Locale = CultureInfo.InvariantCulture;
                        using (var dataAdapter = new SqlDataAdapter(cmd))
                        {
                            dataAdapter.Fill(dataTable);
                        }
                    }

                    // Add
                    using (new MonitorLock(_dependencies))
                    {
                        _dependencies[table] = sqlDependency;
                    }
                }
            }
            finally
            {
                if (newConnection)
                {
                    conn.Dispose();
                }
            }
        }
示例#6
0
        internal static bool TriggerExists(SqlConnection connection, SqlTransaction trans, SqlDependencyQualifiedObjectName trigger)
        {
            var commandText = string.Format(CultureInfo.InvariantCulture,
                                            "SELECT COUNT(*) FROM [sys].[triggers] WHERE [object_id] = OBJECT_ID('{0}')",
                                            trigger);

            using (var cmd = new SqlCommand(commandText, connection))
            {
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = trans;
                return(Convert.ToInt32(cmd.ExecuteScalar(), CultureInfo.InvariantCulture) > 0);
            }
        }
示例#7
0
 protected void FireTableChangedEvent(SqlDependencyQualifiedObjectName table, SqlDependencyMonitoredChanges changes)
 {
     OnTableChanged?.Invoke(this, new SqlDependencyTableChangedEventArgs(table, changes));
 }
 protected void FireTableChangedEvent(SqlDependencyQualifiedObjectName table, SqlDependencyMonitoredChanges changes)
 {
     OnTableChanged?.Invoke(this, new SqlDependencyTableChangedEventArgs(table, changes));
 }
 public SqlDependencyQualifiedObjectName GetTableTrigger(SqlDependencyQualifiedObjectName table)
 {
     if (table?.Name == null)
     {
         throw new ArgumentNullException(nameof(table));
     }
     return new SqlDependencyQualifiedObjectName(IntermediateObjectPrefix + TableTriggerBaseName + "_" + table.Name.Trim(), table.Schema);
 }