Esempio n. 1
0
        public void DeleteTest()
        {
            using (Db4oDatabase db = new Db4oDatabase(dbfile1, container)) {
                MockObject obj1 = new MockObject
                {
                    Name = "Jacky",
                    Phone = "22305779",
                    Address = new Address
                    {
                        Office = "ZDH",
                        Home = "BBG"
                    }
                };

                db.Store(obj1);
                Assert.AreEqual(1, db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                }).Count);

                MockObject obj2 = db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                })[0];
                db.Delete(obj2);
                Assert.AreEqual(0, db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                }).Count);

            }
        }
Esempio n. 2
0
        public override void AddUsersToRoles(string[] usernames, string[] rolenames)
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                foreach (string rolename in rolenames)
                {
                    if (!RoleExists(rolename, dbc))
                        throw new ProviderException("Role name not found.");
                }

                foreach (string username in usernames)
                {
                    if (username.Contains(","))
                        throw new ArgumentException("User names cannot contain commas.");
                }

                foreach (string rolename in rolenames)
                {
                    IList<Role> results = dbc.Query((Role r) => r.Rolename == rolename && r.ApplicationName == applicationName);

                    Role found = results[0];

                    foreach (string username in usernames)
                    {
                        if (!found.EnrolledUsers.Contains(username))
                            found.EnrolledUsers.Add(username);
                    }

                    dbc.Store(found);
                }

                foreach (string username in usernames)
                {
                    IList<EnrolledUser> results = dbc.Query((EnrolledUser u) => u.Username == username && u.ApplicationName == applicationName);

                    EnrolledUser found;

                    if (results.Count == 0)
                    {
                        // this is the only place in the API that EnrolledUser's
                        // are added to the database
                        found = new EnrolledUser(username, applicationName);
                    }
                    else
                        found = results[0];

                    foreach (string rolename in rolenames)
                    {
                        if (!found.Roles.Contains(rolename))
                            found.Roles.Add(rolename);
                    }

                    dbc.Store(found);
                }
            }
        }
        public virtual IReplicationReference ReferenceNewObject(object obj, IReplicationReference
                                                                counterpartReference, IReplicationReference referencingObjCounterPartRef, string
                                                                fieldName)
        {
            IDrsUUID uuid = counterpartReference.Uuid();

            if (uuid == null)
            {
                return(null);
            }
            byte[]       signature            = uuid.GetSignaturePart();
            long         longPart             = uuid.GetLongPart();
            long         version              = counterpartReference.Version();
            Db4oDatabase db                   = _signatureMap.Produce(signature, 0);
            Db4oReplicationReferenceImpl @ref = new Db4oReplicationReferenceImpl(obj, db, longPart
                                                                                 , version);

            AddReference(@ref);
            return(@ref);
        }
Esempio n. 4
0
            public IObjectInfo Decode(ByteArrayInputStream @is)
            {
                long id = PrimitiveCodec.ReadLong(@is);

                if (id == -1)
                {
                    return(null);
                }
                long         sourceDatabaseId = PrimitiveCodec.ReadLong(@is);
                Db4oDatabase sourceDatabase   = null;

                if (sourceDatabaseId > 0)
                {
                    sourceDatabase = (Db4oDatabase)this._enclosing.Container().GetByID(this._enclosing
                                                                                       .Transaction(), sourceDatabaseId);
                }
                long uuidLongPart = PrimitiveCodec.ReadLong(@is);
                long version      = PrimitiveCodec.ReadLong(@is);

                return(new FrozenObjectInfo(null, id, sourceDatabase, uuidLongPart, version));
            }
