示例#1
0
        /// <summary>
        /// Constructs Job Storage by Mongo client settings, name and options
        /// </summary>
        /// <param name="mongoClientSettings">Client settings for MongoDB</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="options">Storage options</param>
        public MongoStorage(MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions options)
        {
            if (mongoClientSettings == null)
            {
                throw new ArgumentNullException("mongoClientSettings");
            }

            if (String.IsNullOrWhiteSpace(databaseName) == true)
            {
                throw new ArgumentNullException("databaseName");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _mongoClientSettings = mongoClientSettings;
            _databaseName        = databaseName;
            _options             = options;

            Connection = new HangfireDbContext(mongoClientSettings, databaseName, options.Prefix);
            var defaultQueueProvider = new MongoJobQueueProvider(options);

            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }
示例#2
0
        /// <summary>
        /// Constructs Job Storage by Mongo client settings, name and options
        /// </summary>
        /// <param name="mongoClientSettings">Client settings for MongoDB</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="storageOptions">Storage options</param>
        public MongoStorage(MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions storageOptions)
        {
            if (mongoClientSettings == null)
            {
                throw new ArgumentNullException(nameof(mongoClientSettings));
            }
            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentNullException(nameof(databaseName));
            }
            if (storageOptions == null)
            {
                throw new ArgumentNullException(nameof(storageOptions));
            }

            _mongoClientSettings = mongoClientSettings;
            _databaseName        = databaseName;
            _storageOptions      = storageOptions;

            Connection = new HangfireDbContext(mongoClientSettings, databaseName, _storageOptions.Prefix);

            var defaultQueueProvider = new MongoJobQueueProvider(_storageOptions);

            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }
示例#3
0
        /// <summary>
        /// Constructs Job Storage by database connection string, name and options
        /// </summary>
        /// <param name="connectionString">MongoDB connection string</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="storageOptions">Storage options</param>
        public MongoStorage(string connectionString, string databaseName, MongoStorageOptions storageOptions)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }
            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentNullException(nameof(databaseName));
            }
            if (storageOptions == null)
            {
                throw new ArgumentNullException(nameof(storageOptions));
            }

            _connectionString = connectionString;
            _databaseName     = databaseName;
            _storageOptions   = storageOptions;

            Connection = new HangfireDbContext(connectionString, databaseName, storageOptions.Prefix);
            Connection.Init(_storageOptions);

            var defaultQueueProvider = new MongoJobQueueProvider(_storageOptions);

            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }
示例#4
0
        /// <summary>
        /// Constructs Job Storage by Mongo client settings, name and options
        /// </summary>
        /// <param name="mongoClientSettings">Client settings for MongoDB</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="storageOptions">Storage options</param>
        public MongoStorage(MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions storageOptions)
        {
            _mongoClientSettings = mongoClientSettings ?? throw new ArgumentNullException(nameof(mongoClientSettings));
            _databaseName        = databaseName ?? throw new ArgumentNullException(nameof(databaseName));
            _storageOptions      = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions));

            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentException("Please state a connection name", nameof(databaseName));
            }

            Connection = new HangfireDbContext(mongoClientSettings, databaseName, _storageOptions.Prefix);

            var migrationManager = new MongoMigrationManager(storageOptions);

            migrationManager.Migrate(Connection);

            var defaultQueueProvider = new MongoJobQueueProvider(_storageOptions);

            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }