[845] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 |
|
---|
| 27 | using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
|
---|
| 28 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[925] | 29 | using System.Runtime.CompilerServices;
|
---|
[845] | 30 |
|
---|
| 31 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
[925] | 32 | class UserAdapter : DataAdapterBase, IUserAdapter {
|
---|
[845] | 33 | private dsHiveServerTableAdapters.HiveUserTableAdapter adapter =
|
---|
| 34 | new dsHiveServerTableAdapters.HiveUserTableAdapter();
|
---|
| 35 |
|
---|
[925] | 36 | private dsHiveServer.HiveUserDataTable data =
|
---|
| 37 | new dsHiveServer.HiveUserDataTable();
|
---|
[845] | 38 |
|
---|
[925] | 39 | private IPermissionOwnerAdapter permOwnerAdapter =
|
---|
| 40 | ServiceLocator.GetPermissionOwnerAdapter();
|
---|
| 41 |
|
---|
| 42 | public UserAdapter() {
|
---|
| 43 | adapter.Fill(data);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | protected override void Update() {
|
---|
| 47 | this.adapter.Update(this.data);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[899] | 50 | private User Convert(dsHiveServer.HiveUserRow row,
|
---|
| 51 | User user) {
|
---|
| 52 | if (row != null && user != null) {
|
---|
| 53 | /*Parent - PermissionOwner*/
|
---|
| 54 | user.PermissionOwnerId = row.PermissionOwnerId;
|
---|
[925] | 55 | permOwnerAdapter.GetPermissionOwnerById(user);
|
---|
[845] | 56 |
|
---|
| 57 | /*User*/
|
---|
[899] | 58 | if (!row.IsPasswordNull())
|
---|
| 59 | user.Password = row.Password;
|
---|
| 60 | else
|
---|
| 61 | user.Password = String.Empty;
|
---|
[845] | 62 |
|
---|
| 63 | return user;
|
---|
| 64 | } else
|
---|
| 65 | return null;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | private dsHiveServer.HiveUserRow Convert(User user,
|
---|
| 69 | dsHiveServer.HiveUserRow row) {
|
---|
| 70 | if (user != null && row != null) {
|
---|
| 71 | row.Password = user.Password;
|
---|
| 72 |
|
---|
[899] | 73 | return row;
|
---|
| 74 | } else
|
---|
| 75 | return null;
|
---|
[845] | 76 | }
|
---|
| 77 |
|
---|
| 78 | #region IUserAdapter Members
|
---|
| 79 |
|
---|
[925] | 80 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
[845] | 81 | public void UpdateUser(User user) {
|
---|
[905] | 82 | if (user != null) {
|
---|
| 83 | permOwnerAdapter.UpdatePermissionOwner(user);
|
---|
| 84 |
|
---|
[925] | 85 | dsHiveServer.HiveUserRow row =
|
---|
| 86 | data.FindByPermissionOwnerId(user.PermissionOwnerId);
|
---|
| 87 | if (row == null) {
|
---|
[905] | 88 | row = data.NewHiveUserRow();
|
---|
| 89 | row.PermissionOwnerId = user.PermissionOwnerId;
|
---|
| 90 | data.AddHiveUserRow(row);
|
---|
[925] | 91 | }
|
---|
[905] | 92 |
|
---|
| 93 | Convert(user, row);
|
---|
| 94 | }
|
---|
[845] | 95 | }
|
---|
| 96 |
|
---|
[899] | 97 | public User GetUserById(long userId) {
|
---|
[905] | 98 | User user = new User();
|
---|
| 99 |
|
---|
[925] | 100 | dsHiveServer.HiveUserRow row =
|
---|
| 101 | data.FindByPermissionOwnerId(userId);
|
---|
| 102 |
|
---|
| 103 | if(row != null) {
|
---|
[905] | 104 | Convert(row, user);
|
---|
| 105 |
|
---|
| 106 | return user;
|
---|
| 107 | } else {
|
---|
| 108 | return null;
|
---|
| 109 | }
|
---|
[845] | 110 | }
|
---|
| 111 |
|
---|
[899] | 112 | public User GetUserByName(String name) {
|
---|
[905] | 113 | User user = new User();
|
---|
| 114 |
|
---|
[925] | 115 | PermissionOwner permOwner =
|
---|
| 116 | permOwnerAdapter.GetPermissionOwnerByName(name);
|
---|
| 117 |
|
---|
| 118 | if (permOwner != null) {
|
---|
[905] | 119 | dsHiveServer.HiveUserRow row =
|
---|
[925] | 120 | data.FindByPermissionOwnerId(permOwner.PermissionOwnerId);
|
---|
[905] | 121 |
|
---|
[925] | 122 | if (row != null) {
|
---|
| 123 | Convert(row, user);
|
---|
| 124 |
|
---|
| 125 | return user;
|
---|
| 126 | }
|
---|
[905] | 127 | }
|
---|
[925] | 128 |
|
---|
| 129 | return null;
|
---|
[899] | 130 | }
|
---|
| 131 |
|
---|
[845] | 132 | public ICollection<User> GetAllUsers() {
|
---|
[905] | 133 | ICollection<User> allUsers =
|
---|
| 134 | new List<User>();
|
---|
| 135 |
|
---|
| 136 | foreach (dsHiveServer.HiveUserRow row in data) {
|
---|
| 137 | User user = new User();
|
---|
| 138 | Convert(row, user);
|
---|
| 139 | allUsers.Add(user);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | return allUsers;
|
---|
[845] | 143 | }
|
---|
| 144 |
|
---|
[925] | 145 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
[845] | 146 | public bool DeleteUser(User user) {
|
---|
[925] | 147 | if (user != null) {
|
---|
| 148 | dsHiveServer.HiveUserRow row =
|
---|
| 149 | data.FindByPermissionOwnerId(user.PermissionOwnerId);
|
---|
| 150 |
|
---|
| 151 | if (row != null) {
|
---|
| 152 | data.RemoveHiveUserRow(row);
|
---|
| 153 |
|
---|
| 154 | return permOwnerAdapter.DeletePermissionOwner(user);
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | return false;
|
---|
[845] | 159 | }
|
---|
| 160 |
|
---|
| 161 | #endregion
|
---|
| 162 | }
|
---|
| 163 | }
|
---|