Esempio n. 5
0
        public virtual void ReplaceClassMetadataRepository()
        {
            Db4objects.Db4o.Internal.Transaction systemTransaction = _targetDb.SystemTransaction
                                                                         ();
            // Can't use strictMappedID because the repository ID can
            // be lower than HandlerRegisrtry _highestBuiltinTypeID and
            // the ClassRepository ID would be treated as a system handler
            // and the unmapped ID would be returned.
            int newRepositoryId   = _mapping.MappedId(SourceClassCollectionID());
            int sourceIdentityID  = DatabaseIdentityID(DefragmentServicesImpl.Sourcedb);
            int targetIdentityID  = _mapping.MappedId(sourceIdentityID);
            int targetUuidIndexID = _mapping.MappedId(SourceUuidIndexID());
            int oldIdentityId     = _targetDb.SystemData().Identity().GetID(systemTransaction);
            int oldRepositoryId   = _targetDb.ClassCollection().GetID();
            ClassMetadataRepository oldRepository = _targetDb.ClassCollection();
            ClassMetadataRepository newRepository = new ClassMetadataRepository(systemTransaction
                                                                                );

            newRepository.SetID(newRepositoryId);
            newRepository.Read(systemTransaction);
            newRepository.InitOnUp(systemTransaction);
            _targetDb.SystemData().ClassCollectionID(newRepositoryId);
            _targetDb.ReplaceClassMetadataRepository(newRepository);
            _targetDb.SystemData().UuidIndexId(targetUuidIndexID);
            Db4oDatabase identity = (Db4oDatabase)_targetDb.GetByID(systemTransaction, targetIdentityID
                                                                    );

            _targetDb.SetIdentity(identity);
            ClassMetadataIterator iterator = oldRepository.Iterator();

            while (iterator.MoveNext())
            {
                ClassMetadata           classMetadata = iterator.CurrentClass();
                BTreeClassIndexStrategy index         = (BTreeClassIndexStrategy)classMetadata.Index();
                index.Btree().Free(_targetDb.LocalSystemTransaction());
                FreeById(classMetadata.GetID());
            }
            FreeById(oldIdentityId);
            FreeById(oldRepositoryId);
        }
Esempio n. 6
0
        private User GetUser(Predicate <User> userPredicate, bool userIsOnline)
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                var results = dbc.Query(userPredicate);

                if (results.Count == 0)
                {
                    return(null);
                }

                User found = results[0];

                if (userIsOnline)
                {
                    found.LastActivityDate = DateTime.Now;
                    dbc.Store(found);
                }

                return(found);
            }
        }
Esempio n. 7
0
        public void StoreIListTest()
        {
            using (Db4oDatabase db = new Db4oDatabase(dbfile1, container)) {
                IList <Address> list = new List <Address> {
                    new Address {
                        Office = "ZDH", Home = "BBG"
                    },
                    new Address {
                        Office = "DHZ", Home = "GBB"
                    }
                };

                db.Store(list);
                Assert.AreEqual(2, db.Load <Address>().Count);

                IList <Address> list2 = new List <Address> {
                    new Address {
                        Office = "ZDH1", Home = "BBG"
                    },
                    new Address {
                        Office = "ZDH2", Home = "BBG"
                    },
                    new Address {
                        Office = "ZDH3", Home = "BBG"
                    },
                    new Address {
                        Office = "ZDH4", Home = "BBG"
                    }
                };
                db.Store(list2);
                Assert.AreEqual(6, db.Load <Address>().Count);

                IList <Address> list3 = db.Load <Address>(delegate(Address addr) {
                    return(addr.Home == "BBG");
                });
                Assert.AreEqual(5, list3.Count);
            }
        }
        internal override void Instantiate1(ObjectReferenceContext context)
        {
            int                 dbID      = context.ReadInt();
            Transaction         trans     = context.Transaction();
            ObjectContainerBase container = trans.Container();

            container.ShowInternalClasses(true);
            try
            {
                Db4oDatabase db = (Db4oDatabase)container.GetByID2(trans, dbID);
                if (db != null && db.i_signature == null)
                {
                    container.Activate(trans, db, new FixedActivationDepth(2));
                }
                VirtualAttributes va = context.ObjectReference().VirtualAttributes();
                va.i_database = db;
                va.i_uuid     = context.ReadLong();
            }
            finally
            {
                container.ShowInternalClasses(false);
            }
        }
