Exemplo n.º 1
0
 public FirebirdConnection(
     FbConnection connection,
     PersistentJobQueueProviderCollection queueProviders,
     FirebirdStorageOptions options)
     : this(connection, queueProviders, options, true)
 {
 }
 public FirebirdConnection(
     FbConnection connection,
     PersistentJobQueueProviderCollection queueProviders,
     FirebirdStorageOptions options)
     : this(connection, queueProviders, options, true)
 {
 }
Exemplo n.º 3
0
        public FirebirdFetchedJob(
            IDbConnection connection,
            FirebirdStorageOptions options,
            int id,
            string jobId,
            string queue)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (jobId == null)
            {
                throw new ArgumentNullException("jobId");
            }
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _connection = connection;
            _options    = options;

            Id    = id;
            JobId = jobId;
            Queue = queue;
        }
        public FirebirdJobQueueMonitoringApi(IDbConnection connection, FirebirdStorageOptions options)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            if (options == null) throw new ArgumentNullException("options");

            _connection = connection;
            _options = options;
        }
        public ExpirationManager(FirebirdStorage storage, FirebirdStorageOptions options, TimeSpan checkInterval)
        {
            if (storage == null) throw new ArgumentNullException("storage");
            if (options == null) throw new ArgumentNullException("options");

            _options = options;
            _storage = storage;
            _checkInterval = checkInterval;
        }
Exemplo n.º 6
0
        public FirebirdJobQueueProvider(FirebirdStorageOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _options = options;
        }
        private void Init(string resource, TimeSpan timeout, IDbConnection connection, FirebirdStorageOptions options)
        {
            Stopwatch lockAcquiringTime = new Stopwatch();
            lockAcquiringTime.Start();

            bool tryAcquireLock = true;

            while (tryAcquireLock)
            {
                try
                {
                    int rowsAffected = -1;
                    using (var trx = _connection.BeginTransaction(IsolationLevel.RepeatableRead))
                    {
                        rowsAffected = _connection.Execute(string.Format(@"
                            INSERT INTO ""{0}.LOCK"" (resource) 
                            SELECT @resource
                            FROM rdb$database
                            WHERE NOT EXISTS (
                                SELECT 1 FROM ""{0}.LOCK"" 
                                WHERE resource = @resource
                            );
                            ", _options.Prefix), new
                             {
                                 resource = resource
                             }, trx);

                        trx.Commit();
                    }
                    if (rowsAffected > 0) return;
                }
                catch (Exception)
                {
                }

                if (lockAcquiringTime.ElapsedMilliseconds > timeout.TotalMilliseconds)
                    tryAcquireLock = false;
                else
                {
                    int sleepDuration = (int)(timeout.TotalMilliseconds - lockAcquiringTime.ElapsedMilliseconds);
                    if (sleepDuration > 1000) sleepDuration = 1000;
                    if (sleepDuration > 0)
                        Thread.Sleep(sleepDuration);
                    else
                        tryAcquireLock = false;
                }
            }

            throw new FirebirdDistributedLockException(
                string.Format(
                "Could not place a lock on the resource '{0}': {1}.",
                _resource,
                "Lock timeout"));

        }
        public static FirebirdStorage UseFirebirdStorage(
            this IBootstrapperConfiguration configuration,
            string nameOrConnectionString,
            FirebirdStorageOptions options)
        {
            var storage = new FirebirdStorage(nameOrConnectionString, options);

            configuration.UseStorage(storage);

            return(storage);
        }
        public FirebirdDistributedLock(string resource, TimeSpan timeout, IDbConnection connection,
            FirebirdStorageOptions options)
        {
            if (String.IsNullOrEmpty(resource)) throw new ArgumentNullException("resource");
            if (connection == null) throw new ArgumentNullException("connection");
            if (options == null) throw new ArgumentNullException("options");

            _resource = resource;
            _connection = connection;
            _options = options;

            Init(resource, timeout, connection, options);
        }
        public FirebirdWriteOnlyTransaction( 
            FbConnection connection,
            FirebirdStorageOptions options,
            PersistentJobQueueProviderCollection queueProviders)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            if (queueProviders == null) throw new ArgumentNullException("queueProviders");
            if (options == null) throw new ArgumentNullException("options");

            _connection = connection;
            _options = options;
            _queueProviders = queueProviders;
        }
Exemplo n.º 11
0
        public FirebirdMonitoringApi(
            string connectionString,
            FirebirdStorageOptions options,
            PersistentJobQueueProviderCollection queueProviders)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _connectionString = connectionString;
            _queueProviders   = queueProviders;
            _options          = options;
        }
Exemplo n.º 12
0
        public FirebirdJobQueueMonitoringApi(IDbConnection connection, FirebirdStorageOptions options)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _connection = connection;
            _options    = options;
        }
        public FirebirdConnection(
            FbConnection connection, 
            PersistentJobQueueProviderCollection queueProviders,
            FirebirdStorageOptions options,
            bool ownsConnection)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            if (queueProviders == null) throw new ArgumentNullException("queueProviders");
            if (options == null) throw new ArgumentNullException("options");

            _connection = connection;
            _queueProviders = queueProviders;
            _options = options;
            OwnsConnection = ownsConnection;
        }
