Beispiel #1
0
    public void Create(
        string storageConnectionString,
        string creatorConnectionString,
        string schemaName,
        string name)
    {
        _installer.TryConnect(storageConnectionString);

        _installer.TryConnect(creatorConnectionString);

        if (_installer.HangfireStorageSchemaExists(schemaName, creatorConnectionString))
        {
            throw new Exception("Schema already exists.");
        }

        _installer.InstallHangfireStorageSchema(schemaName, creatorConnectionString);

        _storage.WriteConfiguration(new StoredConfiguration
        {
            Name             = name,
            ConnectionString = storageConnectionString,
            SchemaName       = schemaName,
            Active           = false
        });
    }
Beispiel #2
0
    public void Upgrade(UpgradeWorkerServers command)
    {
        var exceptions = new List <Exception>();

        try
        {
            var connectionString = setCredentials(command, _options.ConfigurationOptions().ConnectionString);
            _installer.InstallHangfireConfigurationSchema(connectionString);
        }
        catch (Exception e)
        {
            exceptions.Add(e);
        }

        var configurations = _storage.ReadConfigurations();

        var exs = configurations
                  .Where(x => !string.IsNullOrEmpty(x.ConnectionString))
                  .Where(x =>
        {
            var hasSchema = x.ConnectionString.ToDbVendorSelector().SelectDialect(true, true, false);
            return(hasSchema);
        })
                  .Select(x =>
        {
            var schemaName = x.SchemaName ?? x.ConnectionString
                             .GetProvider().DefaultSchemaName();

            var connectionString = setCredentials(command, x.ConnectionString);

            try
            {
                _installer.InstallHangfireStorageSchema(schemaName, connectionString);
            }
            catch (Exception e)
            {
                return(e);
            }

            return(null);
        })
                  .Where(x => x != null)
                  .ToArray();

        exceptions.AddRange(exs);

        if (exceptions.Count == 1)
        {
            ExceptionDispatchInfo.Capture(exceptions.First()).Throw();
        }
        if (exceptions.Any())
        {
            throw new AggregateException(exceptions);
        }
    }