public NotificationQuery(string name, NotificationMechanism notificationMechanism, NotificationLevel notificationLevel, int pollInterval, string sql, string[] keyFieldNames) { Name = name; NotificationMechanism = notificationMechanism; NotificationLevel = notificationLevel; PollInterval = pollInterval; Sql = sql; KeyFieldNames = keyFieldNames; }
public NotificationTable(string name, NotificationMechanism notificationMechanism, NotificationLevel notificationLevel, int pollInterval, string tableName, string[] keyFieldNames, string[] columnNames = null) { Name = name; NotificationMechanism = notificationMechanism; NotificationLevel = notificationLevel; PollInterval = pollInterval; TableName = tableName; KeyFieldNames = keyFieldNames; ColumnNames = columnNames; }
private void PreLoadTables() { _preLoadedRequests = new List <IDisposable>(); List <NotificationRequest> requests = new List <NotificationRequest>(); try { foreach (TableElement table in _config.PreLoadedTables) { if (string.IsNullOrEmpty(table.DatabaseType) || string.Compare(table.DatabaseType, _databaseType, true) == 0) { if (string.IsNullOrEmpty(table.DatabaseName) || string.Compare(table.DatabaseName, _databaseName, true) == 0) { string tableName = table.Table; string[] tableKey = null; if (!string.IsNullOrEmpty(table.Key)) { tableKey = table.Key.Split(','); } NotificationMechanism notificationMechanism = table.NotificationMechanism == NotificationMechanism.None ? _config.DefaultNotificationMechanism : table.NotificationMechanism; NotificationLevel notificationLevel = table.NotificationLevel == NotificationLevel.None ? _config.DefaultNotificationLevel : table.NotificationLevel; int pollInterval = table.PollInterval == 0 ? _config.DefaultPollInterval : table.PollInterval; requests.Add(new NotificationRequest(Guid.NewGuid().ToString(), new NotificationTable(tableName, notificationMechanism, notificationLevel, pollInterval, tableName, tableKey))); } } } Parallel.ForEach(requests, request => { try { _preLoadedRequests.Add(RegisterNotification(request, null)); } catch (Exception ex) { if (_log.IsErrorEnabled) { foreach (var query in request.Queries) { _log.ErrorFormat("Failed to pre-load table: {0} - {1}", query.Name, ex.Message); } } } }); } catch (Exception ex) { if (_log.IsErrorEnabled) { _log.ErrorFormat("Failed to pre-load tables: {0}", ex.Message); } } }
public NotificationManager(string databaseType, string databaseName, string connectionString = "") { _databaseType = databaseType; _databaseName = databaseName; try { _config = NotificationConfiguration.Current; if (string.IsNullOrEmpty(connectionString)) { _connectionString = _config.Databases.GetConnectionString(databaseType, databaseName); if (string.IsNullOrEmpty(connectionString)) { var element = ConfigurationManager.ConnectionStrings[databaseName]; if (element != null) { _connectionString = element.ConnectionString; } } } else { _connectionString = connectionString; } _defaultNotificationMechanism = _config.DefaultNotificationMechanism; _defaultNotificationLevel = _config.DefaultNotificationLevel; _defaultPollInterval = _config.DefaultPollInterval; } catch (Exception ex) { throw new InvalidOperationException("Failed to read notification configuration", ex); } if (string.IsNullOrEmpty(_connectionString)) { throw new ArgumentException("Connection string required"); } LoadProvider(_databaseType); PreLoadTables(); }
public NotificationTable(string name, NotificationMechanism notificationMechanism, NotificationLevel notificationLevel, int pollInterval, string tableName, string keyFieldName, string[] columnNames = null) : this(name, notificationMechanism, notificationLevel, pollInterval, tableName, new string[] { keyFieldName }, columnNames) { }
public NotificationQuery(string name, NotificationMechanism notificationMechanism, NotificationLevel notificationLevel, int pollInterval, string sql, string keyFieldName) : this(name, notificationMechanism, notificationLevel, pollInterval, sql, new string[] { keyFieldName }) { }
private void ApplyOverrides(NotificationRequest request) { try { List <INotificationQuery> newQueries = new List <INotificationQuery>(); foreach (INotificationQuery query in request.Queries) { NotificationTable table = query as NotificationTable; if (table == null) { newQueries.Add(query); } else { var tableOverride = _config.TableOverrides.GetTable(table.Name, _databaseType, _databaseName); if (tableOverride == null) { newQueries.Add(query); } else { if (tableOverride.Overrides.Count == 0) { table.PollInterval = tableOverride.PollInterval == 0 ? table.PollInterval : tableOverride.PollInterval; table.NotificationMechanism = tableOverride.NotificationMechanism == NotificationMechanism.None ? table.NotificationMechanism : tableOverride.NotificationMechanism; table.NotificationLevel = tableOverride.NotificationLevel == NotificationLevel.None ? table.NotificationLevel : tableOverride.NotificationLevel; newQueries.Add(table); if (_log.IsInfoEnabled) { _log.InfoFormat("Notification Table override: {0}, Poll Interval={1}, Poll Mechanism={2}", table.Name, table.PollInterval, table.NotificationMechanism); } } else { foreach (TableElement newTable in tableOverride.Overrides) { string newTableName = newTable.Table; string[] newTableKey = null; if (!string.IsNullOrEmpty(newTable.Key)) { newTableKey = newTable.Key.Split(','); } NotificationMechanism newNotificationMechanism = newTable.NotificationMechanism == NotificationMechanism.None ? tableOverride.NotificationMechanism : newTable.NotificationMechanism; newNotificationMechanism = newNotificationMechanism == NotificationMechanism.None ? table.NotificationMechanism : newNotificationMechanism; NotificationLevel newNotificationLevel = newTable.NotificationLevel == NotificationLevel.None ? tableOverride.NotificationLevel : newTable.NotificationLevel; newNotificationLevel = newNotificationLevel == NotificationLevel.None ? table.NotificationLevel : newNotificationLevel; int newPollInterval = newTable.PollInterval == 0 ? tableOverride.PollInterval : newTable.PollInterval; newPollInterval = newPollInterval == 0 ? table.PollInterval : newPollInterval; newQueries.Add(new NotificationTable(newTableName, newNotificationMechanism, newNotificationLevel, newPollInterval, newTableName, newTableKey)); if (_log.IsInfoEnabled) { _log.InfoFormat("Notification Table override: {0}, New Table={1}, New Table Key='{2}', Poll Interval={3}, Notification Mechanism={4}, Notification Level={4}", table.Name, newTableName, newTable.Key, newPollInterval, newNotificationMechanism, newNotificationLevel); } } } } } } request.Queries = newQueries.ToArray(); } catch (Exception ex) { if (_log.IsErrorEnabled) { foreach (var query in request.Queries) { _log.ErrorFormat("Failed to apply table overloads: {0}", query.Name, ex.Message); } } } }