コード例 #1
0
 public IUser[] GetUsers()
 {
     if (!_allUsersLoaded)
     {
         Sync(() =>
         {
             if (_allUsersLoaded)
                 return;
             _allUsersLoaded = true;
             GetSchemas();
             var qry = _store.CreateQuery<UserModel>();
             var users = qry.Find();
             IUser user = null;
             foreach (var userModel in users)
             {
                 if (!_users.TryGetValue(userModel.Login.ToLower(), out user))
                 {
                     user = new UserImpl(GetSchema(userModel.SchemaId), userModel);
                     _users[user.Login.ToLower()] = user;
                 }
             }
         });
     }
     return _users.Values.OrderBy(u => u.Login).ToArray();
 }
コード例 #2
0
        private IUser GetUserInternal(String login, bool throwIfNotExists)
        {
            Assert.EmptyString(login, "login");
            IUser result = null;
            login = login.ToLower();
            if (!_users.TryGetValue(login, out result))
            {
                var qry = _store.CreateQuery<UserModel>();
                qry.AddFilterEqual("Login", login);
                var model = qry.FindFirst();
                if (model != null)
                {
                    result = new UserImpl(GetSchemaInternal(model.SchemaId, true), model);
                    _users[login] = result;
                }
            }
            if (result == null && throwIfNotExists)
                throw new InvalidOperationException("Não existe um usuário com o login " + throwIfNotExists);

            return result;
        }
コード例 #3
0
        public IUser CreateUser(ISchema schema, string login, string name, string email)
        {
            Assert.NullArgument(schema, "schema");
            Assert.EmptyString(login, "login");
            Assert.EmptyString(name, "name");
            Assert.EmptyString(email, "email");

            IUser user = null;
            Sync(() =>
            {
                user = GetUserInternal(login, false);
                if (user == null)
                {
                    var model = new UserModel()
                    {
                        Login = login,
                        Name = name,
                        Email = email,
                        SchemaId = schema.Id
                    };
                    if (_store.Save(model))
                    {
                        user = new UserImpl(schema, model);
                        _users[login.ToLower()] = user;
                    }
                    else
                        throw new Exception("Não foi possivel criar o esquema de usuários - erro ao persistir as informações");
                }
                else
                    throw new Exception("Já existe um usuário com o login " + login);
            });
            return user;
        }