{
string applicationName;
+ bool schemaIsOk = false;
ConnectionStringSettings connectionString;
DbProviderFactory factory;
DbConnection CreateConnection ()
{
+ if (!schemaIsOk && !(schemaIsOk = AspNetDBSchemaChecker.CheckMembershipSchemaVersion (factory, connectionString.ConnectionString, "role manager", "1")))
+ throw new ProviderException ("Incorrect ASP.NET DB Schema Version.");
+
DbConnection connection = factory.CreateConnection ();
connection.ConnectionString = connectionString.ConnectionString;
return dbp;
}
+ static DbParameter AddParameter (DbCommand command, string parameterName, ParameterDirection direction, DbType type, object parameterValue)
+ {
+ DbParameter dbp = command.CreateParameter ();
+ dbp.ParameterName = parameterName;
+ dbp.Value = parameterValue;
+ dbp.Direction = direction;
+ dbp.DbType = type;
+ command.Parameters.Add (dbp);
+ return dbp;
+ }
+
public override void AddUsersToRoles (string [] usernames, string [] rolenames)
{
Hashtable h = new Hashtable ();
throw new ArgumentNullException ("null element in usernames array");
if (h.ContainsKey (u))
throw new ArgumentException ("duplicate element in usernames array");
- if (u.Length == 0 || u.Length > 256 || u.IndexOf (",") != -1)
+ if (u.Length == 0 || u.Length > 256 || u.IndexOf (',') != -1)
throw new ArgumentException ("element in usernames array in illegal format");
h.Add (u, u);
}
throw new ArgumentNullException ("null element in rolenames array");
if (h.ContainsKey (r))
throw new ArgumentException ("duplicate element in rolenames array");
- if (r.Length == 0 || r.Length > 256 || r.IndexOf (",") != -1)
+ if (r.Length == 0 || r.Length > 256 || r.IndexOf (',') != -1)
throw new ArgumentException ("element in rolenames array in illegal format");
h.Add (r, r);
}
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
- AddParameter (command, "RoleNames", String.Join (",", rolenames));
- AddParameter (command, "UserNames", String.Join (",", usernames));
- AddParameter (command, "ApplicationName", ApplicationName);
- AddParameter (command, "CurrentTimeUtc", DateTime.UtcNow);
- DbParameter dbpr = AddParameter (command, null, ParameterDirection.ReturnValue, null);
+ AddParameter (command, "@RoleNames", String.Join (",", rolenames));
+ AddParameter (command, "@UserNames", String.Join (",", usernames));
+ AddParameter (command, "@ApplicationName", ApplicationName);
+ AddParameter (command, "@CurrentTimeUtc", DateTime.UtcNow);
+ DbParameter dbpr = AddParameter (command, "@ReturnVal", ParameterDirection.ReturnValue, DbType.Int32, null);
command.ExecuteNonQuery ();
if (rolename == null)
throw new ArgumentNullException ("rolename");
- if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (",") != -1)
+ if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (',') != -1)
throw new ArgumentException ("rolename is in invalid format");
using (DbConnection connection = CreateConnection ()) {
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
- AddParameter (command, "ApplicationName", ApplicationName);
- AddParameter (command, "RoleName", rolename);
- DbParameter dbpr = AddParameter (command, null, ParameterDirection.ReturnValue, null);
+ AddParameter (command, "@ApplicationName", ApplicationName);
+ AddParameter (command, "@RoleName", rolename);
+ DbParameter dbpr = AddParameter (command, "@ReturnVal", ParameterDirection.ReturnValue, DbType.Int32, null);
command.ExecuteNonQuery ();
int returnValue = (int) dbpr.Value;
if (rolename == null)
throw new ArgumentNullException ("rolename");
- if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (",") != -1)
+ if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (',') != -1)
throw new ArgumentException ("rolename is in invalid format");
using (DbConnection connection = CreateConnection ()) {
command.CommandText = @"dbo.aspnet_Roles_DeleteRole";
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
- AddParameter (command, "ApplicationName", ApplicationName);
- AddParameter (command, "RoleName", rolename);
- AddParameter (command, "DeleteOnlyIfRoleIsEmpty", throwOnPopulatedRole);
- DbParameter dbpr = AddParameter (command, null, ParameterDirection.ReturnValue, null);
+ AddParameter (command, "@ApplicationName", ApplicationName);
+ AddParameter (command, "@RoleName", rolename);
+ AddParameter (command, "@DeleteOnlyIfRoleIsEmpty", throwOnPopulatedRole);
+ DbParameter dbpr = AddParameter (command, "@ReturnVal", ParameterDirection.ReturnValue, DbType.Int32, null);
command.ExecuteNonQuery ();
int returnValue = (int)dbpr.Value;
if (returnValue == 0)
return true;
if (returnValue == 1)
- return false; //role does not exists
+ return false; //role does not exist
else if (returnValue == 2 && throwOnPopulatedRole)
throw new ProviderException (rolename + " is not empty");
else
throw new ArgumentNullException ("roleName");
if (usernameToMatch == null)
throw new ArgumentNullException ("usernameToMatch");
- if (roleName.Length == 0 || roleName.Length > 256 || roleName.IndexOf (",") != -1)
+ if (roleName.Length == 0 || roleName.Length > 256 || roleName.IndexOf (',') != -1)
throw new ArgumentException ("roleName is in invalid format");
if (usernameToMatch.Length == 0 || usernameToMatch.Length > 256)
throw new ArgumentException ("usernameToMatch is in invalid format");
command.CommandText = @"dbo.aspnet_UsersInRoles_FindUsersInRole";
command.CommandType = CommandType.StoredProcedure;
- AddParameter (command, "ApplicationName", ApplicationName);
- AddParameter (command, "RoleName", roleName);
- AddParameter (command, "UsernameToMatch", usernameToMatch);
+ AddParameter (command, "@ApplicationName", ApplicationName);
+ AddParameter (command, "@RoleName", roleName);
+ AddParameter (command, "@UsernameToMatch", usernameToMatch);
DbDataReader reader = command.ExecuteReader ();
ArrayList userList = new ArrayList ();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
- AddParameter (command, "ApplicationName", ApplicationName);
+ AddParameter (command, "@ApplicationName", ApplicationName);
DbDataReader reader = command.ExecuteReader ();
ArrayList roleList = new ArrayList ();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
- AddParameter (command, "UserName", username);
- AddParameter (command, "ApplicationName", ApplicationName);
+ AddParameter (command, "@UserName", username);
+ AddParameter (command, "@ApplicationName", ApplicationName);
DbDataReader reader = command.ExecuteReader ();
ArrayList roleList = new ArrayList ();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
- AddParameter (command, "RoleName", rolename);
- AddParameter (command, "ApplicationName", ApplicationName);
+ AddParameter (command, "@RoleName", rolename);
+ AddParameter (command, "@ApplicationName", ApplicationName);
DbDataReader reader = command.ExecuteReader ();
ArrayList userList = new ArrayList ();
return rv;
}
- [MonoTODO]
public override void Initialize (string name, NameValueCollection config)
{
if (config == null)
base.Initialize (name, config);
- applicationName = config ["applicationName"];
+ applicationName = GetStringConfigValue (config, "applicationName", "/");
string connectionStringName = config ["connectionStringName"];
if (applicationName.Length > 256)
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
- AddParameter (command, "RoleName", rolename);
- AddParameter (command, "UserName", username);
- AddParameter (command, "ApplicationName", ApplicationName);
- DbParameter dbpr = AddParameter (command, null, ParameterDirection.ReturnValue, null);
+ AddParameter (command, "@RoleName", rolename);
+ AddParameter (command, "@UserName", username);
+ AddParameter (command, "@ApplicationName", ApplicationName);
+ DbParameter dbpr = AddParameter (command, "@ReturnVal", ParameterDirection.ReturnValue, DbType.Int32, null);
command.ExecuteNonQuery ();
int returnValue = (int) dbpr.Value;
throw new ArgumentNullException ("null element in usernames array");
if (h.ContainsKey (u))
throw new ArgumentException ("duplicate element in usernames array");
- if (u.Length == 0 || u.Length > 256 || u.IndexOf (",") != -1)
+ if (u.Length == 0 || u.Length > 256 || u.IndexOf (',') != -1)
throw new ArgumentException ("element in usernames array in illegal format");
h.Add (u, u);
}
throw new ArgumentNullException ("null element in rolenames array");
if (h.ContainsKey (r))
throw new ArgumentException ("duplicate element in rolenames array");
- if (r.Length == 0 || r.Length > 256 || r.IndexOf (",") != -1)
+ if (r.Length == 0 || r.Length > 256 || r.IndexOf (',') != -1)
throw new ArgumentException ("element in rolenames array in illegal format");
h.Add (r, r);
}
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
- AddParameter (command, "UserNames", String.Join (",", usernames));
- AddParameter (command, "RoleNames", String.Join (",", rolenames));
- AddParameter (command, "ApplicationName", ApplicationName);
- DbParameter dbpr = AddParameter (command, null, ParameterDirection.ReturnValue, null);
+ AddParameter (command, "@UserNames", String.Join (",", usernames));
+ AddParameter (command, "@RoleNames", String.Join (",", rolenames));
+ AddParameter (command, "@ApplicationName", ApplicationName);
+ DbParameter dbpr = AddParameter (command, "@ReturnVal", ParameterDirection.ReturnValue, DbType.Int32, null);
command.ExecuteNonQuery ();
int returnValue = (int) dbpr.Value;
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
- AddParameter (command, "ApplicationName", ApplicationName);
- AddParameter (command, "RoleName", rolename);
- DbParameter dbpr = AddParameter (command, null, ParameterDirection.ReturnValue, null);
+ AddParameter (command, "@ApplicationName", ApplicationName);
+ AddParameter (command, "@RoleName", rolename);
+ DbParameter dbpr = AddParameter (command, "@ReturnVal", ParameterDirection.ReturnValue, DbType.Int32, null);
command.ExecuteNonQuery ();
int returnValue = (int) dbpr.Value;
}
}
- [MonoTODO]
public override string ApplicationName
{
get { return applicationName; }