GetDatabaseConnectionString() static private method

Gets the database connection string.
static private GetDatabaseConnectionString ( MongoDbWebSection mongoDbWebSection, NameValueCollection config ) : string
mongoDbWebSection MongoDB.Web.Config.MongoDbWebSection
config System.Collections.Specialized.NameValueCollection The config.
return string
Example #1
0
        public override void Initialize(string name, NameValueCollection config)
        {
            this.ApplicationName                      = config["applicationName"] ?? HostingEnvironment.ApplicationVirtualPath;
            this.enablePasswordReset                  = Boolean.Parse(config["enablePasswordReset"] ?? "true");
            this.enablePasswordRetrieval              = Boolean.Parse(config["enablePasswordRetrieval"] ?? "false");
            this.maxInvalidPasswordAttempts           = Int32.Parse(config["maxInvalidPasswordAttempts"] ?? "5");
            this.minRequiredNonAlphanumericCharacters = Int32.Parse(config["minRequiredNonAlphanumericCharacters"] ?? "1");
            this.minRequiredPasswordLength            = Int32.Parse(config["minRequiredPasswordLength"] ?? "7");
            this.passwordAttemptWindow                = Int32.Parse(config["passwordAttemptWindow"] ?? "10");
            this.passwordFormat = (MembershipPasswordFormat)Enum.Parse(typeof(MembershipPasswordFormat), config["passwordFormat"] ?? "Hashed");
            this.passwordStrengthRegularExpression = config["passwordStrengthRegularExpression"] ?? String.Empty;
            this.requiresQuestionAndAnswer         = Boolean.Parse(config["requiresQuestionAndAnswer"] ?? "false");
            this.requiresUniqueEmail = Boolean.Parse(config["requiresUniqueEmail"] ?? "true");

            if (this.PasswordFormat == MembershipPasswordFormat.Hashed && this.EnablePasswordRetrieval)
            {
                throw new ProviderException("Configured settings are invalid: Hashed passwords cannot be retrieved. Either set the password format to different type, or set enablePasswordRetrieval to false.");
            }

            this.mongoCollection = MongoDatabase.Create(ConnectionHelper.GetDatabaseConnectionString(config)).GetCollection(config["collection"] ?? "Users");
            this.mongoCollection.EnsureIndex("ApplicationName");
            this.mongoCollection.EnsureIndex("ApplicationName", "EmailLower");
            this.mongoCollection.EnsureIndex("ApplicationName", "UsernameLower");

            base.Initialize(name, config);
        }
Example #2
0
        public override void Initialize(string name, NameValueCollection config)
        {
            this.mongoCollection = MongoDatabase.Create(ConnectionHelper.GetDatabaseConnectionString(config)).GetCollection(config["collection"] ?? "WebEvents");

            config.Remove("collection");
            config.Remove("connectionString");
            config.Remove("database");

            base.Initialize(name, config);
        }
Example #3
0
        public override void Initialize(string name, NameValueCollection config)
        {
            var configuration = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath);

            this.sessionStateSection = configuration.GetSection("system.web/sessionState") as SessionStateSection;

            this.mongoCollection = MongoDatabase.Create(ConnectionHelper.GetDatabaseConnectionString(config)).GetCollection(config["collection"] ?? "SessionState");
            this.mongoCollection.EnsureIndex("applicationVirtualPath", "id");
            this.mongoCollection.EnsureIndex("applicationVirtualPath", "id", "lockId");

            base.Initialize(name, config);
        }
Example #4
0
        public override void Initialize(string name, NameValueCollection config)
        {
            this.ApplicationName = config["applicationName"] ?? HostingEnvironment.ApplicationVirtualPath;

            this.mongoCollection = MongoDatabase.Create(ConnectionHelper.GetDatabaseConnectionString(config)).GetCollection(config["collection"] ?? "Profiles");
            this.mongoCollection.EnsureIndex("ApplicationName");
            this.mongoCollection.EnsureIndex("ApplicationName", "IsAnonymous");
            this.mongoCollection.EnsureIndex("ApplicationName", "IsAnonymous", "LastActivityDate");
            this.mongoCollection.EnsureIndex("ApplicationName", "IsAnonymous", "LastActivityDate", "Username");
            this.mongoCollection.EnsureIndex("ApplicationName", "IsAnonymous", "Username");
            this.mongoCollection.EnsureIndex("ApplicationName", "LastActivityDate");
            this.mongoCollection.EnsureIndex("ApplicationName", "Username");
            this.mongoCollection.EnsureIndex("ApplicationName", "Username", "IsAnonymous");

            base.Initialize(name, config);
        }
