コード例 #1
0
        public static NotificationConfiguration Open()
        {
            NotificationConfiguration section = null;

            section = (NotificationConfiguration)ConfigurationManager.GetSection(SECTION_NAME);
            if (section == null)
            {
                //open the config file
                System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                if (config != null)
                {
                    //open the publisher section of the config
                    section = (NotificationConfiguration)config.GetSection(SECTION_NAME);
                }
            }

            if (section == null)
            {
                section = new NotificationConfiguration();
            }

            _currentConfiguration = section;

            return(section);
        }
コード例 #2
0
        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();
        }