Rebel.Framework.Persistence.NHibernate.ProviderBootstrapper.ValidateSchema C# (CSharp) Méthode

ValidateSchema() public méthode

public ValidateSchema ( global configuration ) : bool
configuration global
Résultat bool
        public bool ValidateSchema(global::NHibernate.Cfg.Configuration configuration)
        {
            using (new WriteLockDisposable(SchemaValidationLocker))
            {
                var myvalidator = new SchemaValidator(configuration);
                try
                {
                    myvalidator.Validate();
                    return true;
                }
                catch (HibernateException ex)
                {
                    /* SchemaValidator.Validate() returns void - FFS */
                    LogHelper.Error<ProviderBootstrapper>("While running SchemaValidator: " + ex.Message, ex);

                    // New in 5.2 (limited support for schema upgrades - pending full migration support)
                    // Use our own validator to actually get back metadata about the missing tables rather than
                    // just an exception of the first failure
                    // Then if it's something we're OK to try to handle, try to handle it...
                    if (_localConfig.AutoUpdateDbSchema)
                    {
                        var customValidator = new SchemaChangeValidator(configuration);
                        var result = customValidator.Validate();
                        if (!result.IsValid)
                        {
                            // 5.2: Just check for whether AggregateNodeStatus is the only missing one
                            if (result.MissingTables.Any())
                            {
                                var missingTables = string.Join(", ", result.MissingTables.Select(x => x.Name));
                                LogHelper.Warn<ProviderBootstrapper>("The following tables are missing from the database: {0}", missingTables);

                                var agg = result.MissingTables.FirstOrDefault(x => x.Name == typeof(AggregateNodeStatus).Name);
                                if (agg != null && result.MissingTables.Count == 1)
                                {
                                    // It's the only missing table, so we've already done one install
                                    LogHelper.Warn<ProviderBootstrapper>("Automatically attempting to update the database schema to add the following missing tables: {0}. You can prevent this behaviour by setting '{1}' to false in the configuration for this provider", missingTables, ProviderConfigurationSection.XAutoUpdateSchema);
                                    try
                                    {
                                        UpdateSchema(configuration);
                                        // Everything went OK, so can return true since we're now "valid"
                                        return true;
                                    }
                                    catch (Exception updateEx)
                                    {
                                        LogHelper.Error<ProviderBootstrapper>("Auto-update of db schema failed. Does the db user have the correct permissions? If you need to manually run the update script, the script should be in the logfile preceding this entry", updateEx);
                                    }
                                }
                            }
                        }
                    }
                    return false;
                }
            }
        }