Example #5
0
        public override void Initialize(string name, NameValueCollection config)
        {
            this.ApplicationName = config["applicationName"] ?? HostingEnvironment.ApplicationVirtualPath;

            var mongoDatabase = MongoDatabase.Create(ConnectionHelper.GetDatabaseConnectionString(config));

            this.rolesMongoCollection        = mongoDatabase.GetCollection(config["collection"] ?? "Roles");
            this.usersInRolesMongoCollection = mongoDatabase.GetCollection("UsersInRoles");

            this.rolesMongoCollection.EnsureIndex("ApplicationName");
            this.rolesMongoCollection.EnsureIndex("ApplicationName", "Role");
            this.usersInRolesMongoCollection.EnsureIndex("ApplicationName", "Role");
            this.usersInRolesMongoCollection.EnsureIndex("ApplicationName", "Username");
            this.usersInRolesMongoCollection.EnsureIndex("ApplicationName", "Role", "Username");

            base.Initialize(name, config);
        }
 public override void Initialize(string name, NameValueCollection config)
 {
     this.mongoCollection = MongoServer.Create(ConnectionHelper.GetDatabaseConnectionString(config)).GetDatabase(config["database"] ?? "ASPNETDB").GetCollection(config["collection"] ?? "OutputCache");
     this.mongoCollection.EnsureIndex("Key");
     base.Initialize(name, config);
 }
        public override void Initialize(string name, NameValueCollection config)
        {
            this._SessionStateSection = ConfigurationManager.GetSection("system.web/sessionState") as SessionStateSection;
            this._MongoWebSection     = ConfigurationManager.GetSection("mongoDbWeb") as MongoDbWebSection;

            var connectionString = ConnectionHelper.GetDatabaseConnectionString(_MongoWebSection, config);
            var databaseName     = ConnectionHelper.GetDatabaseName(_MongoWebSection, config);
            var collectionName   =
                _MongoWebSection != null &&
                _MongoWebSection.SessionState != null &&
                _MongoWebSection.SessionState.MongoCollectionName != null
                                ? _MongoWebSection.SessionState.MongoCollectionName
                                : config["collection"];

            this._MongoCollection = MongoServer.Create(connectionString)
                                    .GetDatabase(databaseName)
                                    .GetCollection <T>(collectionName);

            _UseLock = config["useLock"] == "true" ? true : _MongoWebSection.SessionState.UseLock;

            _DotNetMemoryCacheName = config["dotNetMemoryCacheName"] == null
                                ? _MongoWebSection.SessionState.DotNetMemoryCacheName
                                : config["dotNetMemoryCacheName"];

            _SessionDataClassMap = new BsonClassMap <T>();
            _SessionDataClassMap.AutoMap();

            _ApplicationVirtualPathField = MapBsonMember(t => t.ApplicationVirtualPath);
            _IdField                  = MapBsonMember(t => t.SessionId);
            _LockIdField              = MapBsonMember(t => t.LockId);
            _LockedField              = MapBsonMember(t => t.Locked);
            _AccessedField            = MapBsonMember(t => t.Accessed);
            _ExpiresField             = MapBsonMember(t => t.Expires);
            _LockDateField            = MapBsonMember(t => t.LockDate);
            _SessionStateActionsField = MapBsonMember(t => t.SessionStateActions);
            _SessionItemsField        = MapBsonMember(t => t.SessionStateItems);

            // Ideally, we'd just use the object's bson id - however, serialization gets a bit wonky
            // when trying to have an Id property which isn't a simple type in the base class
            // This also provides better backwards compatibility with the old BsonDocument implementation (field names match)
            this._MongoCollection.EnsureIndex(
                IndexKeys.Ascending(_ApplicationVirtualPathField, _IdField), IndexOptions.SetUnique(true));

            // MongoDB TTL collection http://docs.mongodb.org/manual/tutorial/expire-data/
            this._MongoCollection.EnsureIndex(IndexKeys.Ascending(_AccessedField), IndexOptions.SetTimeToLive(_SessionStateSection.Timeout));

            bool useDotNetMemoryCache = !string.IsNullOrWhiteSpace(_DotNetMemoryCacheName);

            if (useDotNetMemoryCache && _MemoryCache == null)
            {
                lock (_CacheGuarantee)
                {
                    if (_MemoryCache == null)
                    {
                        _MemoryCache = new MemoryCache(_DotNetMemoryCacheName);
                    }
                }
            }

            // Initialise safe mode options. Defaults to Safe Mode=true, fsynch=false, w=0 (replicas to write to before returning)
            bool safeModeEnabled = true;

            bool fsync = _MongoWebSection.FSync;

            if (config["fsync"] != null)
            {
                bool.TryParse(config["fsync"], out fsync);
            }

            int replicasToWrite = _MongoWebSection.ReplicasToWrite;

            if ((config["replicasToWrite"] != null) && (!int.TryParse(config["replicasToWrite"], out replicasToWrite)))
            {
                throw new ProviderException("replicasToWrite must be a valid integer");
            }

            _SafeMode = SafeMode.Create(safeModeEnabled, fsync, replicasToWrite);

            base.Initialize(name, config);
        }