Merge pull request #900 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / Mainsoft.Web / Mainsoft.Web.Security / DerbyRoleProvider.cs
index c2ae24eff2f856d3fe152eb885f9baca3da7faa8..cdce377b281f9f2cba730b786d5e6a9ae36eb961 100644 (file)
@@ -42,14 +42,26 @@ using System.Web.Security;
 \r
 namespace Mainsoft.Web.Security\r
 {\r
-\r
+       /// <summary>\r
+       /// <para>This class supports the Framework infrastructure and is not intended to be used directly from your code.</para>\r
+       /// <para>Manages storage of role membership information for an ASP.NET application in a Derby database.</para>\r
+       /// </summary>\r
        public class DerbyRoleProvider : RoleProvider\r
        {\r
                ConnectionStringSettings connectionString;\r
                string applicationName;\r
+               bool schemaChecked = false;\r
+               DerbyUnloadManager.DerbyShutDownPolicy shutDownPolicy = DerbyUnloadManager.DerbyShutDownPolicy.Default;\r
 \r
                DbConnection CreateConnection ()\r
                {\r
+                       if (!schemaChecked) {\r
+                               DerbyDBSchema.CheckSchema (connectionString.ConnectionString);\r
+                               schemaChecked = true;\r
+\r
+                               DerbyUnloadManager.RegisterUnloadHandler (connectionString.ConnectionString, shutDownPolicy);\r
+                       }\r
+\r
                        OleDbConnection connection = new OleDbConnection (connectionString.ConnectionString);\r
                        connection.Open ();\r
                        return connection;\r
@@ -126,7 +138,7 @@ namespace Mainsoft.Web.Security
                                if (returnValue == 0)\r
                                        return true;\r
                                if (returnValue == 2)\r
-                                       return false; //role does not exists\r
+                                       return false; //role does not exist\r
                                else if (returnValue == 3 && throwOnPopulatedRole)\r
                                        throw new ProviderException (rolename + " is not empty");\r
                                else\r
@@ -151,7 +163,7 @@ namespace Mainsoft.Web.Security
                                int returnValue = DerbyRolesHelper.UsersInRoles_FindUsersInRole (connection, applicationName, roleName, usernameToMatch, out reader);\r
 \r
                                if (returnValue == 2)\r
-                                       throw new ProviderException ("roleName was not found in the database");\r
+                                       throw new ProviderException ("The role '" + roleName + "' was not found.");\r
 \r
                                using (reader) {\r
                                        if (reader == null)\r
@@ -222,7 +234,7 @@ namespace Mainsoft.Web.Security
                                int returnValue = DerbyRolesHelper.UsersInRoles_GetUsersInRoles (connection, applicationName, rolename, out reader);\r
 \r
                                if (returnValue == 2)\r
-                                       throw new ProviderException ("rolename was not found in the database");\r
+                                       throw new ProviderException ("The role '" + rolename + "' was not found.");\r
 \r
                                using (reader) {\r
                                        if (reader == null)\r
@@ -265,7 +277,9 @@ namespace Mainsoft.Web.Security
                        if (connectionString == null)\r
                                throw new ProviderException (String.Format("The connection name '{0}' was not found in the applications configuration or the connection string is empty.", connectionStringName));\r
 \r
-                       DerbyDBSchema.InitializeSchema (connectionString.ConnectionString);\r
+                       string shutdown = config ["shutdown"];\r
+                       if (!String.IsNullOrEmpty (shutdown))\r
+                               shutDownPolicy = (DerbyUnloadManager.DerbyShutDownPolicy) Enum.Parse (typeof (DerbyUnloadManager.DerbyShutDownPolicy), shutdown, true);\r
                }\r
 \r
                public override bool IsUserInRole (string username, string rolename)\r