Esempio n. 1
0
 private static string setCredentials(UpgradeWorkerServers command, string connectionString) =>
 connectionString
 .SetCredentials(
     command.SchemaUpgraderUser == null,
     command.SchemaUpgraderUser,
     command.SchemaUpgraderPassword
     );
Esempio n. 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);
        }
    }
 public void UpgradeWorkerServers(UpgradeWorkerServers command) =>
 _upgrader.Upgrade(command);