Validate() public method

public Validate ( ) : bool
return bool
Ejemplo n.º 1
0
        /// <summary>
        /// Create the Membership database and set the roles and users.
        /// </summary>
        /// <param name="config"></param>
        private static void CreateMembership(InstallerConfig config)
        {
            if (config.Membership.Create)
            {
                // Let's first verify that the RoleManager is enabled.
                if (!Roles.Enabled)
                {
                    throw new ApplicationException("The RoleManager was not Enabled. It has been updated! Click &quot;Install&quot; to continue.");
                }

                // Added: 5/19/2011 By King Wilder
                // Needed a way to validate rules based on the Membership section
                // in the web.config, such as minRequiredPasswordLength.  This
                // factory class will create rules based on these requirements and
                // validate the InstallerConfig values then display the error
                // messages back to the browser.
                System.Configuration.Configuration configSection = WebConfigurationManager.OpenWebConfiguration("~");
                IRulesValidationFactory            rulesFactory  = new RulesValidationFactory(config, configSection);
                if (!rulesFactory.Validate())
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<p><b>There are some items that need your attention:</b></p>");
                    sb.Append("<ul>");
                    foreach (string error in rulesFactory.ValidationErrors)
                    {
                        sb.AppendFormat("<li>{0}</li>", error);
                    }
                    sb.Append("</ul>");
                    sb.Append("<p>Please fix these issues in the installer.config file and then come back and click the &quot;Install&quot; button.</p>");

                    throw new ApplicationException(sb.ToString());
                }

                // Add the ASPNETDB tables to the database using the SqlServices Install method.
                // This will add the ASPNETDB tables to the same database as the application.
                // NOTE: This method can ONLY be used for SQL Server.  To point to MySql,
                // you will need to create the database scripts for MySql and add them to
                // the RunScripts method, but then you need to have the MySql data provider
                // set in the web.config.
                if (config.Database.UseTrustedConnection)
                {
                    // For SQL Server trusted connections
                    try
                    {
                        System.Web.Management.SqlServices.Uninstall(config.Database.DataSource.Trim(), config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                    }
                    catch (SqlException)
                    {
                    }

                    //DropASPNETDBTables(config);
                    System.Web.Management.SqlServices.Install(config.Database.DataSource.Trim(), config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                }
                else
                {
                    // For SQL Server
                    try
                    {
                        System.Web.Management.SqlServices.Uninstall(config.Database.DataSource.Trim(), config.Database.UserName, config.Database.Password, config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                    }
                    catch (SqlException)
                    {
                    }

                    //DropASPNETDBTables(config);
                    System.Web.Management.SqlServices.Install(config.Database.DataSource.Trim(), config.Database.UserName, config.Database.Password, config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create the Membership database and set the roles and users.
        /// </summary>
        /// <param name="config"></param>
        private static void CreateMembership(InstallerConfig config)
        {
            if (config.Membership.Create)
            {
                // Let's first verify that the RoleManager is enabled.
                if (!Roles.Enabled)
                    throw new ApplicationException("The RoleManager was not Enabled. It has been updated! Click &quot;Install&quot; to continue.");

                // Added: 5/19/2011 By King Wilder
                // Needed a way to validate rules based on the Membership section
                // in the web.config, such as minRequiredPasswordLength.  This
                // factory class will create rules based on these requirements and
                // validate the InstallerConfig values then display the error
                // messages back to the browser.
                System.Configuration.Configuration configSection = WebConfigurationManager.OpenWebConfiguration("~");
                IRulesValidationFactory rulesFactory = new RulesValidationFactory(config, configSection);
                if (!rulesFactory.Validate())
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<p><b>There are some items that need your attention:</b></p>");
                    sb.Append("<ul>");
                    foreach (string error in rulesFactory.ValidationErrors)
                    {
                        sb.AppendFormat("<li>{0}</li>", error);
                    }
                    sb.Append("</ul>");
                    sb.Append("<p>Please fix these issues in the installer.config file and then come back and click the &quot;Install&quot; button.</p>");

                    throw new ApplicationException(sb.ToString());
                }

                // Add the ASPNETDB tables to the database using the SqlServices Install method.
                // This will add the ASPNETDB tables to the same database as the application.
                // NOTE: This method can ONLY be used for SQL Server.  To point to MySql,
                // you will need to create the database scripts for MySql and add them to
                // the RunScripts method, but then you need to have the MySql data provider
                // set in the web.config.
                if (config.Database.UseTrustedConnection)
                {
                    // For SQL Server trusted connections
                    try
                    {
                        System.Web.Management.SqlServices.Uninstall(config.Database.DataSource.Trim(), config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                    }
                    catch (SqlException)
                    {
                    }

                    //DropASPNETDBTables(config);
                    System.Web.Management.SqlServices.Install(config.Database.DataSource.Trim(), config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                }
                else
                {
                    // For SQL Server
                    try
                    {
                        System.Web.Management.SqlServices.Uninstall(config.Database.DataSource.Trim(), config.Database.UserName, config.Database.Password, config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                    }
                    catch (SqlException)
                    {
                    }

                    //DropASPNETDBTables(config);
                    System.Web.Management.SqlServices.Install(config.Database.DataSource.Trim(), config.Database.UserName, config.Database.Password, config.Database.InitialCatalog, System.Web.Management.SqlFeatures.All);
                }

            }
        }