public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) { base.Initialize(name, config); if (config == null) { throw new ArgumentException(Resources.SiteMapConnectionStringMissing); } string connStrName; if (string.IsNullOrEmpty(connStrName = config["connectionStringName"])) { throw new ArgumentException(Resources.SiteMapConnectionStringMissing); } _connStr = ConfigurationManager.ConnectionStrings[connStrName].ConnectionString; writeExceptionsToEventLog = false; if (config["writeExceptionsToEventLog"] != null) { writeExceptionsToEventLog = (config["writeExceptionsToEventLog"].ToUpper() == "TRUE"); } SchemaManager.CheckSchema(_connStr, config); }
/// <summary> /// Initializes the provider. /// </summary> /// <param name="name">The friendly name of the provider.</param> /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param> /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception> /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception> /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"/> on a provider after the provider has already been initialized.</exception> public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } if (name == null || name.Length == 0) { name = "MySQLRoleProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "MySQL Role provider"); } base.Initialize(name, config); string applicationName = HostingEnvironment.ApplicationVirtualPath; if (!String.IsNullOrEmpty(config["applicationName"])) { applicationName = config["applicationName"]; } if (!(config["writeExceptionsToEventLog"] == null)) { if (config["writeExceptionsToEventLog"].ToUpper() == "TRUE") { pWriteExceptionsToEventLog = true; } } pConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]]; if (pConnectionStringSettings != null) { connectionString = pConnectionStringSettings.ConnectionString.Trim(); } else { connectionString = ""; } if (String.IsNullOrEmpty(connectionString)) { return; } // make sure our schema is up to date SchemaManager.CheckSchema(connectionString, config); app = new Application(applicationName, Description); }
/// <summary> /// Initializes the provider. /// </summary> /// <param name="name">The friendly name of the provider.</param> /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param> /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception> /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception> /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"/> on a provider after the provider has already been initialized.</exception> public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } if (name == null || name.Length == 0) { name = "MySQLProfileProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "MySQL Profile provider"); } base.Initialize(name, config); try { string applicationName = GetConfigValue(config["applicationName"], HostingEnvironment.ApplicationVirtualPath); dateTimeUseUtc = Convert.ToBoolean(GetConfigValue(config["dateTimeUseUtc"], "False")); connectionString = ""; ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[ config["connectionStringName"]]; if (ConnectionStringSettings != null) { connectionString = ConnectionStringSettings.ConnectionString.Trim(); } if (String.IsNullOrEmpty(connectionString)) { return; } // make sure our schema is up to date SchemaManager.CheckSchema(connectionString, config); app = new Application(applicationName, base.Description); } catch (Exception ex) { throw new ProviderException(Resources.ErrorInitProfileProvider, ex); } }
/// <summary> /// Initializes the provider. /// </summary> /// <param name="name">The friendly name of the provider.</param> /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param> /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception> /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception> /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"/> on a provider after the provider has already been initialized.</exception> public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } if (name == null || name.Length == 0) { name = "MySQLProfileProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "MySQL Profile provider"); } base.Initialize(name, config); try { string applicationName = GetConfigValue(config["applicationName"], HostingEnvironment.ApplicationVirtualPath); connectionString = ConfigUtility.GetConnectionString(config); if (String.IsNullOrEmpty(connectionString)) { return; } // make sure our schema is up to date SchemaManager.CheckSchema(connectionString, config); app = new Application(applicationName, base.Description); } catch (Exception ex) { throw new ProviderException(Properties.Resources.ErrorInitProfileProvider, ex); } }
/// <summary> /// Initializes the provider. /// </summary> /// <param name="name">The friendly name of the provider.</param> /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param> /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception> /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception> /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"/> on a provider after the provider has already been initialized.</exception> public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } if (name == null || name.Length == 0) { name = "MySQLRoleProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "MySQL Role provider"); } base.Initialize(name, config); if (config["applicationName"] == null || config["applicationName"].Trim() == "") { applicationName = HostingEnvironment.ApplicationVirtualPath; } else { applicationName = config["applicationName"]; } if (!(config["writeExceptionsToEventLog"] == null)) { if (config["writeExceptionsToEventLog"].ToUpper() == "TRUE") { pWriteExceptionsToEventLog = true; } } pConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]]; if (pConnectionStringSettings != null) { connectionString = pConnectionStringSettings.ConnectionString.Trim(); } else { connectionString = ""; } if (String.IsNullOrEmpty(connectionString)) { return; } // make sure our schema is up to date SchemaManager.CheckSchema(connectionString, config); try { // now pre-cache the applicationId using (MySqlConnection conn = new MySqlConnection(connectionString)) { conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT id FROM my_aspnet_Applications WHERE name=@name", conn); cmd.Parameters.AddWithValue("@name", applicationName); object appId = cmd.ExecuteScalar(); if (appId != null) { applicationId = Convert.ToInt32(appId); } } } catch (Exception ex) { throw new ProviderException(Resources.ErrorInitOfRoleProvider, ex); } }
/// <summary> /// Initializes the provider with the property values specified in the ASP.NET application configuration file /// </summary> /// <param name="name">The name of the provider instance to initialize.</param> /// <param name="config">Object that contains the names and values of configuration options for the provider. /// </param> public override void Initialize(string name, NameValueCollection config) { //Initialize values from web.config. if (config == null) { throw new ArgumentException("config"); } if (name == null || name.Length == 0) { throw new ArgumentException("name"); } if (String.IsNullOrEmpty(config["description"])) { config.Remove("description"); config["description"] = "MySQL Session State Store Provider"; } base.Initialize(name, config); string applicationName = HostingEnvironment.ApplicationVirtualPath; if (!String.IsNullOrEmpty(config["applicationName"])) { applicationName = config["applicationName"]; } // Get <sessionState> configuration element. Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath); sessionStateConfig = (SessionStateSection)webConfig.SectionGroups["system.web"].Sections["sessionState"]; // Initialize connection. connectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]]; if (connectionStringSettings == null || connectionStringSettings.ConnectionString.Trim() == "") { throw new HttpException("Connection string can not be blank"); } connectionString = connectionStringSettings.ConnectionString; writeExceptionsToEventLog = false; if (config["writeExceptionsToEventLog"] != null) { writeExceptionsToEventLog = (config["writeExceptionsToEventLog"].ToUpper() == "TRUE"); } // Make sure we have the correct schema. SchemaManager.CheckSchema(connectionString, config); app = new Application(applicationName, base.Description); // Get the application id. try { using (MySqlConnection conn = new MySqlConnection(connectionString)) { conn.Open(); app.EnsureId(conn); CheckStorageEngine(conn); cleanupInterval = GetCleanupInterval(conn); } } catch (MySqlException e) { HandleMySqlException(e, "Initialize"); } // Setup the cleanup timer if (cleanupInterval <= 0) { cleanupInterval = 1; } cleanupTimer = new Timer(new TimerCallback(CleanupOldSessions), null, 0, cleanupInterval * 1000 * 60); }
/// <summary> /// Initializes the provider with the property values specified in the ASP .NET application configuration file. /// </summary> /// <param name="name">The name of the provider instance to initialize.</param> /// <param name="config">Object that contains the names and values of configuration options for the provider. /// </param> public override void Initialize(string name, NameValueCollection config) { //Initialize values from web.config. if (config == null) { throw new ArgumentException("config"); } if (name == null || name.Length == 0) { throw new ArgumentException("name"); } if (String.IsNullOrEmpty(config["description"])) { config.Remove("description"); config["description"] = "MySQL Session State Store Provider"; } base.Initialize(name, config); string applicationName = HostingEnvironment.ApplicationVirtualPath; if (!String.IsNullOrEmpty(config["applicationName"])) { applicationName = config["applicationName"]; } // Get <sessionState> configuration element. Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath); sessionStateConfig = (SessionStateSection)webConfig.SectionGroups["system.web"].Sections["sessionState"]; // Initialize connection. connectionString = ConfigUtility.GetConnectionString(config); if (string.IsNullOrEmpty(connectionString)) { return; } writeExceptionsToEventLog = false; if (config["writeExceptionsToEventLog"] != null) { writeExceptionsToEventLog = (config["writeExceptionsToEventLog"].ToUpper() == "TRUE"); } enableExpireCallback = false; if (config["enableExpireCallback"] != null) { enableExpireCallback = (config["enableExpireCallback"].ToUpper() == "TRUE"); } // Make sure we have the correct schema. SchemaManager.CheckSchema(connectionString, config); app = new Application(applicationName, base.Description); // Get the application id. try { using (MySqlConnection conn = new MySqlConnection(connectionString)) { conn.Open(); app.EnsureId(conn); CheckStorageEngine(conn); } } catch (MySqlException e) { HandleMySqlException(e, "Initialize"); } try { using (MySqlConnection conn = new MySqlConnection(connectionString)) { MySqlCommand cmd = new MySqlCommand( "INSERT IGNORE INTO my_aspnet_sessioncleanup SET" + " ApplicationId = @ApplicationId, " + " LastRun = NOW(), " + " IntervalMinutes = 10", conn); cmd.Parameters.AddWithValue("@ApplicationId", ApplicationId); conn.Open(); cmd.ExecuteNonQuery(); cleanupInterval = GetCleanupInterval(conn, ApplicationId); } } catch (MySqlException e) { HandleMySqlException(e, "Initialize"); } // Setup the cleanup timer if (cleanupInterval <= 0) { cleanupInterval = 1; } cleanupTimer = new Timer(new TimerCallback(CleanupOldSessions), null, 0, cleanupInterval * 1000 * 60); }
/// <summary> /// Initializes settings values for Personalization Provider. /// </summary> /// <param name="name">The name of the provider.</param> /// <param name="config">A named value collection representing the configurations for this provider.</param> public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } if (string.IsNullOrEmpty(name)) { name = "MySqlPersonalizationProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "MySql Personalization provider"); } base.Initialize(name, config); string applicationName = HostingEnvironment.ApplicationVirtualPath; if (!String.IsNullOrEmpty(config["applicationName"])) { applicationName = config["applicationName"]; } if (!(config["writeExceptionsToEventLog"] == null)) { if (config["writeExceptionsToEventLog"].ToUpper() == "TRUE") { writeExceptionsToEventLog = true; } } connectionString = ConfigUtility.GetConnectionString(config); if (String.IsNullOrEmpty(connectionString)) { return; } // Make sure we have the correct schema. SchemaManager.CheckSchema(connectionString, config); app = new Application(applicationName, base.Description); // Get the application id. try { using (MySqlConnection conn = new MySqlConnection(connectionString)) { conn.Open(); app.EnsureId(conn); } } catch (Exception ex) { if (writeExceptionsToEventLog) { WriteToEventLog(ex, "MySQLPersonalizationProvider - Initialize"); } throw; } }