Example #1
0
        public virtual void Initialise(INotificationProvider provider, INotificationQuery query)
        {
            Provider = (T_Provider)provider;
            Query    = query;

            NotificationTable table = query as NotificationTable;

            if (table != null)
            {
                if (table.KeyFieldNames == null || table.KeyFieldNames.Length == 0)
                {
                    throw new ArgumentException("Invalid notification table. No key columns defined");
                }
            }
        }
Example #2
0
        public static void Initialise(this INotificationQuery query, IDbConnection connection)
        {
            NotificationTable table = query as NotificationTable;

            if (table != null)
            {
                if (table.ColumnNames == null || table.ColumnNames.Length == 0)
                {
                    if (connection != null)
                    {
                        if (connection.State != ConnectionState.Open)
                        {
                            connection.Open();
                        }

                        using (IDbCommand command = connection.CreateCommand())
                        {
                            command.CommandText = table.Sql;

                            using (IDataReader reader = command.ExecuteReader())
                            {
                                List <string> columns = new List <string>();
                                for (int i = 0; i < reader.FieldCount; i++)
                                {
                                    string columnName = reader.GetName(i).ToLower();
                                    if (!columns.Contains(columnName))
                                    {
                                        columns.Add(columnName);
                                    }
                                }
                                table.ColumnNames = columns.ToArray();
                                reader.Close();
                            }
                        }
                        connection.Close();
                        connection.Dispose();
                    }
                }
            }
        }
Example #3
0
        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);
                    }
                }
            }
        }