Exemplo n.º 14
0
        public ExpirationManager(FirebirdStorage storage, FirebirdStorageOptions options, TimeSpan checkInterval)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _options       = options;
            _storage       = storage;
            _checkInterval = checkInterval;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FirebirdStorage"/> class with
        /// explicit instance of the <see cref="FbConnection"/> class that will be used
        /// to query the data.
        /// </summary>
        /// <param name="existingConnection">Existing connection</param>
        /// <param name="options">FirebirdStorageOptions</param>
        public FirebirdStorage(FbConnection existingConnection, FirebirdStorageOptions options)
        {
            if (existingConnection == null)
            {
                throw new ArgumentNullException("existingConnection");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            //var connectionStringBuilder = new FbConnectionStringBuilder(existingConnection.ConnectionString);
            //if (connectionStringBuilder.Enlist) throw new ArgumentException("FirebirdSql is not fully compatible with TransactionScope yet, only connections without Enlist = true are accepted.");

            _existingConnection = existingConnection;
            _options            = new FirebirdStorageOptions();

            InitializeQueueProviders();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initializes FirebirdStorage from the provided FirebirdStorageOptions and either the provided connection
        /// string or the connection string with provided name pulled from the application config file.
        /// </summary>
        /// <param name="nameOrConnectionString">Either a Firebird connection string or the name of
        /// a Firebird connection string located in the connectionStrings node in the application config</param>
        /// <param name="options"></param>
        /// <exception cref="ArgumentNullException"><paramref name="nameOrConnectionString"/> argument is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> argument is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="nameOrConnectionString"/> argument is neither
        /// a valid Firebird connection string nor the name of a connection string in the application
        /// config file.</exception>
        public FirebirdStorage(string nameOrConnectionString, FirebirdStorageOptions options)
        {
            if (nameOrConnectionString == null)
            {
                throw new ArgumentNullException("nameOrConnectionString");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _options = options;

            if (IsConnectionString(nameOrConnectionString))
            {
                _connectionString = nameOrConnectionString;
            }
            else if (IsConnectionStringInConfiguration(nameOrConnectionString))
            {
                _connectionString = ConfigurationManager.ConnectionStrings[nameOrConnectionString].ConnectionString;
            }
            else
            {
                throw new ArgumentException(
                          string.Format("Could not find connection string with name '{0}' in application config file",
                                        nameOrConnectionString));
            }

            if (options.PrepareSchemaIfNecessary)
            {
                var connectionStringBuilder = new FbConnectionStringBuilder(_connectionString);
                if (!File.Exists(connectionStringBuilder.Database))
                {
                    FbConnection.CreateDatabase(_connectionString, 16384, true, false);
                }

                using (var connection = CreateAndOpenConnection())
                {
                    FirebirdObjectsInstaller.Install(connection);
                }
            }

            InitializeQueueProviders();
        }
        public FirebirdFetchedJob(
            IDbConnection connection, 
            FirebirdStorageOptions options,
            int id, 
            string jobId, 
            string queue)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            if (jobId == null) throw new ArgumentNullException("jobId");
            if (queue == null) throw new ArgumentNullException("queue");
            if (options == null) throw new ArgumentNullException("options");

            _connection = connection;
            _options = options;

            Id = id;
            JobId = jobId;
            Queue = queue;
        }
        public FirebirdWriteOnlyTransaction(
            FbConnection connection,
            FirebirdStorageOptions options,
            PersistentJobQueueProviderCollection queueProviders)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (queueProviders == null)
            {
                throw new ArgumentNullException("queueProviders");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _connection     = connection;
            _options        = options;
            _queueProviders = queueProviders;
        }
        public FirebirdDistributedLock(string resource, TimeSpan timeout, IDbConnection connection,
                                       FirebirdStorageOptions options)
        {
            if (String.IsNullOrEmpty(resource))
            {
                throw new ArgumentNullException("resource");
            }
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _resource   = resource;
            _connection = connection;
            _options    = options;

            Init(resource, timeout, connection, options);
        }
        public static IGlobalConfiguration <FirebirdStorage> UseFirebirdStorage(
            [NotNull] this IGlobalConfiguration configuration,
            [NotNull] string nameOrConnectionString,
            [NotNull] FirebirdStorageOptions options)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            if (nameOrConnectionString == null)
            {
                throw new ArgumentNullException("nameOrConnectionString");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            var storage = new FirebirdStorage(nameOrConnectionString, options);

            return(configuration.UseStorage(storage));
        }
Exemplo n.º 21
0
        public FirebirdConnection(
            FbConnection connection,
            PersistentJobQueueProviderCollection queueProviders,
            FirebirdStorageOptions options,
            bool ownsConnection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (queueProviders == null)
            {
                throw new ArgumentNullException("queueProviders");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _connection     = connection;
            _queueProviders = queueProviders;
            _options        = options;
            OwnsConnection  = ownsConnection;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Initializes FirebirdStorage from the provided FirebirdStorageOptions and either the provided connection
        /// string or the connection string with provided name pulled from the application config file.       
        /// </summary>
        /// <param name="nameOrConnectionString">Either a Firebird connection string or the name of 
        /// a Firebird connection string located in the connectionStrings node in the application config</param>
        /// <param name="options"></param>
        /// <exception cref="ArgumentNullException"><paramref name="nameOrConnectionString"/> argument is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> argument is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="nameOrConnectionString"/> argument is neither 
        /// a valid Firebird connection string nor the name of a connection string in the application
        /// config file.</exception>
        public FirebirdStorage(string nameOrConnectionString, FirebirdStorageOptions options)
        {
            if (nameOrConnectionString == null) throw new ArgumentNullException("nameOrConnectionString");
            if (options == null) throw new ArgumentNullException("options");

            _options = options;

            if (IsConnectionString(nameOrConnectionString))
            {
                _connectionString = nameOrConnectionString;
            }
            else if (IsConnectionStringInConfiguration(nameOrConnectionString))
            {
                _connectionString = ConfigurationManager.ConnectionStrings[nameOrConnectionString].ConnectionString;
            }
            else
            {
                throw new ArgumentException(
                    string.Format("Could not find connection string with name '{0}' in application config file",
                                  nameOrConnectionString));
            }

            if (options.PrepareSchemaIfNecessary)
            {
                var connectionStringBuilder = new FbConnectionStringBuilder(_connectionString);
                if (!File.Exists(connectionStringBuilder.Database))
                    FbConnection.CreateDatabase(_connectionString, 16384, true, false);

                using (var connection = CreateAndOpenConnection())
                {
                    FirebirdObjectsInstaller.Install(connection);
                }
            }

            InitializeQueueProviders();
        }
        public FirebirdJobQueueProvider(FirebirdStorageOptions options)
        {
            if (options == null) throw new ArgumentNullException("options");

            _options = options;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FirebirdStorage"/> class with
        /// explicit instance of the <see cref="FbConnection"/> class that will be used
        /// to query the data.
        /// </summary>
        /// <param name="existingConnection">Existing connection</param>
        /// <param name="options">FirebirdStorageOptions</param>
        public FirebirdStorage(FbConnection existingConnection, FirebirdStorageOptions options)
        {
            if (existingConnection == null) throw new ArgumentNullException("existingConnection");
            if (options == null) throw new ArgumentNullException("options");
            //var connectionStringBuilder = new FbConnectionStringBuilder(existingConnection.ConnectionString);
            //if (connectionStringBuilder.Enlist) throw new ArgumentException("FirebirdSql is not fully compatible with TransactionScope yet, only connections without Enlist = true are accepted.");

            _existingConnection = existingConnection;
            _options = new FirebirdStorageOptions();

            InitializeQueueProviders();
        }
Exemplo n.º 25
0
 public ExpirationManager(FirebirdStorage storage, FirebirdStorageOptions options)
     : this(storage, options, TimeSpan.FromHours(1))
 {
 }
 public ExpirationManager(FirebirdStorage storage, FirebirdStorageOptions options)
     : this(storage, options, TimeSpan.FromHours(1))
 {
 }
        private void Init(string resource, TimeSpan timeout, IDbConnection connection, FirebirdStorageOptions options)
        {
            Stopwatch lockAcquiringTime = new Stopwatch();

            lockAcquiringTime.Start();

            bool tryAcquireLock = true;

            while (tryAcquireLock)
            {
                try
                {
                    int rowsAffected = -1;
                    using (var trx = _connection.BeginTransaction(IsolationLevel.RepeatableRead))
                    {
                        rowsAffected = _connection.Execute(string.Format(@"
                            INSERT INTO ""{0}.LOCK"" (resource) 
                            SELECT @resource
                            FROM rdb$database
                            WHERE NOT EXISTS (
                                SELECT 1 FROM ""{0}.LOCK"" 
                                WHERE resource = @resource
                            );
                            ", _options.Prefix), new
                        {
                            resource = resource
                        }, trx);

                        trx.Commit();
                    }
                    if (rowsAffected > 0)
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                }

                if (lockAcquiringTime.ElapsedMilliseconds > timeout.TotalMilliseconds)
                {
                    tryAcquireLock = false;
                }
                else
                {
                    int sleepDuration = (int)(timeout.TotalMilliseconds - lockAcquiringTime.ElapsedMilliseconds);
                    if (sleepDuration > 1000)
                    {
                        sleepDuration = 1000;
                    }
                    if (sleepDuration > 0)
                    {
                        Thread.Sleep(sleepDuration);
                    }
                    else
                    {
                        tryAcquireLock = false;
                    }
                }
            }

            throw new FirebirdDistributedLockException(
                      string.Format(
                          "Could not place a lock on the resource '{0}': {1}.",
                          _resource,
                          "Lock timeout"));
        }