Esempio n. 9
0
        private int GetProfileSize(string username)
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                var profiles = dbc.Query((Profile p) => p.Username == username && p.ApplicationName == applicationName);

                if (profiles.Count == 0)
                {
                    return(0);
                }

                var profile = profiles[0];
                int result  = 0;

                foreach (SettingsPropertyValue spv in profile.SettingsPropertyValueList)
                {
                    // this will be way off for any types that don't translate well to a string
                    result += spv.PropertyValue.ToString().Length * 2;
                }

                return(result);
            }
        }
Esempio n. 10
0
        public override bool DeleteRole(string rolename, bool throwOnPopulatedRole)
        {
            if (!RoleExists(rolename))
            {
                throw new ProviderException("Role does not exist.");
            }

            if (throwOnPopulatedRole && GetUsersInRole(rolename).Length > 0)
            {
                throw new ProviderException("Cannot delete a populated role.");
            }

            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                IList <Role> results = dbc.Query((Role r) => r.Rolename == rolename && r.ApplicationName == applicationName);

                Role found = results[0];

                dbc.Delete(found);

                return(true);
            }
        }
 public virtual void StartReplicationTransaction(IReadonlyReplicationProviderSignature
                                                 peerSignature)
 {
     ClearAllReferences();
     lock (Lock())
     {
         Transaction  trans      = _container.Transaction;
         Db4oDatabase myIdentity = _container.Identity();
         _signatureMap.Put(myIdentity);
         Db4oDatabase otherIdentity = _signatureMap.Produce(peerSignature.GetSignature(),
                                                            peerSignature.GetCreated());
         Db4oDatabase younger = null;
         Db4oDatabase older   = null;
         if (myIdentity.IsOlderThan(otherIdentity))
         {
             younger = otherIdentity;
             older   = myIdentity;
         }
         else
         {
             younger = myIdentity;
             older   = otherIdentity;
         }
         _replicationRecord = ReplicationRecord.QueryForReplicationRecord(_container, trans
                                                                          , younger, older);
         if (_replicationRecord == null)
         {
             _replicationRecord = new ReplicationRecord(younger, older);
             _replicationRecord.Store(_container);
         }
         else
         {
             _container.RaiseCommitTimestamp(_replicationRecord._version + 1);
         }
         _commitTimestamp = _container.GenerateTransactionTimestamp(0);
     }
 }
Esempio n. 12
0
        public override string[] GetUsersInRole(string rolename)
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                IList<Role> results = dbc.Query((Role r) => r.Rolename == rolename && r.ApplicationName == applicationName);

                if (results.Count == 0)
                    return new string[0];

                Role found = results[0];

                return found.EnrolledUsers.ToArray();
            }
        }
Esempio n. 13
0
        public override void RemoveUsersFromRoles(string[] usernames, string[] rolenames)
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                foreach (string rolename in rolenames)
                {
                    if (!RoleExists(rolename, dbc))
                        throw new ProviderException("Role name not found.");
                }

                foreach (string rolename in rolenames)
                {
                    IList<Role> results = dbc.Query((Role r) => r.Rolename == rolename && r.ApplicationName == applicationName);

                    Role found = results[0];

                    foreach (string username in usernames)
                    {
                        if (found.EnrolledUsers.Contains(username))
                            found.EnrolledUsers.Remove(username);
                    }

                    dbc.Store(found);
                }

                foreach (string username in usernames)
                {
                    IList<EnrolledUser> results = dbc.Query((EnrolledUser u) => u.Username == username && u.ApplicationName == applicationName);

                    if (results.Count == 0)
                        continue;

                    EnrolledUser found = results[0];

                    foreach (string rolename in rolenames)
                    {
                        if (found.Roles.Contains(rolename))
                            found.Roles.Remove(rolename);
                    }

                    dbc.Store(found);
                }
            }
        }
Esempio n. 14
0
        public override string[] GetAllRoles()
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                IList<Role> results = dbc.Query((Role r) => r.ApplicationName == applicationName);

                List<string> roleList = new List<string>();
                foreach (Role role in results)
                    roleList.Add(role.Rolename);

                return roleList.ToArray();
            }
        }
