Exemple #1
0
        /// <summary>
        /// 全局初始化
        /// </summary>
        public static void Initialize()
        {
            // 设置连接字符串
            string source = AppConfig.GetAppSetting("ConnectionSource");

            if (string.IsNullOrEmpty(source))
            {
                throw new PoseidonException(ErrorCode.DatabaseConnectionNotFound);
            }

            string connection = "";

            if (source == "dbconfig")
            {
                string name = AppConfig.GetAppSetting("DbConnection");
                connection = ConfigUtility.GetConnectionString(name);
            }
            else if (source == "appconfig")
            {
                connection = AppConfig.GetConnectionString();
            }

            if (string.IsNullOrEmpty(connection))
            {
                throw new PoseidonException(ErrorCode.DatabaseConnectionNotFound);
            }

            Cache.Instance.Add("ConnectionString", connection);

            // 设置数据库访问类型
            string dalPrefix = AppConfig.GetAppSetting("DALPrefix");

            Cache.Instance.Add("DALPrefix", dalPrefix);
        }
Exemple #2
0
        /// <summary>
        /// 全局初始化
        /// </summary>
        public static void Initialize()
        {
            try
            {
                // 设置连接字符串
                string source = AppConfig.GetAppSetting("ConnectionSource");
                if (string.IsNullOrEmpty(source))
                {
                    Logger.Instance.Error("连接源未确定");
                    throw new PoseidonException(ErrorCode.DatabaseConnectionNotFound);
                }

                string connection = "";
                if (source == "dbconfig")
                {
                    string name = AppConfig.GetAppSetting("DbConnection");
                    connection = ConfigUtility.GetConnectionString(name);
                }
                else if (source == "appconfig")
                {
                    connection = AppConfig.GetConnectionString();
                }

                if (string.IsNullOrEmpty(connection))
                {
                    Logger.Instance.Error("连接字符串未找到");
                    throw new PoseidonException(ErrorCode.DatabaseConnectionNotFound);
                }

                Cache.Instance.Add("ConnectionString", connection);
                Logger.Instance.Debug("连接字符串已设置");

                // 设置数据库类型
                string dalPrefix = AppConfig.GetAppSetting("DALPrefix");
                Cache.Instance.Add("DALPrefix", dalPrefix);
                Logger.Instance.Debug("数据库类型已设置");

                // 设置服务访问类型
                string callerType = AppConfig.GetAppSetting("CallerType");
                Cache.Instance.Add("CallerType", callerType);
                Logger.Instance.Debug("服务访问类型已设置");

                // 设置远程API地址
                string apiHost = AppConfig.GetAppSetting("ApiHost");
                Cache.Instance.Add("ApiHost", apiHost);
                Logger.Instance.Debug("API主机已设置");
            }
            catch (Exception e)
            {
                Logger.Instance.Exception("初始化失败", e);
                throw new PoseidonException(ErrorCode.Error);
            }
        }
Exemple #3
0
        /// <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;
                }
            }

            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, Description);
        }
Exemple #4
0
        /// <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);
            }
        }
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            base.Initialize(name, config);

            if (config == null)
            {
                throw new ArgumentException(Resources.SiteMapConnectionStringMissing);
            }

            _connStr = ConfigUtility.GetConnectionString(config);
            if (string.IsNullOrEmpty(_connStr))
            {
                throw new ArgumentException(Resources.SiteMapConnectionStringMissing);
            }

            writeExceptionsToEventLog = false;
            if (config["writeExceptionsToEventLog"] != null)
            {
                writeExceptionsToEventLog = (config["writeExceptionsToEventLog"].ToUpper() == "TRUE");
            }

            SchemaManager.CheckSchema(_connStr, config);
        }
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (string.IsNullOrEmpty(name))
            {
                name = "MySqlExtendedMembershipProvider";
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", string.Format("MySql Default {0} Description", name));
            }

            base.Initialize(name, config);

            var appName = GetConfigValue(config["applicationName"], HostingEnvironment.SiteName);

            _maxPwdAttempts               = Int32.Parse(GetConfigValue(config["maxInvalidPasswordAttempts"], "5"));
            _pwdAttemptWindow             = Int32.Parse(GetConfigValue(config["passwordAttemptWindow"], "10"));
            _minReqNonAlphanumericalChars = Int32.Parse(GetConfigValue(config["minRequiredNonalphanumericCharacters"], "1"));
            _minReqPwdLength              = Int32.Parse(GetConfigValue(config["minRequiredPasswordLength"], "7"));
            _pwdStrenghtRegex             = GetConfigValue(config["passwordStrengthRegularExpression"], "");
            _enablePwdReset               = bool.Parse(GetConfigValue(config["enablePasswordReset"], "True"));
            _enablePwdRetrival            = bool.Parse(GetConfigValue(config["enablePasswordRetrieval"], "False"));
            _reqQuestionAnswer            = bool.Parse(GetConfigValue(config["requiresQuestionAndAnswer"], "False"));
            _reqUniqueEmail               = bool.Parse(GetConfigValue(config["requiresUniqueEmail"], "True"));

            var pwdFormat = !string.IsNullOrEmpty(config["passwordFormat"]) ? config["passwordFormat"].ToString().ToLowerInvariant() : "hashed";

            switch (pwdFormat)
            {
            case "hashed":
                _pwdFormat = MembershipPasswordFormat.Hashed;
                break;

            case "encrypted":
                _pwdFormat = MembershipPasswordFormat.Encrypted;
                break;

            case "clear":
                _pwdFormat = MembershipPasswordFormat.Clear;
                break;

            default:
                throw new ProviderException(Resources.PasswordFormatNotSupported);
            }

            if (_pwdFormat == MembershipPasswordFormat.Hashed)
            {
                if (_enablePwdRetrival)
                {
                    throw new ProviderException(Resources.CannotRetrieveHashedPasswords);
                }
            }

            _app             = new Application(appName, base.Description);
            ConnectionString = ConfigUtility.GetConnectionString(config);
            if (string.IsNullOrEmpty(ConnectionString))
            {
                return;
            }

            UserTableName       = GetConfigValue(config["userTableName"], "");
            UserIdColumn        = GetConfigValue(config["userIdColumn"], "");
            UserNameColumn      = GetConfigValue(config["userNameColumn"], "");
            _autoGenerateTables = bool.Parse(GetConfigValue(config["autoGenerateTables"], "True"));
            if (_autoGenerateTables)
            {
                CreateTables();
            }

            Initialized = true;
        }
        /// <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);
        }
Exemple #8
0
        /// <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;
            }
        }