示例#1
0
    /// <summary>
    /// Validates control.
    /// </summary>
    public bool ValidateForSeparation()
    {
        // Get database name
        if (radCreateNew.Checked && SqlServerCapabilities.SupportsDatabaseCreation)
        {
            Database = txtNewDatabaseName.Text;
        }
        else
        {
            Database = txtExistingDatabaseName.Text;
        }
        Database = TextHelper.LimitLength(Database, 100, String.Empty);

        if (String.IsNullOrEmpty(Database))
        {
            DisplaySeparationError(GetString("Install.ErrorDBNameEmpty"));
            return(false);
        }

        // Set up the connection string
        ConnectionString = ConnectionHelper.BuildConnectionString(AuthenticationType, ServerName, Database, Username, Password, 240);

        // Test existing DB
        if (radUseExisting.Checked || !SqlServerCapabilities.SupportsDatabaseCreation)
        {
            if (SqlServerCapabilities.ControlServerPermissionAvailable &&
                !DatabaseHelper.CheckDBPermission(DatabasePermission.ModifyDatabase, AuthenticationType, ServerName, Username, Password))
            {
                DisplaySeparationError(GetString("separationDB.permissionmodify"));
                return(false);
            }

            if (!String.IsNullOrEmpty(ConnectionHelper.TestConnection(AuthenticationType, ServerName, Database, Username, Password)))
            {
                DisplaySeparationError(String.Format(ResHelper.GetFileString("Install.ErrorDatabseDoesntExist"), Database));
                return(false);
            }

            if (DatabaseSeparationHelper.CheckCMDatabase(ConnectionString))
            {
                DisplaySeparationError(GetString("separationDB.errorCMexists"));
                return(false);
            }
        }
        // Test new DB
        else
        {
            if (DatabaseHelper.DatabaseExists(ConnectionString))
            {
                DisplaySeparationError(GetString("separationDB.ErrorDBExists"));
                return(false);
            }
            if (SqlServerCapabilities.ControlServerPermissionAvailable)
            {
                if (!DatabaseHelper.CheckDBPermission(DatabasePermission.ModifyDatabase, AuthenticationType, ServerName, Username, Password))
                {
                    DisplaySeparationError(GetString("separationDB.permissionmodify"));
                    return(false);
                }
                if (!DatabaseHelper.CheckDBPermission(DatabasePermission.CreateDatabase, AuthenticationType, ServerName, Username, Password))
                {
                    DisplaySeparationError(GetString("separationDB.permissioncreate"));
                    return(false);
                }
            }
        }

        // Test if tasks are stopped
        if (SchedulingHelper.EnableScheduler || SchedulingHelper.IsAnyTaskRunning())
        {
            DisplaySeparationError(GetString("separationDB.stoptaskserror"));
            return(false);
        }
        iconHelp.Visible = btnStopTasks.Visible = true;

        // Test if separation process is not already started.
        if (DatabaseSeparationHelper.SeparationInProgress)
        {
            DisplaySeparationError(GetString("separationDB.processalreadystarted"));
            return(false);
        }

        return(true);
    }
    /// <summary>
    /// Validates control.
    /// </summary>
    public bool ValidateForSeparation()
    {
        bool dbEngineSupportsDBCreation = !DatabaseSeparationHelper.IsUsingAzureDatabase;

        // Get database name
        if (radCreateNew.Checked && dbEngineSupportsDBCreation)
        {
            Database = txtNewDatabaseName.Text;
        }
        else
        {
            Database = txtExistingDatabaseName.Text;
        }
        Database = TextHelper.LimitLength(Database, 100, String.Empty);

        if (String.IsNullOrEmpty(Database))
        {
            DisplaySeparationError(GetString("Install.ErrorDBNameEmpty"));
            return(false);
        }

        // Set up the connection string
        ConnectionString = ConnectionHelper.GetConnectionString(AuthenticationType, ServerName, Database, Username, Password, 240, false);

        // Test existing DB
        if (radUseExisting.Checked || !dbEngineSupportsDBCreation)
        {
            bool dbControlServerPermissionRequired = !DatabaseSeparationHelper.IsUsingAzureDatabase;

            if (dbControlServerPermissionRequired &&
                !DatabaseHelper.CheckDBPermission(DatabasePermission.ModifyDatabase, AuthenticationType, ServerName, Username, Password))
            {
                DisplaySeparationError(GetString("separationDB.permissionmodify"));
                return(false);
            }

            if (!String.IsNullOrEmpty(ConnectionHelper.TestConnection(AuthenticationType, ServerName, Database, Username, Password)))
            {
                DisplaySeparationError(String.Format(ResHelper.GetFileString("Install.ErrorDatabseDoesntExist"), Database));
                return(false);
            }

            if (DatabaseSeparationHelper.CheckCMDatabase(ConnectionString))
            {
                DisplaySeparationError(GetString("separationDB.errorCMexists"));
                return(false);
            }
        }
        // Test new DB
        else
        {
            if (DatabaseHelper.DatabaseExists(ConnectionString))
            {
                DisplaySeparationError(GetString("separationDB.ErrorDBExists"));
                return(false);
            }
            if (!SystemContext.IsRunningOnAzure)
            {
                if (!DatabaseHelper.CheckDBPermission(DatabasePermission.ModifyDatabase, AuthenticationType, ServerName, Username, Password))
                {
                    DisplaySeparationError(GetString("separationDB.permissionmodify"));
                    return(false);
                }
                if (!DatabaseHelper.CheckDBPermission(DatabasePermission.CreateDatabase, AuthenticationType, ServerName, Username, Password))
                {
                    DisplaySeparationError(GetString("separationDB.permissioncreate"));
                    return(false);
                }
            }
        }

        // Test if tasks are stopped
        if (EnabledTasks())
        {
            DisplaySeparationError(GetString("separationDB.stoptaskserror"));
            return(false);
        }
        iconHelp.Visible = btnStopTasks.Visible = true;

        // Test if separation process is not already started.
        if (DatabaseSeparationHelper.SeparationInProgress)
        {
            DisplaySeparationError(GetString("separationDB.processalreadystarted"));
            return(false);
        }

        return(true);
    }