Esempio n. 15
0
        public override string[] GetRolesForUser(string username)
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                IList<EnrolledUser> results = dbc.Query((EnrolledUser u) => u.Username == username && u.ApplicationName == applicationName);

                if (results.Count == 0)
                    return new string[0];

                EnrolledUser found = results[0];

                return found.Roles.ToArray();
            }
        }
Esempio n. 16
0
        public void StoreIListTest()
        {
            using (Db4oDatabase db = new Db4oDatabase(dbfile1, container)) {
                IList<Address> list = new List<Address> {
                    new Address { Office = "ZDH", Home = "BBG" },
                    new Address { Office = "DHZ", Home = "GBB" }
                };

                db.Store(list);
                Assert.AreEqual(2, db.Load<Address>().Count);

                IList<Address> list2 = new List<Address> {
                    new Address { Office = "ZDH1", Home = "BBG" },
                    new Address { Office = "ZDH2", Home = "BBG" },
                    new Address { Office = "ZDH3", Home = "BBG" },
                    new Address { Office = "ZDH4", Home = "BBG" }
                };
                db.Store(list2);
                Assert.AreEqual(6, db.Load<Address>().Count);

                IList<Address> list3 = db.Load<Address>(delegate(Address addr) {
                    return addr.Home == "BBG";
                });
                Assert.AreEqual(5, list3.Count);
            }
        }
Esempio n. 17
0
        public override bool DeleteRole(string rolename, bool throwOnPopulatedRole)
        {
            if (!RoleExists(rolename))
                throw new ProviderException("Role does not exist.");

            if (throwOnPopulatedRole && GetUsersInRole(rolename).Length > 0)
                throw new ProviderException("Cannot delete a populated role.");

            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                IList<Role> results = dbc.Query((Role r) => r.Rolename == rolename && r.ApplicationName == applicationName);

                Role found = results[0];

                dbc.Delete(found);

                return true;
            }
        }
Esempio n. 18
0
 public static ReplicationRecord QueryForReplicationRecord(ObjectContainerBase
                                                           container, Transaction trans, Db4oDatabase younger, Db4oDatabase older)
 {
     container.ShowInternalClasses(true);
     try
     {
         var q = container.Query(trans);
         q.Constrain(typeof(ReplicationRecord));
         q.Descend("_youngerPeer").Constrain(younger).Identity();
         q.Descend("_olderPeer").Constrain(older).Identity();
         var objectSet = q.Execute();
         if (objectSet.HasNext())
         {
             var replicationRecord = (ReplicationRecord
                                      )objectSet.Next();
             container.Activate(replicationRecord, int.MaxValue);
             return(replicationRecord);
         }
         return(null);
     }
     finally
     {
         container.ShowInternalClasses(false);
     }
 }
Esempio n. 19
0
        public override void CreateRole(string rolename)
        {
            if (rolename.Contains(","))
                throw new ArgumentException("Role names cannot contain commas.");

            if (RoleExists(rolename))
                throw new ProviderException("Role name already exists.");

            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                dbc.Store(new Role(rolename, applicationName));
            }
        }
Esempio n. 20
0
 public void Db4oDatabase_ctorTest()
 {
     using (Db4oDatabase db = new Db4oDatabase(dbfile1, container)){
         Assert.AreEqual(true, File.Exists(dbfile1));
     }
 }
Esempio n. 21
0
 public ReplicationRecord(Db4oDatabase younger, Db4oDatabase older)
 {
     _youngerPeer = younger;
     _olderPeer   = older;
 }
