using System.Configuration;
using System.Reflection;
using System;
namespace Yavsc.Model.RolesAndMembers
{
///
/// User manager.
///
public static class UserManager
{
///
/// Changes the name.
///
/// Old name.
/// New name.
public static void ChangeName (string oldName, string newName) {
Provider.ChangeName (oldName, newName);
}
///
/// Determines if is available the specified name.
///
/// true if is available the specified name; otherwise, false.
/// Name.
public static bool IsAvailable(string name)
{
return Provider.IsNameAvailable (name);
}
///
/// The provider.
///
private static ChangeUserNameProvider provider;
///
/// Gets the provider.
///
/// The provider.
public static ChangeUserNameProvider Provider {
get {
if (provider == null)
provider = GetProvider ();
if (provider == null)
throw new ConfigurationErrorsException ("No username section defined");
return provider;
}
}
private static ChangeUserNameProvider GetProvider ()
{
DataProviderConfigurationSection config = ConfigurationManager.GetSection ("system.web/userNameManager") as DataProviderConfigurationSection;
if (config == null)
throw new ConfigurationErrorsException("The configuration bloc for the username provider was not found");
ProviderSettings celt=null;
if (config.DefaultProvider!=null)
celt = config.Providers[config.DefaultProvider];
if ((celt == null) && config.Providers!=null)
if (config.Providers.Count>0)
celt = config.Providers [0];
if (celt == null)
throw new ConfigurationErrorsException("The default username provider was not found");
ConstructorInfo ci = Type.GetType (celt.Type).GetConstructor (Type.EmptyTypes);
provider = ci.Invoke (Type.EmptyTypes) as ChangeUserNameProvider;
provider.Initialize (celt.Name, celt.Parameters);
return provider;
}
}
}