Exemple #1
0
        private static string GetCollectionName <T>()
        {
            var t = typeof(T);

            if (t == typeof(MembershipAccount))
            {
                return(MembershipAccount.GetCollectionName());
            }

            if (t == typeof(Role))
            {
                return(Role.GetCollectionName());
            }

            if (t == typeof(OAuthToken))
            {
                return(OAuthToken.GetCollectionName());
            }

            if (t == typeof(OAuthMembership))
            {
                return(OAuthMembership.GetCollectionName());
            }

            return(string.Empty);
        }
Exemple #2
0
        private void SeedData(MongoDatabase db)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }

            // Reset db
            db.GetCollection("IDSequence").Drop();

            _usersCol = db.GetCollection <MembershipAccount>(MembershipAccount.GetCollectionName());
            _usersCol.Drop();

            var salt = Crypto.GenerateSalt();

            var user1 = new MembershipAccount("User1")
            {
                PasswordSalt = salt,
                Password     = Crypto.HashPassword("p@ssword" + salt),
                IsConfirmed  = false
            };

            var user2 = new MembershipAccount("NonLocalUser")
            {
                IsLocalAccount = false,
                IsConfirmed    = true
            };

            _usersCol.InsertBatch(new[] { user1, user2 });

            var oAuthTokenCol = db.GetCollection <OAuthToken>(OAuthToken.GetCollectionName());

            oAuthTokenCol.Drop();
            oAuthTokenCol.Insert(new OAuthToken("Tok3n", "tok3nSecret"));

            var oAuthMembershipCol = db.GetCollection <OAuthMembership>(OAuthMembership.GetCollectionName());

            oAuthMembershipCol.Drop();
            oAuthMembershipCol.Insert(new OAuthMembership("Test", "User1@Test", 1));

            Users            = _usersCol.AsQueryable();
            OAuthTokens      = oAuthTokenCol.AsQueryable();
            OAuthMemberships = oAuthMembershipCol.AsQueryable();
        }
Exemple #3
0
        public MongoDataContext(string connectionNameOrString)
        {
            Contract.Requires <ArgumentNullException>(!string.IsNullOrWhiteSpace(connectionNameOrString));

            // If it's a name, we lookup config setting
            var connSettings = ConfigurationManager.ConnectionStrings[connectionNameOrString];

            if (connSettings != null && !string.IsNullOrWhiteSpace(connSettings.ConnectionString))
            {
                connectionNameOrString = connSettings.ConnectionString;
            }

            _db = GetDatase(connectionNameOrString);

            _roleCol            = _db.GetCollection <Role>(Role.GetCollectionName());
            _userCol            = _db.GetCollection <MembershipAccount>(MembershipAccount.GetCollectionName());
            _oAuthTokenCol      = _db.GetCollection <OAuthToken>(OAuthToken.GetCollectionName());
            _oAuthMembershipCol = _db.GetCollection <OAuthMembership>(OAuthMembership.GetCollectionName());

            // Check that we can connect to MongoDB server -- will throw an exception that should be caught in provider init
            _roleCol.EnsureUniqueIndex(x => x.RoleName);
        }