Esempio n. 22
0
        public void StoreTest()
        {
            using (Db4oDatabase db = new Db4oDatabase(dbfile1, container)) {
                MockObject obj1 = new MockObject
                {
                    Name = "Jacky",
                    Phone = "22305779",
                    Address = new Address {
                        Office = "ZDH",
                        Home = "BBG"
                    }
                };

                db.Store(obj1);

                Assert.IsNotNull(db.Load<MockObject>()[0]);
                Assert.IsNotNull(db.Load<Address>()[0]);

                IList<MockObject> list = db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                });
                Assert.AreEqual("Jacky", list[0].Name);
                Assert.AreEqual("22305779", list[0].Phone);
                Assert.IsNotNull(list[0].Address);
                Console.WriteLine(list[0]);

                MockObject obj2 = list[0];
                obj2.Phone = "22228057";
                db.Store(obj2);
                Assert.AreEqual(1, db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                }).Count);
                Console.WriteLine(obj2);

                MockObject obj3 = new MockObject
                {
                    Name = "Jacky",
                    Phone = "22305779",
                    Address = new Address
                    {
                        Office = "ZDH",
                        Home = "BBG"
                    }
                };
                db.Store(obj3);
                list.Clear();
                list = db.Load<MockObject>(delegate(MockObject obj) {
                    return obj.Name == "Jacky";
                });
                Assert.AreEqual(2, list.Count);
                foreach (MockObject obj in list) {
                    Console.WriteLine(obj);
                }
            }
        }
Esempio n. 23
0
 public Db4oReplicationProviderSignature(Db4oDatabase delegate_)
 {
     _delegate = delegate_;
 }
Esempio n. 24
0
 public void Db4oDatabase_ctorTest()
 {
     using (Db4oDatabase db = new Db4oDatabase(dbfile1, container)){
         Assert.AreEqual(true, File.Exists(dbfile1));
     }
 }
Esempio n. 25
0
 public override bool RoleExists(string rolename)
 {
     using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
     {
         return RoleExists(rolename, dbc);
     }
 }
        private User UpdateUser(Predicate<User> userPredicate, Action<User> userUpdate)
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                IList<User> results = dbc.Query(userPredicate);

                if (results.Count != 1)
                    return null;

                User found = results[0];

                if (userUpdate != null)
                    userUpdate(found);

                found.LastActivityDate = DateTime.Now;

                dbc.Store(found);

                return found;
            }
        }
Esempio n. 27
0
 private List <User> GetUsers(Predicate <User> userPredicate)
 {
     using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
         return(new List <User>(dbc.Query(userPredicate)));
 }
Esempio n. 28
0
 public virtual void Identity(Db4oDatabase identityObject)
 {
     _identity = identityObject;
 }
        public override MembershipUser CreateUser(string username,
            string password,
            string email,
            string passwordQuestion,
            string passwordAnswer,
            bool isApproved,
            object providerUserKey,
            out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != "")
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            MembershipUser u = GetUser(username, false);

            if (u == null)
            {
                DateTime createDate = DateTime.Now;

                if (providerUserKey == null)
                {
                    providerUserKey = Guid.NewGuid();
                }
                else
                {
                    if (!(providerUserKey is Guid))
                    {
                        status = MembershipCreateStatus.InvalidProviderUserKey;
                        return null;
                    }
                }

                var user = new User(
                    (Guid)providerUserKey,
                    username,
                    EncodePassword(password),
                    email,
                    passwordQuestion,
                    EncodePassword(passwordAnswer),
                    isApproved,
                    "",
                    createDate,
                    createDate,
                    createDate,
                    applicationName,
                    false,
                    createDate,
                    0,
                    createDate,
                    0,
                    createDate);

                using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
                {
                    dbc.Store(user);
                }

                status = MembershipCreateStatus.Success;

                return GetUser(username, false);
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return null;
        }
