private static void GrantPlatformPermissions(PlatformDatabaseConfiguration platformConfiguration)
 {
     try {
         ConfigurationManagerUtils.ExecuteStatements(
             platformConfiguration.ElevatedRuntimeDatabaseConfiguration(),
             GetGrantPlatformPermissionsStatements(platformConfiguration.RuntimeUser));
     } catch { }
 }
        public override string GenerateSetupScript()
        {
            NormalizeAllUsers();
            PlatformDatabaseConfiguration conf = (PlatformDatabaseConfiguration)uiConfiguration;

            //for P10 the setup script is going to be generated by the conf tool to avoid duplication
            string setupScript = ReplaceTokens(ReadScriptFile(StreamForSetupScriptFile));

            return(setupScript);
        }
        /// <summary>
        /// Replaces known tokens in the given statement
        /// </summary>
        /// <param name="statement"></param>
        /// <returns></returns>
        private string ReplaceTokens(string statement)
        {
            PlatformDatabaseConfiguration conf = (PlatformDatabaseConfiguration)uiConfiguration;
            const string TAG_LOGUSERNAME       = "******";
            const string TAG_LOGPASSWORD       = "******";

            var tokenMap = new Dictionary <string, string>()
            {
                { TAG_LOGUSERNAME, conf.LogUser },
                { TAG_LOGPASSWORD, conf.LogPassword },
            };

            return(ConfigurationManagerUtils.ReplaceTokens(conf, statement, tokenMap));
        }
        public override string ProcessStatement(string statement)
        {
            PlatformDatabaseConfiguration config = (PlatformDatabaseConfiguration)uiConfiguration;

            statement = statement.Trim();

            if (config.Unicode)
            {
                statement = _varcharRe.Replace(statement, "$1nvarchar$2$3");
                statement = _clobRe.Replace(statement, "$1nclob$2");
                statement = _textRe.Replace(statement, "$1ntext$2");
            }

            return(statement);
        }
        private void GrantPlatformDatabaseUserPermissions(PlatformDatabaseConfiguration dbConfig)
        {
            var configRuntime = dbConfig.ElevatedRuntimeDatabaseConfiguration();
            var configMaster  = ConfigurationManagerUtils.ConfigurationToMaster(dbConfig);
            var authType      = dbConfig.AuthenticationMode;

            // Create User

            if (ConfigurationManagerUtils.NeedsCreate(configMaster, configRuntime, dbConfig.AdminUser))
            {
                if (authType == AuthenticationType.Windows_Authentication)
                {
                    ConfigurationManagerUtils.AddIntegratedAuthLogin(configRuntime, dbConfig.AdminUser);
                }
                else
                {
                    ConfigurationManagerUtils.AddDBAuthLogin(configMaster, dbConfig.AdminUser, dbConfig.AdminPassword);
                }
            }

            if (ConfigurationManagerUtils.NeedsPermissionsForAdmin(configRuntime, dbConfig.AdminUser))
            {
                ConfigurationManagerUtils.AddAdminPermissions(configRuntime, dbConfig.AdminUser);
            }

            if (ConfigurationManagerUtils.NeedsCreate(configMaster, configRuntime, dbConfig.RuntimeUser))
            {
                if (authType == AuthenticationType.Windows_Authentication)
                {
                    ConfigurationManagerUtils.AddIntegratedAuthLogin(configRuntime, dbConfig.RuntimeUser);
                }
                else
                {
                    ConfigurationManagerUtils.AddDBAuthLogin(configMaster, dbConfig.RuntimeUser, dbConfig.RuntimePassword);
                }
            }

            if (ConfigurationManagerUtils.NeedsPermissionsForReadWrite(configRuntime, dbConfig.RuntimeUser, dbConfig.AuthenticationMode))
            {
                ConfigurationManagerUtils.AddReadWritePermissions(configRuntime, dbConfig.RuntimeUser);
            }

            try {
                ConfigurationManagerUtils.AddRuntimePermissionsAfterUpgradeScript(configRuntime, dbConfig.RuntimeUser);
            } catch { }

            GrantPlatformPermissions(dbConfig);
        }
        public override string GenerateSetupScript()
        {
            NormalizeAllUsers();
            PlatformDatabaseConfiguration conf = (PlatformDatabaseConfiguration)uiConfiguration;

            //for P10 the setup script is going to be generated by the conf tool to avoid duplication
            StringBuilder sb = new StringBuilder(ReadScriptFile(StreamForSetupScriptFile));

            sb.Replace(TAG_CATALOG, conf.Catalog);
            sb.Replace(TAG_ADMINUSERNAME, conf.AdminUser);
            sb.Replace(TAG_ADMINPASSWORD, conf.AdminPassword);
            sb.Replace(TAG_RUNTIMEUSERNAME, conf.RuntimeUser);
            sb.Replace(TAG_RUNTIMEPASSWORD, conf.RuntimePassword);
            sb.Replace(TAG_LOGUSERNAME, conf.LogUser);
            sb.Replace(TAG_LOGPASSWORD, conf.LogPassword);
            sb.Replace(TAG_AUTH, conf.AuthenticationMode == AuthenticationType.Windows_Authentication ? "windows" : "sql");

            return(sb.ToString());
        }