Exemple #1
0
        public void Add(string databaseName, string serverName)
        {
            if (databaseName is null)
            {
                throw new ArgumentNullException(nameof(databaseName));
            }
            if (serverName is null)
            {
                throw new ArgumentNullException(nameof(serverName));
            }

            if (!_databaseValidator.IsValidName(name: databaseName))
            {
                throw new ArgumentException($"Invalid database databaseName {databaseName}.", nameof(databaseName));
            }

            if (!_databaseValidator.IsUniqueName(name: databaseName))
            {
                throw new ArgumentException($"Database with databaseName {databaseName} is already exists.", nameof(databaseName));
            }

            if (!_databaseValidator.IsValidServerName(serverName: serverName))
            {
                throw new ArgumentException($"Invalid server databaseName {serverName}.", nameof(serverName));
            }

            Database database = new Database(name: databaseName, serverName: serverName);

            _databaseRepository.Add(entity: database);
        }
Exemple #2
0
        public void RenameDatabase(Database database, string databaseName)
        {
            if (database is null)
            {
                throw new ArgumentNullException(nameof(database));
            }
            if (databaseName is null)
            {
                throw new ArgumentNullException(nameof(databaseName));
            }

            if (database.Name == databaseName)
            {
                return;
            }

            if (!_databaseValidator.IsValidName(name: databaseName))
            {
                throw new ArgumentException($"Invalid database tableName {databaseName}.", nameof(databaseName));
            }

            if (!_databaseValidator.IsUniqueName(name: databaseName))
            {
                throw new ArgumentException($"Database with tableName {databaseName} is already exists.", nameof(databaseName));
            }

            if (_deployService.IsDeployed(database: database))
            {
                _deployService.RenameDeployedDatabase(database: database, validNewDatabaseName: databaseName);
            }

            _databaseService.Rename(database: database, name: databaseName);
        }