Esempio n. 30
0
        public override void AddUsersToRoles(string[] usernames, string[] rolenames)
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                foreach (string rolename in rolenames)
                {
                    if (!RoleExists(rolename, dbc))
                    {
                        throw new ProviderException("Role name not found.");
                    }
                }

                foreach (string username in usernames)
                {
                    if (username.Contains(","))
                    {
                        throw new ArgumentException("User names cannot contain commas.");
                    }
                }

                foreach (string rolename in rolenames)
                {
                    IList <Role> results = dbc.Query((Role r) => r.Rolename == rolename && r.ApplicationName == applicationName);

                    Role found = results[0];

                    foreach (string username in usernames)
                    {
                        if (!found.EnrolledUsers.Contains(username))
                        {
                            found.EnrolledUsers.Add(username);
                        }
                    }

                    dbc.Store(found);
                }

                foreach (string username in usernames)
                {
                    IList <EnrolledUser> results = dbc.Query((EnrolledUser u) => u.Username == username && u.ApplicationName == applicationName);

                    EnrolledUser found;

                    if (results.Count == 0)
                    {
                        // this is the only place in the API that EnrolledUser's
                        // are added to the database
                        found = new EnrolledUser(username, applicationName);
                    }
                    else
                    {
                        found = results[0];
                    }

                    foreach (string rolename in rolenames)
                    {
                        if (!found.Roles.Contains(rolename))
                        {
                            found.Roles.Add(rolename);
                        }
                    }

                    dbc.Store(found);
                }
            }
        }
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                var results = dbc.Query<User>(u => u.Username == username && u.ApplicationName == applicationName);

                if (results.Count != 1)
                    return false;

                User found = results[0];

                dbc.Delete(found);
            }

            return false;
        }
        private User GetUser(Predicate<User> userPredicate, bool userIsOnline)
        {
            using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
            {
                var results = dbc.Query(userPredicate);

                if (results.Count == 0)
                    return null;

                User found = results[0];

                if (userIsOnline)
                {
                    found.LastActivityDate = DateTime.Now;
                    dbc.Store(found);
                }

                return found;
            }
        }
Esempio n. 33
0
 public static Db4objects.Drs.Db4o.ReplicationRecord QueryForReplicationRecord(ObjectContainerBase
                                                                               container, Transaction trans, Db4oDatabase younger, Db4oDatabase older)
 {
     container.ShowInternalClasses(true);
     try
     {
         IQuery q = container.Query(trans);
         q.Constrain(typeof(Db4objects.Drs.Db4o.ReplicationRecord));
         q.Descend("_youngerPeer").Constrain(younger).Identity();
         q.Descend("_olderPeer").Constrain(older).Identity();
         IObjectSet objectSet = q.Execute();
         return(objectSet.HasNext() ? (Db4objects.Drs.Db4o.ReplicationRecord)objectSet.Next
                    () : null);
     }
     finally
     {
         container.ShowInternalClasses(false);
     }
 }
 private List<User> GetUsers(Predicate<User> userPredicate)
 {
     using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
         return new List<User>(dbc.Query(userPredicate));
 }
        public virtual void TestIdentitySignatureIsNotNull()
        {
            Db4oDatabase identity = Db().Identity();

            Assert.IsNotNull(identity.GetSignature());
        }
Esempio n. 36
0
        public override MembershipUser CreateUser(string username,
                                                  string password,
                                                  string email,
                                                  string passwordQuestion,
                                                  string passwordAnswer,
                                                  bool isApproved,
                                                  object providerUserKey,
                                                  out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != "")
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return(null);
            }

            MembershipUser u = GetUser(username, false);

            if (u == null)
            {
                DateTime createDate = DateTime.Now;

                if (providerUserKey == null)
                {
                    providerUserKey = Guid.NewGuid();
                }
                else
                {
                    if (!(providerUserKey is Guid))
                    {
                        status = MembershipCreateStatus.InvalidProviderUserKey;
                        return(null);
                    }
                }

                var user = new User(
                    (Guid)providerUserKey,
                    username,
                    EncodePassword(password),
                    email,
                    passwordQuestion,
                    EncodePassword(passwordAnswer),
                    isApproved,
                    "",
                    createDate,
                    createDate,
                    createDate,
                    applicationName,
                    false,
                    createDate,
                    0,
                    createDate,
                    0,
                    createDate);

                using (Db4oDatabase dbc = new Db4oDatabase(connectionString))
                {
                    dbc.Store(user);
                }

                status = MembershipCreateStatus.Success;

                return(GetUser(username, false));
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return(null);
        }